From f2c0da3753207598ac9dc549ec13f3277ad7824c Mon Sep 17 00:00:00 2001 From: "SAMSAM5.5" Date: Sat, 30 Aug 2025 12:54:48 +0200 Subject: [PATCH] Add ButtonLeft method Add a new method in the Walnut::UI namespace (UI.h/UI.cpp). This is a slightly modified version of ButtonCentered that creates left-aligned buttons. It can be useful for popups or other menus where alignment matters. --- Walnut/Platform/GUI/Walnut/UI/UI.cpp | 14 ++++++++++++++ Walnut/Platform/GUI/Walnut/UI/UI.h | 1 + 2 files changed, 15 insertions(+) diff --git a/Walnut/Platform/GUI/Walnut/UI/UI.cpp b/Walnut/Platform/GUI/Walnut/UI/UI.cpp index 31efeb019..fb5b8cda3 100644 --- a/Walnut/Platform/GUI/Walnut/UI/UI.cpp +++ b/Walnut/Platform/GUI/Walnut/UI/UI.cpp @@ -552,6 +552,20 @@ namespace Walnut::UI { return ImGui::Button(label); } + bool ButtonLeft(const char* label, const ImVec2& size) + { + ImGuiStyle& style = ImGui::GetStyle(); + + float actualSize = ImGui::CalcTextSize(label).x + style.FramePadding.x * 2.0f; + float avail = ImGui::GetContentRegionAvail().x; + + float off = (avail - actualSize); + if (off > 0.0f) + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + off); + + return ImGui::Button(label); + } + void DrawBorder(ImRect rect, float thickness, float rounding, float offsetX, float offsetY) { auto min = rect.Min; diff --git a/Walnut/Platform/GUI/Walnut/UI/UI.h b/Walnut/Platform/GUI/Walnut/UI/UI.h index cc241c96e..ab5282546 100644 --- a/Walnut/Platform/GUI/Walnut/UI/UI.h +++ b/Walnut/Platform/GUI/Walnut/UI/UI.h @@ -49,6 +49,7 @@ namespace Walnut::UI { void EndMenubar(); bool ButtonCentered(const char* label, const ImVec2& size = ImVec2(0, 0)); + bool ButtonLeft(const char* label, const ImVec2& size = ImVec2(0, 0)); // Utilities class ScopedStyle