1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-21 01:44:21 +00:00

(Breaking) Fonts: PushFont() default to preserve current font size.

This commit is contained in:
ocornut 2025-03-21 19:13:23 +01:00
parent 168b97c291
commit 44498825cd
3 changed files with 19 additions and 7 deletions

View file

@ -8582,7 +8582,7 @@ void ImGui::UpdateFontsNewFrame()
atlas->Locked = true;
// We do this really unusual thing of calling *push_front()*, the reason behind that we want to support the PushFont()/NewFrame()/PopFont() idiom.
ImFontStackData font_stack_data = { ImGui::GetDefaultFont(), ImGui::GetDefaultFont()->Sources[0].SizePixels };
ImFontStackData font_stack_data = { ImGui::GetDefaultFont(), ImGui::GetDefaultFont()->DefaultSize };
g.FontStack.push_front(font_stack_data);
if (g.FontStack.Size == 1)
ImGui::SetCurrentFont(font_stack_data.Font, font_stack_data.FontSize);
@ -8647,8 +8647,13 @@ void ImGui::PushFont(ImFont* font, float font_size)
ImGuiContext& g = *GImGui;
if (font == NULL)
font = GetDefaultFont();
if (font_size < 0.0f)
font_size = font->Sources[0].SizePixels; // g.FontSize;
if (font_size <= 0.0f)
{
if (font->Flags & ImFontFlags_UseDefaultSize)
font_size = font->DefaultSize; // Legacy: use default font size. Same as doing PushFont(font, font->DefaultSize). // FIXME-NEWATLAS
else
font_size = g.FontSizeBeforeScaling; // Keep current font size
}
g.FontStack.push_back({ font, font_size });
SetCurrentFont(font, font_size);
}