From e3860aa6ac0be98df8df0aeaa194107a27f5f4d4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 26 May 2025 13:52:20 +0200 Subject: [PATCH] (Breaking) Fonts: removing obsolete ImFont::Scale. --- imgui.cpp | 13 ++++++++++--- imgui.h | 4 +++- imgui_draw.cpp | 2 ++ imgui_internal.h | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9b9874a5a..79d36db59 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8683,7 +8683,9 @@ void ImGui::SetCurrentFont(ImFont* font, float font_size) if (font != NULL) { IM_ASSERT(font && font->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ? +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS IM_ASSERT(font->Scale > 0.0f); +#endif g.DrawListSharedData.Font = g.Font; ImFontAtlasUpdateDrawListsSharedData(g.Font->ContainerAtlas); if (g.CurrentWindow != NULL) @@ -8699,7 +8701,10 @@ void ImGui::UpdateCurrentFontSize() return; float final_size = g.FontSizeBeforeScaling * g.IO.FontGlobalScale; - final_size *= g.Font->Scale; +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + if (g.Font != NULL) + final_size *= g.Font->Scale; +#endif if (window != NULL) final_size *= window->FontWindowScale; @@ -16753,14 +16758,16 @@ void ImGui::DebugNodeFont(ImFont* font) ImFontAtlasFontDiscardBakes(atlas, font, 2); // Display details +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS SetNextItemWidth(GetFontSize() * 8); DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); - SameLine(); MetricsHelpMarker( + /*SameLine(); MetricsHelpMarker( "Note that the default embedded font is NOT meant to be scaled.\n\n" "Font are currently rendered into bitmaps at a given size at the time of building the atlas. " "You may oversample them to get some flexibility with scaling. " "You can also render at multiple sizes and select which one to use at runtime.\n\n" - "(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)"); + "(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)");*/ +#endif char c_str[5]; Text("Fallback character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->FallbackChar), font->FallbackChar); diff --git a/imgui.h b/imgui.h index 8ed8f2318..9a9473760 100644 --- a/imgui.h +++ b/imgui.h @@ -3762,10 +3762,12 @@ struct ImFont ImVector Sources; // 16 // in // List of sources. Pointers within ContainerAtlas->Sources[] ImWchar EllipsisChar; // 2-4 // out // Character used for ellipsis rendering ('...'). ImWchar FallbackChar; // 2-4 // out // Character used if a glyph isn't found (U+FFFD, '?') - float Scale; // 4 // in // Base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale() ImU8 Used8kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/8192/8]; // 1 bytes if ImWchar=ImWchar16, 16 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints. bool EllipsisAutoBake; // 1 // // Mark when the "..." glyph needs to be generated. ImGuiStorage RemapPairs; // 16 // // Remapping pairs when using AddRemapChar(), otherwise empty. +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + float Scale; // 4 // in // Legacy base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale() +#endif // Methods IMGUI_API ImFont(); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b2380dfc0..7e5b10f34 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -5018,7 +5018,9 @@ void ImFontBaked::ClearOutputData() ImFont::ImFont() { memset(this, 0, sizeof(*this)); +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS Scale = 1.0f; +#endif } ImFont::~ImFont() diff --git a/imgui_internal.h b/imgui_internal.h index 59666f3e5..5dacf666e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2139,7 +2139,7 @@ struct ImGuiContext 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 * io.FontGlobalScale * font->Scale * g.CurrentWindow->FontWindowScale). - float FontSizeBeforeScaling; // == value passed to PushFontSize() + float FontSizeBeforeScaling; // == value passed to PushFont() / PushFontSize() when specified. float FontScale; // == FontBaked->Size / Font->FontSize. Scale factor over baked size. float FontRasterizerDensity; // Current font density. Used by all calls to GetFontBaked(). float CurrentDpiScale; // Current window/viewport DpiScale == CurrentViewport->DpiScale