Skip to content

Commit

Permalink
Internals: merge ScaleWindowsInViewport() from docking branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Dec 20, 2024
1 parent 2a600bd commit 18929bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14788,6 +14788,7 @@ void ImGui::LocalizeRegisterEntries(const ImGuiLocEntry* entries, int count)
//-----------------------------------------------------------------------------
// - GetMainViewport()
// - SetWindowViewport() [Internal]
// - ScaleWindowsInViewport() [Internal]
// - UpdateViewportsNewFrame() [Internal]
// (this section is more complete in the 'docking' branch)
//-----------------------------------------------------------------------------
Expand All @@ -14803,6 +14804,24 @@ void ImGui::SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
window->Viewport = viewport;
}

static void ScaleWindow(ImGuiWindow* window, float scale)
{
ImVec2 origin = window->Viewport->Pos;
window->Pos = ImFloor((window->Pos - origin) * scale + origin);
window->Size = ImTrunc(window->Size * scale);
window->SizeFull = ImTrunc(window->SizeFull * scale);
window->ContentSize = ImTrunc(window->ContentSize * scale);
}

// Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!)
void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
{
ImGuiContext& g = *GImGui;
for (ImGuiWindow* window : g.Windows)
if (window->Viewport == viewport)
ScaleWindow(window, scale);
}

// Update viewports and monitor infos
static void ImGui::UpdateViewportsNewFrame()
{
Expand Down
1 change: 1 addition & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,7 @@ namespace ImGui
IMGUI_API void CallContextHooks(ImGuiContext* context, ImGuiContextHookType type);

// Viewports
IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale);
IMGUI_API void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport);

// Settings
Expand Down

0 comments on commit 18929bd

Please sign in to comment.