1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-24 02:14:22 +00:00

Fonts: adding new fonts after removing all fonts mid-frame properly updates current state.

This commit is contained in:
ocornut 2026-01-21 19:53:31 +01:00
parent cb3b7ff4fb
commit 3aba95060e
2 changed files with 7 additions and 0 deletions

View file

@ -128,6 +128,7 @@ Other Changes:
is enabled, creating side-effects when later disabling hinting or
dynamically switching to stb_truetype rasterizer.
- Post rescale GlyphOffset is always rounded.
- Adding new fonts after removing all fonts mid-frame properly updates current state.
- Textures:
- Fixed a building issue when ImTextureID is defined as a struct.
- Fixed displaying texture # in Metrics/Debugger window.

View file

@ -3035,6 +3035,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in)
ImFontAtlasBuildInit(this);
// Create new font
const bool is_first_font = (Fonts.Size == 0);
ImFont* font;
if (!font_cfg_in->MergeMode)
{
@ -3092,6 +3093,8 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in)
}
ImFontAtlasFontSourceAddToFont(this, font, font_cfg);
if (is_first_font)
ImFontAtlasBuildNotifySetFont(this, NULL, font);
return font;
}
@ -3254,6 +3257,9 @@ void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont*
shared_data->Font = new_font;
if (ImGuiContext* ctx = shared_data->Context)
{
if (ctx->FrameCount == 0 && old_font == NULL) // While this should work either way, we save ourselves the bother / debugging confusion of running ImGui code so early when it is not needed.
continue;
if (ctx->IO.FontDefault == old_font)
ctx->IO.FontDefault = new_font;
if (ctx->Font == old_font)