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

Fonts: internals: renamed g.FontSizeBeforeScaling to g.FontSizeBase for consistency.

# Conflicts:
#	imgui_internal.h
This commit is contained in:
ocornut 2025-06-05 14:54:46 +02:00
parent 3c27c643a9
commit 2d2b1cee6b
4 changed files with 16 additions and 15 deletions

View file

@ -1358,8 +1358,8 @@ static void* GImAllocatorUserData = NULL;
ImGuiStyle::ImGuiStyle() ImGuiStyle::ImGuiStyle()
{ {
FontSizeBase = 0.0f; // Will default to io.Fonts->Fonts[0] on first frame. FontSizeBase = 0.0f; // Will default to io.Fonts->Fonts[0] on first frame.
FontScaleMain = 1.0f; // Main global scale factor. FontScaleMain = 1.0f; // Main scale factor. May be set by application once, or exposed to end-user.
FontScaleDpi = 1.0f; // Scale factor from viewport/monitor. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor DPI. FontScaleDpi = 1.0f; // Additional scale factor from viewport/monitor contents scale. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor DPI.
Alpha = 1.0f; // Global alpha applies to everything in Dear ImGui. Alpha = 1.0f; // Global alpha applies to everything in Dear ImGui.
DisabledAlpha = 0.60f; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha. DisabledAlpha = 0.60f; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha.
@ -3979,7 +3979,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
Initialized = false; Initialized = false;
Font = NULL; Font = NULL;
FontBaked = NULL; FontBaked = NULL;
FontSize = FontSizeBeforeScaling = FontBakedScale = CurrentDpiScale = 0.0f; FontSize = FontSizeBase = FontBakedScale = CurrentDpiScale = 0.0f;
FontRasterizerDensity = 1.0f; FontRasterizerDensity = 1.0f;
IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)();
if (shared_font_atlas == NULL) if (shared_font_atlas == NULL)
@ -8651,7 +8651,7 @@ void ImGui::UpdateFontsNewFrame()
// Set initial font // Set initial font
g.Font = font; g.Font = font;
g.FontSizeBeforeScaling = g.Style.FontSizeBase; g.FontSizeBase = g.Style.FontSizeBase;
g.FontSize = 0.0f; g.FontSize = 0.0f;
ImFontStackData font_stack_data = { font, g.Style.FontSizeBase, g.Style.FontSizeBase }; // <--- Will restore FontSize ImFontStackData font_stack_data = { font, g.Style.FontSizeBase, g.Style.FontSizeBase }; // <--- Will restore FontSize
SetCurrentFont(font_stack_data.Font, font_stack_data.FontSizeBeforeScaling, 0.0f); // <--- but use 0.0f to enable scale SetCurrentFont(font_stack_data.Font, font_stack_data.FontSizeBeforeScaling, 0.0f); // <--- but use 0.0f to enable scale
@ -8717,7 +8717,7 @@ void ImGui::SetCurrentFont(ImFont* font, float font_size_before_scaling, float f
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
g.Font = font; g.Font = font;
g.FontSizeBeforeScaling = font_size_before_scaling; g.FontSizeBase = font_size_before_scaling;
UpdateCurrentFontSize(font_size_after_scaling); UpdateCurrentFontSize(font_size_after_scaling);
if (font != NULL) if (font != NULL)
@ -8738,7 +8738,7 @@ void ImGui::UpdateCurrentFontSize(float restore_font_size_after_scaling)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
g.Style.FontSizeBase = g.FontSizeBeforeScaling; g.Style.FontSizeBase = g.FontSizeBase;
if (window != NULL && window->SkipItems) if (window != NULL && window->SkipItems)
return; return;
@ -8746,7 +8746,7 @@ void ImGui::UpdateCurrentFontSize(float restore_font_size_after_scaling)
float final_size = (restore_font_size_after_scaling > 0.0f) ? restore_font_size_after_scaling : 0.0f; float final_size = (restore_font_size_after_scaling > 0.0f) ? restore_font_size_after_scaling : 0.0f;
if (final_size == 0.0f) if (final_size == 0.0f)
{ {
final_size = g.FontSizeBeforeScaling; final_size = g.FontSizeBase;
// External scale factors // External scale factors
final_size *= g.Style.FontScaleMain; // Main global scale factor final_size *= g.Style.FontScaleMain; // Main global scale factor
@ -8796,7 +8796,7 @@ void ImGui::SetFontRasterizerDensity(float rasterizer_density)
void ImGui::PushFont(ImFont* font, float font_size_base) void ImGui::PushFont(ImFont* font, float font_size_base)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
g.FontStack.push_back({ g.Font, g.FontSizeBeforeScaling, g.FontSize }); g.FontStack.push_back({ g.Font, g.FontSizeBase, g.FontSize });
if (font == NULL) if (font == NULL)
font = GetDefaultFont(); font = GetDefaultFont();
if (font_size_base <= 0.0f) if (font_size_base <= 0.0f)
@ -8804,7 +8804,7 @@ void ImGui::PushFont(ImFont* font, float font_size_base)
if (font->Flags & ImFontFlags_DefaultToLegacySize) if (font->Flags & ImFontFlags_DefaultToLegacySize)
font_size_base = font->LegacySize; // Legacy: use AddFont() specified font size. Same as doing PushFont(font, font->LegacySize) font_size_base = font->LegacySize; // Legacy: use AddFont() specified font size. Same as doing PushFont(font, font->LegacySize)
else else
font_size_base = g.FontSizeBeforeScaling; // Keep current font size font_size_base = g.FontSizeBase; // Keep current font size
} }
SetCurrentFont(font, font_size_base, 0.0f); SetCurrentFont(font, font_size_base, 0.0f);
} }

