diff --git a/imgui.cpp b/imgui.cpp index 07e4ad5a..9330f28f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3832,6 +3832,7 @@ void ImGui::GcCompactTransientWindowBuffers(ImGuiWindow* window) window->DC.ChildWindows.clear(); window->DC.ItemWidthStack.clear(); window->DC.TextWrapPosStack.clear(); + window->DC.TextAlignmentStack.clear(); } void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window) @@ -6784,6 +6785,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.TextWrapPos = -1.0f; // disabled window->DC.ItemWidthStack.resize(0); window->DC.TextWrapPosStack.resize(0); + window->DC.TextAlignmentStack.resize(0); if (window->AutoFitFramesX > 0) window->AutoFitFramesX--; @@ -7234,6 +7236,20 @@ void ImGui::PopTextWrapPos() window->DC.TextWrapPosStack.pop_back(); } +void ImGui::PushTextAlignment(float alignment) +{ + ImGuiWindow *window = GetCurrentWindow(); + window->DC.TextAlignmentStack.push_back(window->DC.TextAlignment); + window->DC.TextAlignment = alignment; +} + +void ImGui::PopTextAlignment() +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.TextAlignment = window->DC.TextAlignmentStack.back(); + window->DC.TextAlignmentStack.pop_back(); +} + static ImGuiWindow* GetCombinedRootWindow(ImGuiWindow* window, bool popup_hierarchy) { ImGuiWindow* last_window = NULL; diff --git a/imgui.h b/imgui.h index c7f53448..e5b29fa1 100644 --- a/imgui.h +++ b/imgui.h @@ -424,6 +424,8 @@ namespace ImGui IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position. NOT necessarily the width of last item unlike most 'Item' functions. IMGUI_API void PushTextWrapPos(float wrap_local_pos_x = 0.0f); // push word-wrapping position for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space IMGUI_API void PopTextWrapPos(); + IMGUI_API void PushTextAlignment(float alignment = 0.0f); // push text alignment position for TextWrapped*() commands. 0.0f: no alignment; 1.0f: align right; 0.5f: align center + IMGUI_API void PopTextAlignment(); // Style read access // - Use the ShowStyleEditor() function to interactively see/edit the colors. diff --git a/imgui_internal.h b/imgui_internal.h index 70a62334..3204d48d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2296,8 +2296,11 @@ struct IMGUI_API ImGuiWindowTempData // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings. float ItemWidth; // Current item width (>0.0: width in pixels, <0.0: align xx pixels to the right of window). float TextWrapPos; // Current text wrap pos. + float TextAlignment; // Current text alignment. ImVector ItemWidthStack; // Store item widths to restore (attention: .back() is not == ItemWidth) ImVector TextWrapPosStack; // Store text wrap pos to restore (attention: .back() is not == TextWrapPos) + ImVector TextAlignmentStack; // Store text alignment to restore (attention: .back() is not == TextAlignment) + ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting }; // Storage for one window