From 67ac7da30f2372dbd9c7371ef42114a436f6659d Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 4 Oct 2017 18:13:57 -0700 Subject: [PATCH] Styles: Added ImGuiStyle::ScaleAllSizes(float) helper to make it easier to have application transition to e.g. High DPI with a matching style. --- imgui.cpp | 23 +++++++++++++++++++++++ imgui.h | 1 + 2 files changed, 24 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index f1fdb508..21aba4eb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -744,6 +744,29 @@ void ImGui::StyleColorsClassic(ImGuiStyle* dst) colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); } +// To scale your entire UI (e.g. if you want your app to use High DPI or generally be DPI aware) you may use this helper function. Scaling the fonts is done separately and is up to you. +// Tips: if you need to change your scale multiple times, prefer calling this on a freshly initialized ImGuiStyle structure rather than scaling multiple times (because floating point multiplications are lossy). +void ImGuiStyle::ScaleAllSizes(float scale_factor) +{ + WindowPadding *= scale_factor; + WindowMinSize *= scale_factor; + WindowRounding *= scale_factor; + ChildWindowRounding *= scale_factor; + FramePadding *= scale_factor; + FrameRounding *= scale_factor; + ItemSpacing *= scale_factor; + ItemInnerSpacing *= scale_factor; + TouchExtraPadding *= scale_factor; + IndentSpacing *= scale_factor; + ColumnsMinSpacing *= scale_factor; + ScrollbarSize *= scale_factor; + ScrollbarRounding *= scale_factor; + GrabMinSize *= scale_factor; + GrabRounding *= scale_factor; + DisplayWindowPadding *= scale_factor; + DisplaySafeAreaPadding *= scale_factor; +} + ImGuiIO::ImGuiIO() { // Most fields are initialized with zero diff --git a/imgui.h b/imgui.h index 0740592f..654e83fc 100644 --- a/imgui.h +++ b/imgui.h @@ -769,6 +769,7 @@ struct ImGuiStyle ImVec4 Colors[ImGuiCol_COUNT]; IMGUI_API ImGuiStyle(); + IMGUI_API void ScaleAllSizes(float scale_factor); }; // This is where your app communicate with ImGui. Access via ImGui::GetIO().