From f3780c73544466ebe10c6c31749d57d605210b48 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 19 May 2025 18:14:12 +0200 Subject: [PATCH] Fonts: adding GetFontBaked() in public API. --- imgui.cpp | 5 +++++ imgui.h | 5 +++-- imgui_internal.h | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 58455df8d..13cb78f0b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8419,6 +8419,11 @@ ImFont* ImGui::GetFont() return GImGui->Font; } +ImFontBaked* ImGui::GetFontBaked() +{ + return GImGui->FontBaked; +} + float ImGui::GetFontSize() { return GImGui->FontSize; diff --git a/imgui.h b/imgui.h index 0eb83cd9a..916ad7547 100644 --- a/imgui.h +++ b/imgui.h @@ -495,7 +495,7 @@ namespace ImGui // *IMPORTANT* before 1.92, fonts had a single size. They can now be dynamically be adjusted. // - Before 1.92: PushFont() always used font default size. // - Since 1.92: PushFont() preserve the current shared font size. - // - To use old behavior: use 'PushFont(font, font->DefaultSize)' in call site, or set 'ImFontConfig::Flags |= ImFontFlags_UseDefaultSize' before calling AddFont(). + // - To use old behavior (single size font): use 'PushFont(font, font->DefaultSize)' in call site, or set 'ImFontConfig::Flags |= ImFontFlags_UseDefaultSize' before calling AddFont(). IMGUI_API void PushFont(ImFont* font, float font_size = -1); // use NULL as a shortcut to push default font. Use <0.0f to keep current font size. Use font->DefaultSize to revert to font default size. IMGUI_API void PopFont(); IMGUI_API void PushFontSize(float font_size); @@ -526,6 +526,7 @@ namespace ImGui IMGUI_API ImFont* GetFont(); // get current font IMGUI_API float GetFontSize(); // get current font size (= height in pixels) of current font with current scale applied IMGUI_API ImVec2 GetFontTexUvWhitePixel(); // get UV coordinate for a white pixel, useful to draw custom shapes via the ImDrawList API + IMGUI_API ImFontBaked* GetFontBaked(); // get current font bound at current size // == GetFont()->GetFontBaked(GetFontSize()) IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul = 1.0f); // retrieve given style color with style alpha applied and optional extra alpha multiplier, packed as a 32-bit value suitable for ImDrawList IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied, packed as a 32-bit value suitable for ImDrawList IMGUI_API ImU32 GetColorU32(ImU32 col, float alpha_mul = 1.0f); // retrieve given color with style alpha applied, packed as a 32-bit value suitable for ImDrawList @@ -3754,7 +3755,7 @@ struct ImFont // [Internal] Members: Cold ~24-52 bytes // Conceptually Sources[] is the list of font sources merged to create this font. ImGuiID FontId; // Unique identifier for the font - float DefaultSize; // 4 // in // Default font size + float DefaultSize; // 4 // in // Default font size passed to AddFont(). It's unlikely you should use this (use ImGui::GetFontBaked() to get font baked at current bound size). 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, '?') diff --git a/imgui_internal.h b/imgui_internal.h index b1d8774ce..b4ddf4175 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2136,9 +2136,9 @@ struct ImGuiContext ImGuiPlatformIO PlatformIO; ImGuiStyle Style; ImVector FontAtlases; // List of font atlases used by the context (generally only contains g.IO.Fonts aka the main font atlas) - ImFont* Font; // == FontStack.back().Font - ImFontBaked* FontBaked; // == Font->GetFontBaked(FontSize) - float FontSize; // == FontSizeBeforeScaling * io.FontGlobalScale * font->Scale * g.CurrentWindow->FontWindowScale. Current text height. + 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 FontScale; // == FontBaked->Size / Font->FontSize. Scale factor over baked size. float FontRasterizerDensity; // Current font density. Used by all calls to GetFontBaked().