View file

@ -2227,9 +2227,10 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
struct ImGuiStyle struct ImGuiStyle
{ {
float FontSizeBase; // Current base font size before external scaling factors are applied. Use PushFont()/PushFontSize() to modify. Use ImGui::GetFontSize() to obtain scaled value. Final FontSize = FontSizeBase * (FontScaleBase * FontScaleDpi * other_factors) // ImGui::GetFontSize() == FontSizeBase * (FontScaleMain * FontScaleDpi * other_scaling_factors)
float FontSizeBase; // Current base font size before external scaling factors are applied. Use PushFont()/PushFontSize() to modify. Use ImGui::GetFontSize() to obtain scaled value.
float FontScaleMain; // Main scale factor. May be set by application once, or exposed to end-user. float FontScaleMain; // Main scale factor. May be set by application once, or exposed to end-user.
float FontScaleDpi; // Scale factor from viewport/monitor contents scale. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor. float FontScaleDpi; // Additional scale factor from viewport/monitor contents scale. When io.ConfigDpiScaleFonts is enabled, this is automatically overwritten when changing monitor DPI.
float Alpha; // Global alpha applies to everything in Dear ImGui. float Alpha; // Global alpha applies to everything in Dear ImGui.
float DisabledAlpha; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha. float DisabledAlpha; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha.

View file

@ -3193,7 +3193,7 @@ static void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font,
bool need_bind_ctx = ctx != curr_ctx; bool need_bind_ctx = ctx != curr_ctx;
if (need_bind_ctx) if (need_bind_ctx)
ImGui::SetCurrentContext(ctx); ImGui::SetCurrentContext(ctx);
ImGui::SetCurrentFont(new_font, ctx->FontSizeBeforeScaling, ctx->FontSize); ImGui::SetCurrentFont(new_font, ctx->FontSizeBase, ctx->FontSize);
if (need_bind_ctx) if (need_bind_ctx)
ImGui::SetCurrentContext(curr_ctx); ImGui::SetCurrentContext(curr_ctx);
} }

View file

@ -2139,8 +2139,8 @@ struct ImGuiContext
ImVector<ImFontAtlas*> FontAtlases; // List of font atlases used by the context (generally only contains g.IO.Fonts aka the main font atlas) ImVector<ImFontAtlas*> FontAtlases; // List of font atlases used by the context (generally only contains g.IO.Fonts aka the main font atlas)
ImFont* Font; // Currently bound font. (== FontStack.back().Font) ImFont* Font; // Currently bound font. (== FontStack.back().Font)
ImFontBaked* FontBaked; // Currently bound font at currently bound size. (== Font->GetFontBaked(FontSize)) ImFontBaked* FontBaked; // Currently bound font at currently bound size. (== Font->GetFontBaked(FontSize))
float FontSize; // Currently bound font size == line height (== FontSizeBeforeScaling + externals scales applied in the UpdateCurrentFontSize() function). float FontSize; // Currently bound font size == line height (== FontSizeBase + externals scales applied in the UpdateCurrentFontSize() function).
float FontSizeBeforeScaling; // Font size before scaling == style.FontSizeBase == value passed to PushFont() / PushFontSize() when specified. float FontSizeBase; // Font size before scaling == style.FontSizeBase == value passed to PushFont() / PushFontSize() when specified.
float FontBakedScale; // == FontBaked->Size / FontSize. Scale factor over baked size. Rarely used nowadays, very often == 1.0f. float FontBakedScale; // == FontBaked->Size / FontSize. Scale factor over baked size. Rarely used nowadays, very often == 1.0f.
float FontRasterizerDensity; // Current font density. Used by all calls to GetFontBaked(). float FontRasterizerDensity; // Current font density. Used by all calls to GetFontBaked().
float CurrentDpiScale; // Current window/viewport DpiScale == CurrentViewport->DpiScale float CurrentDpiScale; // Current window/viewport DpiScale == CurrentViewport->DpiScale
@ -2690,7 +2690,7 @@ public:
ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight; return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight); } ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight; return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight); }
// [Obsolete] ImGuiWindow::CalcFontSize() was removed in 1.92.x because error-prone/misleading. You can use window->FontRefSize for a copy of g.FontSize at the time of the last Begin() call for this window. // [Obsolete] ImGuiWindow::CalcFontSize() was removed in 1.92.x because error-prone/misleading. You can use window->FontRefSize for a copy of g.FontSize at the time of the last Begin() call for this window.
//float CalcFontSize() const { ImGuiContext& g = *Ctx; return g.FontBaseSize * FontWindowScale * FontWindowScaleParents; } //float CalcFontSize() const { ImGuiContext& g = *Ctx; return g.FontSizeBase * FontWindowScale * FontWindowScaleParents;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------