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

Fonts: added ImGuiStyle::FontSizeBase. Ensuring PushFontSize() works before main loop and across NewFrame().

# Conflicts:
#	imgui.cpp
This commit is contained in:
ocornut 2025-05-26 20:24:06 +02:00
parent b029be6b6c
commit 1e118ab891
5 changed files with 125 additions and 56 deletions

20
imgui.h
View file

@ -498,8 +498,13 @@ 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 (single size font): use 'PushFont(font, font->LegacySize)' in call site, or set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' 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->LegacySize to revert to font size specified by AddFont().
// - To use old behavior (single size font, size specified in AddFontXXX() call:
// - Use 'PushFont(font, font->LegacySize)' at call site
// - Or set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' before calling AddFont(), and then 'PushFont(font)' will use this size.
// *IMPORTANT* If you want to scale an existing font size:
// - OK: PushFontSize(style.FontSizeBase * factor) (= value before external scale factors applied).
// - KO: PushFontSize(GetFontSize() * factor) (= value after external scale factors applied. external scale factors are io.FontGlobalScale and per-viewport scales.).
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.
IMGUI_API void PopFont();
IMGUI_API void PushFontSize(float font_size);
IMGUI_API void PopFontSize();
@ -2222,6 +2227,8 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
struct ImGuiStyle
{
float FontSizeBase; // Current base font size (scaling applied). Use PushFont()/PushFontSize() to modify. Use ImGui::GetFontSize() to obtain scaled value.
float Alpha; // Global alpha applies to everything in Dear ImGui.
float DisabledAlpha; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha.
ImVec2 WindowPadding; // Padding within a window.
@ -2287,8 +2294,13 @@ struct ImGuiStyle
ImGuiHoveredFlags HoverFlagsForTooltipMouse;// Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse.
ImGuiHoveredFlags HoverFlagsForTooltipNav; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad.
IMGUI_API ImGuiStyle();
IMGUI_API void ScaleAllSizes(float scale_factor);
// [Internal]
float _MainScale; // FIXME-WIP: Reference scale, as applied by ScaleAllSizes().
float _NextFrameFontSizeBase; // FIXME: Temporary hack until we finish remaining work.
// Functions
IMGUI_API ImGuiStyle();
IMGUI_API void ScaleAllSizes(float scale_factor);
// Obsolete names
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS