Skip to content

Commit ca72eb0

Browse files
committed
(Breaking) Fonts: obsolete PushFont() default parameter.
1 parent 04a5b9c commit ca72eb0

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

docs/CHANGELOG.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,25 @@ Breaking changes:
7373
Platform_GetWindowFramebufferScale() handler in 'docking' branch.
7474
- Fonts: **IMPORTANT** on Font Sizing:
7575
- Before 1.92, fonts were of a single size. They can now be dynamically sized.
76-
- PushFont() API now has an optional size parameter. PushFontSize() was also added.
77-
void PushFont(ImFont* font) --> void PushFont(ImFont* font, float size = 0.0f);
78-
- Before 1.92: ImGui::PushFont() always used font "default" size specified in AddFont() call.
79-
- Since 1.92: ImGui::PushFont() preserve the current font size which is a shared value.
76+
- PushFont() API now has a REQUIRED size parameter.
77+
void PushFont(ImFont* font) --> void PushFont(ImFont* font, float size);
78+
- PushFont(font, 0.0f) // Change font and keep current size
79+
- PushFont(NULL, 20.0f) // Keep font and change current size
80+
- PushFont(font, 20.0f) // Change font and set size to 20.0f
81+
- PushFont(font, style.FontSizeBase * 2.0f) // Change font and set size to be twice bigger than current size.
82+
- PushFont(font, font->LegacySize) // Change font and set size to size passed to AddFontXXX() function. Same as pre-1.92 behavor, for fixed size fonts.
8083
- To use old behavior:
8184
- use 'ImGui::PushFont(font, font->LegacySize)' at call site (preferred).
8285
- or set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' in AddFont() call
8386
(not desirable as it requires e.g. all third-party code to be aware of it).
87+
We intentionally didn't add a default parameter because it would make the long-term
88+
transition more difficult.
89+
- Kept inline redirection font. Will obsolete.
90+
- External scale factors may be applied over the provided size.
91+
This is why it is called 'FontSizeBase' in the style structure.
8492
- ImFont::FontSize was removed and does not make sense anymore.
8593
ImFont::LegacySize is the size passed to AddFont().
86-
- Removed support for PushFont(NULL) which was a shortcut for "default font".
94+
- Removed support for old PushFont(NULL) which was a shortcut for "revert to default font".
8795
- Renamed/moved 'io.FontGlobalScale' to 'style.FontScaleMain'.
8896
- Fonts: **IMPORTANT** on Font Merging:
8997
- When searching for a glyph in multiple merged fonts: font inputs are now scanned in order
@@ -182,8 +190,8 @@ Breaking changes:
182190
- renamed ImGuiFreeType::GetBuilderForFreeType() to ImGuiFreeType::GetFontLoader()
183191
- old: io.Fonts->FontBuilderIO = ImGuiFreeType::GetBuilderForFreeType()
184192
- new: io.Fonts.FontLoader = ImGuiFreeType::GetFontLoader();
185-
- DrawList: Fixed a regression from 1.91.1 where a Begin()/PushFont()/AddImage() sequence
186-
would not restore the correct atlas Texture Identifier when the PushFont() call used
193+
- DrawList: Fixed a regression from 1.91.1 where a Begin()/PushFont()/AddImage() sequence
194+
would not restore the correct atlas Texture Identifier when the PushFont() call used
187195
a font from a different atlas. (#8694, caused by #3224, #3875, #6398, #7903)
188196
- DrawList: Renamed ImDrawList::PushTextureID()/PopTextureID() to PushTexture()/PopTexture().
189197
- Fonts: (users of custom rectangles)
@@ -332,7 +340,7 @@ Other changes:
332340
one in docking (they accidentally diverged). (#8554)
333341
- Windows: BeginChild(): fixed being unable to combine manual resize on one axis
334342
and automatic resize on the other axis. (#8690)
335-
e.g. neither ImGuiChildFlags_ResizeX | ImGuiChildFlags_AutoResizeY
343+
e.g. neither ImGuiChildFlags_ResizeX | ImGuiChildFlags_AutoResizeY
336344
or ImGuiChildFlags_ResizeY | ImGuiChildFlags_AutoResizeX worked before.
337345
- TreeNode: added experimental flags to draw tree hierarchy outlines linking
338346
parent and tree nodes: (#2920)
@@ -357,7 +365,7 @@ Other changes:
357365
- TreeNode: fixed incorrect clipping of arrow/bullet when using ImGuiTreeNodeFlags_SpanAllColumns.
358366
- InputText: fixed cursor positioning issue using up/down keys near end of lines while
359367
editing non-ASCII text. (Regression from 1.91.2) (#8635, #7925)
360-
- InputText: fixed a buffer overrun that could happen when using dynamically resizing
368+
- InputText: fixed a buffer overrun that could happen when using dynamically resizing
361369
buffers (e.g. imgui_stdlib.cpp for std::string, or ImGuiInputTextFlags_CallbackRezize)
362370
and programmatically making an insertion. (#8689) [@ocornut, @m9710797]
363371
- Tables: fixed TableHeader() eager vertical clipping of text which may be noticeable

imgui.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,11 @@ CODE
470470
- With a legacy backend (< 1.92): Instead of setting io.FontGlobalScale = 1.0f/N -> set ImFontCfg::RasterizerDensity = N. This already worked before, but is now pretty much required.
471471
- With a new backend (1.92+): This should be all automatic. FramebufferScale is automatically used to set current font RasterizerDensity. FramebufferScale is a per-viewport property provided by backend through the Platform_GetWindowFramebufferScale() handler in 'docking' branch.
472472
- Fonts: **IMPORTANT** on Font Sizing: Before 1.92, fonts were of a single size. They can now be dynamically sized.
473-
- PushFont() API now has an optional size parameter. PushFontSize() was also added.
474-
- Before 1.92: ImGui::PushFont() always used font "default" size specified in AddFont() call.
475-
- Since 1.92: ImGui::PushFont() preserve the current font size which is a shared value.
473+
- PushFont() API now has a REQUIRED size parameter. PushFontSize() was also added.
474+
- Before 1.92: PushFont() always used font "default" size specified in AddFont() call. It is equivalent to calling PushFont(font, font->LegacySize).
475+
- Since 1.92: PushFont(font, 0.0f) preserve the current font size which is a shared value.
476476
- To use old behavior: (A) use 'ImGui::PushFont(font, font->LegacySize)' at call site (preferred). (B) Set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' in AddFont() call (not desirable as it requires e.g. third-party code to be aware of it).
477+
- Kept inline single parameter function. Will obsolete.
477478
- Fonts: **IMPORTANT** on Font Merging:
478479
- When searching for a glyph in multiple merged fonts: font inputs are now scanned in orderfor the first font input which the desired glyph. This is technically a different behavior than before!
479480
- e.g. If you are merging fonts you may have glyphs that you expected to load from Font Source 2 which exists in Font Source 1. After the update and when using a new backend, those glyphs may now loaded from Font Source 1!
@@ -8901,23 +8902,22 @@ void ImGui::SetFontRasterizerDensity(float rasterizer_density)
89018902
UpdateCurrentFontSize(0.0f);
89028903
}
89038904

8904-
// If you want to scale an existing font size:
8905-
// - Use e.g. PushFontSize(style.FontSizeBase * factor) (= value before external scale factors applied).
8906-
// - Do NOT use PushFontSize(GetFontSize() * factor) (= value after external scale factors applied).
8905+
// If you want to scale an existing font size! Read comments in imgui.h!
89078906
void ImGui::PushFont(ImFont* font, float font_size_base)
89088907
{
89098908
ImGuiContext& g = *GImGui;
89108909
//if (font == NULL) // Before 1.92 (June 2025), PushFont(NULL) == PushFont(GetDefaultFont())
89118910
// font = g.Font;
89128911
IM_ASSERT(font != NULL);
8912+
IM_ASSERT(font_size_base >= 0.0f);
89138913

89148914
g.FontStack.push_back({ g.Font, g.FontSizeBase, g.FontSize });
8915-
if (font_size_base <= 0.0f)
8915+
if (font_size_base == 0.0f)
89168916
{
89178917
if (font->Flags & ImFontFlags_DefaultToLegacySize)
8918-
font_size_base = font->LegacySize; // Legacy: use AddFont() specified font size. Same as doing PushFont(font, font->LegacySize)
8918+
font_size_base = font->LegacySize; // Legacy: use AddFont() specified font size. Same as doing PushFont(font, font->LegacySize)
89198919
else
8920-
font_size_base = g.FontSizeBase; // Keep current font size
8920+
font_size_base = g.FontSizeBase; // Keep current font size
89218921
}
89228922
SetCurrentFont(font, font_size_base, 0.0f);
89238923
}
@@ -16909,7 +16909,7 @@ void ImGui::DebugNodeFont(ImFont* font)
1690916909
Indent();
1691016910
if (cfg->ShowFontPreview)
1691116911
{
16912-
PushFont(font);
16912+
PushFont(font, 0.0f);
1691316913
Text("The quick brown fox jumps over the lazy dog");
1691416914
PopFont();
1691516915
}

imgui.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,21 +493,26 @@ namespace ImGui
493493
IMGUI_API void SetScrollFromPosY(float local_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position visible. Generally GetCursorStartPos() + offset to compute a valid position.
494494

495495
// Parameters stacks (font)
496+
// - PushFont(font, 0.0f) // Change font and keep current size
497+
// - PushFont(NULL, 20.0f) // Keep font and change current size
498+
// - PushFont(font, 20.0f) // Change font and set size to 20.0f
499+
// - PushFont(font, style.FontSizeBase * 2.0f) // Change font and set size to be twice bigger than current size.
500+
// - PushFont(font, font->LegacySize) // Change font and set size to size passed to AddFontXXX() function. Same as pre-1.92 behavior.
496501
// *IMPORTANT* before 1.92, fonts had a single size. They can now be dynamically be adjusted.
497-
// - Before 1.92: PushFont() always used font default size.
498-
// - Since 1.92: PushFont() preserve the current shared font size.
499-
// - To use old behavior (single size font, size specified in AddFontXXX() call:
500-
// - Use 'PushFont(font, font->LegacySize)' at call site
501-
// - Or set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' before calling AddFont(), and then 'PushFont(font)' will use this size.
502-
// *IMPORTANT* External scale factors are applied over the provided value. If you want to scale an existing font size:
503-
// - OK: PushFontSize(style.FontSizeBase * 2.0f) (= value before external scale factors applied).
504-
// - NOT OK: PushFontSize(GetFontSize() * 2.0f) (= value after external scale factors applied. External scale factors are: 'style.FontScaleMain * style.FontScaleDpi * maybe more').
505-
IMGUI_API void PushFont(ImFont* font, float font_size_base = -1); // use NULL as a shortcut to push default font. Use <0.0f to keep current font size.
502+
// - In 1.92 we have REMOVED the single parameter version of PushFont() because it seems like the easiest way to provide an error-proof transition.
503+
// - PushFont(font) before 1.92 = PushFont(font, font->LegacySize) after 1.92 // Use default font size as passed to AddFontXXX() function.
504+
// *IMPORTANT* external scale factors are applied over the provided size. If you want to scale an *existing* font size:
505+
// - External scale factors are: 'style.FontScaleMain * style.FontScaleDpi' and maybe more.
506+
// - CORRECT: PushFont(NULL, style.FontSizeBase) // use current unscaled size == does nothing
507+
// - CORRECT: PushFont(NULL, style.FontSizeBase * 2.0f) // use current unscaled size x2 == make text twice bigger
508+
// - INCORRECT: PushFont(NULL, GetFontSize()) // INCORRECT! use size after external factors applied == EXTERNAL SCALING FACTORS WILL APPLY TWICE!
509+
// - INCORRECT: PushFont(NULL, GetFontSize() * 2.0f) // INCORRECT! use size after external factors applied == EXTERNAL SCALING FACTORS WILL APPLY TWICE!
510+
IMGUI_API void PushFont(ImFont* font, float font_size_base_unscaled); // Use NULL as a shortcut to keep current font. Use 0.0f to keep current size.
506511
IMGUI_API void PopFont();
507512
IMGUI_API void PushFontSize(float font_size_base); // keep current font, change its size. Final 'font size = font_size_base * external scale factors'.
508513
IMGUI_API void PopFontSize();
509514
IMGUI_API ImFont* GetFont(); // get current font
510-
IMGUI_API float GetFontSize(); // get current font size (= height in pixels) AFTER external scale factors applied. *IMPORTANT* DO NOT PASS THIS VALUE TO PushFont()/PushFontSize()! Use ImGui::GetStyle().FontSizeBase to get value before external scale factors.
515+
IMGUI_API float GetFontSize(); // get current scaled font size (= height in pixels). AFTER external scale factors applied. *IMPORTANT* DO NOT PASS THIS VALUE TO PushFont()/PushFontSize()! Use ImGui::GetStyle().FontSizeBase to get value before external scale factors.
511516
IMGUI_API ImFontBaked* GetFontBaked(); // get current font bound at current size // == GetFont()->GetFontBaked(GetFontSize())
512517

513518
// Parameters stacks (shared)
@@ -3756,7 +3761,7 @@ struct ImFontBaked
37563761
enum ImFontFlags_
37573762
{
37583763
ImFontFlags_None = 0,
3759-
ImFontFlags_DefaultToLegacySize = 1 << 0, // Legacy compatibility: make PushFont() calls without explicit size use font->LegacySize instead of current font size.
3764+
ImFontFlags_DefaultToLegacySize = 1 << 0, // Legacy compatibility: make `PushFont(font)` == `PushFont(font, font->LegacySize)`. Otherwise by default/shared current font size is used.
37603765
ImFontFlags_NoLoadError = 1 << 1, // Disable throwing an error/assert when calling AddFontXXX() with missing file/data. Calling code is expected to check AddFontXXX() return value.
37613766
ImFontFlags_NoLoadGlyphs = 1 << 2, // [Internal] Disable loading new glyphs.
37623767
ImFontFlags_LockBakedSizes = 1 << 3, // [Internal] Disable loading new baked sizes, disable garbage collecting current ones. e.g. if you want to lock a font to a single size. Important: if you use this to preload given sizes, consider the possibility of multiple font density used on Retina display.
@@ -3949,7 +3954,8 @@ struct ImGuiPlatformImeData
39493954
namespace ImGui
39503955
{
39513956
// OBSOLETED in 1.92.0 (from June 2025)
3952-
IMGUI_API void SetWindowFontScale(float scale); // Set font scale factor for current window. Prefer using PushFontSize(style.FontSizeBase * factor) or use style.FontScaleMain to scale all windows.
3957+
static inline void PushFont(ImFont* font) { IM_ASSERT(font != NULL); PushFont(font, font->LegacySize); }
3958+
IMGUI_API void SetWindowFontScale(float scale); // Set font scale factor for current window. Prefer using PushFont(NULL, style.FontSizeBase * factor) or use style.FontScaleMain to scale all windows.
39533959
// OBSOLETED in 1.91.9 (from February 2025)
39543960
IMGUI_API void Image(ImTextureRef tex_ref, const ImVec2& image_size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col); // <-- 'border_col' was removed in favor of ImGuiCol_ImageBorder. If you use 'tint_col', use ImageWithBg() instead.
39553961
// OBSOLETED in 1.91.0 (from July 2024)

0 commit comments

Comments
 (0)