From 3563f4db3204e2f8f5fe3aaadc1e283393ee2718 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 23 Apr 2025 15:08:57 +0200 Subject: [PATCH] Rework TextAligned() api to fix issues with baseline alignment + use standard CalcItemSize(). (#7024) --- imgui_widgets.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 645de0f7a..ccd976392 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -356,13 +356,10 @@ void ImGui::TextAlignedV(float align_x, float size_x, const char* fmt, va_list a if (window->SkipItems) return; - // ~CalcItemSize() - if (size_x <= 0.0f) - size_x = GetContentRegionAvail().x + size_x; // <-- Remember that size_x is negative here - const char* text, *text_end; ImFormatStringToTempBufferV(&text, &text_end, fmt, args); const ImVec2 text_size = CalcTextSize(text, text_end); + size_x = CalcItemSize(ImVec2(size_x, 0.0f), 0.0f, text_size.y).x; ImVec2 pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); ImVec2 pos_max(pos.x + size_x, window->ClipRect.Max.y); @@ -370,10 +367,7 @@ void ImGui::TextAlignedV(float align_x, float size_x, const char* fmt, va_list a window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, pos.x + text_size.x); window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, pos.x + text_size.x); if (align_x > 0.0f && text_size.x < size_x) - { pos.x += ImTrunc((size_x - text_size.x) * align_x); - window->DC.CursorPos = pos; - } RenderTextEllipsis(window->DrawList, pos, pos_max, pos_max.x, text, text_end, &text_size); const ImVec2 backup_max_pos = window->DC.CursorMaxPos;