@@ -4012,7 +4012,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
40124012 Initialized = false;
40134013 Font = NULL;
40144014 FontBaked = NULL;
4015- FontSize = FontSizeBase = FontBakedScale = CurrentDpiScale = 0.0f;
4015+ FontSize = FontSizeBase = FontBakedScale = LineHeight = CurrentDpiScale = 0.0f;
40164016 FontRasterizerDensity = 1.0f;
40174017 IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)();
40184018 if (shared_font_atlas == NULL)
@@ -5961,10 +5961,9 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
59615961 text_display_end = text_end;
59625962
59635963 ImFont* font = g.Font;
5964- const float font_size = g.FontSize;
59655964 if (text == text_display_end)
5966- return ImVec2(0.0f, font_size );
5967- ImVec2 text_size = font->CalcTextSizeA(font_size , FLT_MAX, wrap_width, text, text_display_end, NULL);
5965+ return ImVec2(0.0f, g.LineHeight );
5966+ ImVec2 text_size = font->CalcTextSizeA(g.FontSize , FLT_MAX, wrap_width, text, text_display_end, NULL);
59685967
59695968 // Round
59705969 // FIXME: This has been here since Dec 2015 (7b0bf230) but down the line we want this out.
@@ -7057,7 +7056,7 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
70577056 // FIXME: Would be nice to generalize the subtleties expressed here into reusable code.
70587057 float pad_l = style.FramePadding.x;
70597058 float pad_r = style.FramePadding.x;
7060- float button_sz = g.FontSize ;
7059+ float button_sz = g.LineHeight ;
70617060 ImVec2 close_button_pos;
70627061 ImVec2 collapse_button_pos;
70637062 if (has_close_button)
@@ -7085,7 +7084,7 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
70857084 if (has_close_button)
70867085 {
70877086 g.CurrentItemFlags |= ImGuiItemFlags_NoFocus;
7088- if (CloseButton(window->GetID("#CLOSE"), close_button_pos))
7087+ if (CloseButton(window->GetID("#CLOSE"), close_button_pos, button_sz ))
70897088 *p_open = false;
70907089 g.CurrentItemFlags &= ~ImGuiItemFlags_NoFocus;
70917090 }
@@ -7440,8 +7439,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
74407439 // Lock menu offset so size calculation can use it as menu-bar windows need a minimum size.
74417440 window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x);
74427441 window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y;
7443- window->TitleBarHeight = (flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : g.FontSize + g.Style.FramePadding.y * 2.0f;
7444- window->MenuBarHeight = (flags & ImGuiWindowFlags_MenuBar) ? window->DC.MenuBarOffset.y + g.FontSize + g.Style.FramePadding.y * 2.0f : 0.0f;
7442+ window->TitleBarHeight = (flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : g.LineHeight + g.Style.FramePadding.y * 2.0f;
7443+ window->MenuBarHeight = (flags & ImGuiWindowFlags_MenuBar) ? window->DC.MenuBarOffset.y + g.LineHeight + g.Style.FramePadding.y * 2.0f : 0.0f;
74457444 window->FontRefSize = g.FontSize; // Lock this to discourage calling window->CalcFontSize() outside of current window.
74467445
74477446 // Depending on condition we use previous or current window size to compare against contents size to decide if a scrollbar should be visible.
@@ -7574,9 +7573,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
75747573 // Large values tend to lead to variety of artifacts and are not recommended.
75757574 window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding;
75767575
7577- // For windows with title bar or menu bar, we clamp to FrameHeight(FontSize + FramePadding.y * 2.0f) to completely hide artifacts.
7576+ // For windows with title bar or menu bar, we clamp to FrameHeight(LineHeight + FramePadding.y * 2.0f) to completely hide artifacts.
75787577 //if ((window->Flags & ImGuiWindowFlags_MenuBar) || !(window->Flags & ImGuiWindowFlags_NoTitleBar))
7579- // window->WindowRounding = ImMin(window->WindowRounding, g.FontSize + style.FramePadding.y * 2.0f);
7578+ // window->WindowRounding = ImMin(window->WindowRounding, g.LineHeight + style.FramePadding.y * 2.0f);
75807579
75817580 // Apply window focus (new and reactivated windows are moved to front)
75827581 bool want_focus = false;
@@ -8745,8 +8744,8 @@ void ImGui::UpdateFontsNewFrame()
87458744 g.Font = font;
87468745 g.FontSizeBase = g.Style.FontSizeBase;
87478746 g.FontSize = 0.0f;
8748- ImFontStackData font_stack_data = { font, g.Style.FontSizeBase, g.Style.FontSizeBase }; // <--- Will restore FontSize
8749- SetCurrentFont(font_stack_data.Font, font_stack_data.FontSizeBeforeScaling, 0.0f); // <--- but use 0.0f to enable scale
8747+ ImFontStackData font_stack_data = { font, g.Style.FontSizeBase, g.Style.FontSizeBase }; // <--- Will restore FontSize
8748+ SetCurrentFont(font_stack_data.Font, font_stack_data.FontSizeBeforeScaling, 0.0f); // <--- but use 0.0f to enable scale
87508749 g.FontStack.push_back(font_stack_data);
87518750 IM_ASSERT(g.Font->IsLoaded());
87528751}
@@ -8875,6 +8874,7 @@ void ImGui::UpdateCurrentFontSize(float restore_font_size_after_scaling)
88758874 g.Font->CurrentRasterizerDensity = g.FontRasterizerDensity;
88768875 g.FontSize = final_size;
88778876 g.FontBaked = (g.Font != NULL && window != NULL) ? g.Font->GetFontBaked(final_size) : NULL;
8877+ g.LineHeight = g.FontBaked ? g.FontBaked->LineHeight : g.FontSize;
88788878 g.FontBakedScale = (g.Font != NULL && window != NULL) ? (g.FontSize / g.FontBaked->Size) : 0.0f;
88798879 g.DrawListSharedData.FontSize = g.FontSize;
88808880 g.DrawListSharedData.FontScale = g.FontBakedScale;
@@ -11365,25 +11365,25 @@ ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
1136511365float ImGui::GetTextLineHeight()
1136611366{
1136711367 ImGuiContext& g = *GImGui;
11368- return g.FontSize ;
11368+ return g.LineHeight ;
1136911369}
1137011370
1137111371float ImGui::GetTextLineHeightWithSpacing()
1137211372{
1137311373 ImGuiContext& g = *GImGui;
11374- return g.FontSize + g.Style.ItemSpacing.y;
11374+ return g.LineHeight + g.Style.ItemSpacing.y;
1137511375}
1137611376
1137711377float ImGui::GetFrameHeight()
1137811378{
1137911379 ImGuiContext& g = *GImGui;
11380- return g.FontSize + g.Style.FramePadding.y * 2.0f;
11380+ return g.LineHeight + g.Style.FramePadding.y * 2.0f;
1138111381}
1138211382
1138311383float ImGui::GetFrameHeightWithSpacing()
1138411384{
1138511385 ImGuiContext& g = *GImGui;
11386- return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y;
11386+ return g.LineHeight + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y;
1138711387}
1138811388
1138911389ImVec2 ImGui::GetContentRegionAvail()
@@ -16660,8 +16660,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1666016660 {
1666116661 char buf[32];
1666216662 ImFormatString(buf, IM_ARRAYSIZE(buf), "%d", window->BeginOrderWithinContext);
16663- float font_size = GetFontSize();
16664- draw_list->AddRectFilled(window->Pos, window->Pos + ImVec2(font_size, font_size), IM_COL32(200, 100, 100, 255));
16663+ draw_list->AddRectFilled(window->Pos, window->Pos + ImVec2(g.FontSize, g.LineHeight), IM_COL32(200, 100, 100, 255));
1666516664 draw_list->AddText(window->Pos, IM_COL32(255, 255, 255, 255), buf);
1666616665 }
1666716666 }
@@ -17044,7 +17043,7 @@ void ImGui::DebugNodeFont(ImFont* font)
1704417043 baked->FindGlyph((ImWchar)base);
1704517044
1704617045 const int surface_sqrt = (int)ImSqrt((float)baked->MetricsTotalSurface);
17047- Text("Ascent: %f, Descent: %f, Ascent-Descent: %f", baked->Ascent, baked->Descent, baked->Ascent - baked->Descent);
17046+ Text("Ascent: %f, Descent: %f, Ascent-Descent: %f, LineHeight: %f ", baked->Ascent, baked->Descent, baked->Ascent - baked->Descent, baked->LineHeight );
1704817047 Text("Texture Area: about %d px ~%dx%d px", baked->MetricsTotalSurface, surface_sqrt, surface_sqrt);
1704917048 for (int src_n = 0; src_n < font->Sources.Size; src_n++)
1705017049 {
@@ -17389,7 +17388,7 @@ void ImGui::ShowDebugLogWindow(bool* p_open)
1738917388{
1739017389 ImGuiContext& g = *GImGui;
1739117390 if ((g.NextWindowData.HasFlags & ImGuiNextWindowDataFlags_HasSize) == 0)
17392- SetNextWindowSize(ImVec2(0.0f, GetFontSize () * 12.0f), ImGuiCond_FirstUseEver);
17391+ SetNextWindowSize(ImVec2(0.0f, GetTextLineHeight () * 12.0f), ImGuiCond_FirstUseEver);
1739317392 if (!Begin("Dear ImGui Debug Log", p_open) || GetCurrentWindow()->BeginCount > 1)
1739417393 {
1739517394 End();
@@ -17709,7 +17708,7 @@ void ImGui::ShowIDStackToolWindow(bool* p_open)
1770917708{
1771017709 ImGuiContext& g = *GImGui;
1771117710 if ((g.NextWindowData.HasFlags & ImGuiNextWindowDataFlags_HasSize) == 0)
17712- SetNextWindowSize(ImVec2(0.0f, GetFontSize () * 8.0f), ImGuiCond_FirstUseEver);
17711+ SetNextWindowSize(ImVec2(0.0f, GetTextLineHeight () * 8.0f), ImGuiCond_FirstUseEver);
1771317712 if (!Begin("Dear ImGui ID Stack Tool", p_open) || GetCurrentWindow()->BeginCount > 1)
1771417713 {
1771517714 End();
0 commit comments