Styles: Added ImGuiStyle::ScaleAllSizes(float) helper to make it easier to have application transition to e.g. High DPI with a matching style.

This commit is contained in:
omar 2017-10-04 18:13:57 -07:00
parent 89ab4b5e07
commit 67ac7da30f
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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().