diff --git a/imgui.cpp b/imgui.cpp index 3fb75eb25..39a79a398 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1358,8 +1358,8 @@ static void* GImAllocatorUserData = NULL; ImGuiStyle::ImGuiStyle() { FontSizeBase = 0.0f; // Will default to io.Fonts->Fonts[0] on first frame. - FontScaleMain = 1.0f; // Main global scale factor. - FontScaleDpi = 1.0f; // Scale factor from viewport/monitor. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor DPI. + FontScaleMain = 1.0f; // Main scale factor. May be set by application once, or exposed to end-user. + FontScaleDpi = 1.0f; // Additional scale factor from viewport/monitor contents scale. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor DPI. Alpha = 1.0f; // Global alpha applies to everything in Dear ImGui. DisabledAlpha = 0.60f; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha. @@ -3979,7 +3979,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas) Initialized = false; Font = NULL; FontBaked = NULL; - FontSize = FontSizeBeforeScaling = FontBakedScale = CurrentDpiScale = 0.0f; + FontSize = FontSizeBase = FontBakedScale = CurrentDpiScale = 0.0f; FontRasterizerDensity = 1.0f; IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); if (shared_font_atlas == NULL) @@ -8651,7 +8651,7 @@ void ImGui::UpdateFontsNewFrame() // Set initial font g.Font = font; - g.FontSizeBeforeScaling = g.Style.FontSizeBase; + g.FontSizeBase = g.Style.FontSizeBase; g.FontSize = 0.0f; ImFontStackData font_stack_data = { font, g.Style.FontSizeBase, g.Style.FontSizeBase }; // <--- Will restore FontSize SetCurrentFont(font_stack_data.Font, font_stack_data.FontSizeBeforeScaling, 0.0f); // <--- but use 0.0f to enable scale @@ -8717,7 +8717,7 @@ void ImGui::SetCurrentFont(ImFont* font, float font_size_before_scaling, float f { ImGuiContext& g = *GImGui; g.Font = font; - g.FontSizeBeforeScaling = font_size_before_scaling; + g.FontSizeBase = font_size_before_scaling; UpdateCurrentFontSize(font_size_after_scaling); if (font != NULL) @@ -8738,7 +8738,7 @@ void ImGui::UpdateCurrentFontSize(float restore_font_size_after_scaling) ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - g.Style.FontSizeBase = g.FontSizeBeforeScaling; + g.Style.FontSizeBase = g.FontSizeBase; if (window != NULL && window->SkipItems) return; @@ -8746,7 +8746,7 @@ void ImGui::UpdateCurrentFontSize(float restore_font_size_after_scaling) float final_size = (restore_font_size_after_scaling > 0.0f) ? restore_font_size_after_scaling : 0.0f; if (final_size == 0.0f) { - final_size = g.FontSizeBeforeScaling; + final_size = g.FontSizeBase; // External scale factors final_size *= g.Style.FontScaleMain; // Main global scale factor @@ -8796,7 +8796,7 @@ void ImGui::SetFontRasterizerDensity(float rasterizer_density) void ImGui::PushFont(ImFont* font, float font_size_base) { ImGuiContext& g = *GImGui; - g.FontStack.push_back({ g.Font, g.FontSizeBeforeScaling, g.FontSize }); + g.FontStack.push_back({ g.Font, g.FontSizeBase, g.FontSize }); if (font == NULL) font = GetDefaultFont(); if (font_size_base <= 0.0f) @@ -8804,7 +8804,7 @@ void ImGui::PushFont(ImFont* font, float font_size_base) if (font->Flags & ImFontFlags_DefaultToLegacySize) font_size_base = font->LegacySize; // Legacy: use AddFont() specified font size. Same as doing PushFont(font, font->LegacySize) else - font_size_base = g.FontSizeBeforeScaling; // Keep current font size + font_size_base = g.FontSizeBase; // Keep current font size } SetCurrentFont(font, font_size_base, 0.0f); } diff --git a/imgui.h b/imgui.h index 563d2eb92..cdcdae68b 100644 --- a/imgui.h +++ b/imgui.h @@ -2227,9 +2227,10 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE struct ImGuiStyle { - float FontSizeBase; // Current base font size before external scaling factors are applied. Use PushFont()/PushFontSize() to modify. Use ImGui::GetFontSize() to obtain scaled value. Final FontSize = FontSizeBase * (FontScaleBase * FontScaleDpi * other_factors) + // ImGui::GetFontSize() == FontSizeBase * (FontScaleMain * FontScaleDpi * other_scaling_factors) + float FontSizeBase; // Current base font size before external scaling factors are applied. Use PushFont()/PushFontSize() to modify. Use ImGui::GetFontSize() to obtain scaled value. float FontScaleMain; // Main scale factor. May be set by application once, or exposed to end-user. - float FontScaleDpi; // Scale factor from viewport/monitor contents scale. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor. + float FontScaleDpi; // Additional scale factor from viewport/monitor contents scale. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor DPI. float Alpha; // Global alpha applies to everything in Dear ImGui. float DisabledAlpha; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 6fabbac9e..c4f342e54 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3193,7 +3193,7 @@ static void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, bool need_bind_ctx = ctx != curr_ctx; if (need_bind_ctx) ImGui::SetCurrentContext(ctx); - ImGui::SetCurrentFont(new_font, ctx->FontSizeBeforeScaling, ctx->FontSize); + ImGui::SetCurrentFont(new_font, ctx->FontSizeBase, ctx->FontSize); if (need_bind_ctx) ImGui::SetCurrentContext(curr_ctx); } diff --git a/imgui_internal.h b/imgui_internal.h index db308bc7a..e344cbccf 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2139,8 +2139,8 @@ struct ImGuiContext ImVector FontAtlases; // List of font atlases used by the context (generally only contains g.IO.Fonts aka the main font atlas) ImFont* Font; // Currently bound font. (== FontStack.back().Font) ImFontBaked* FontBaked; // Currently bound font at currently bound size. (== Font->GetFontBaked(FontSize)) - float FontSize; // Currently bound font size == line height (== FontSizeBeforeScaling + externals scales applied in the UpdateCurrentFontSize() function). - float FontSizeBeforeScaling; // Font size before scaling == style.FontSizeBase == value passed to PushFont() / PushFontSize() when specified. + float FontSize; // Currently bound font size == line height (== FontSizeBase + externals scales applied in the UpdateCurrentFontSize() function). + float FontSizeBase; // Font size before scaling == style.FontSizeBase == value passed to PushFont() / PushFontSize() when specified. float FontBakedScale; // == FontBaked->Size / FontSize. Scale factor over baked size. Rarely used nowadays, very often == 1.0f. float FontRasterizerDensity; // Current font density. Used by all calls to GetFontBaked(). float CurrentDpiScale; // Current window/viewport DpiScale == CurrentViewport->DpiScale @@ -2690,7 +2690,7 @@ public: ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight; return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight); } // [Obsolete] ImGuiWindow::CalcFontSize() was removed in 1.92.x because error-prone/misleading. You can use window->FontRefSize for a copy of g.FontSize at the time of the last Begin() call for this window. - //float CalcFontSize() const { ImGuiContext& g = *Ctx; return g.FontBaseSize * FontWindowScale * FontWindowScaleParents; } + //float CalcFontSize() const { ImGuiContext& g = *Ctx; return g.FontSizeBase * FontWindowScale * FontWindowScaleParents; }; //-----------------------------------------------------------------------------