From ddb26d1336b82794e078764f5947da75f0643430 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sat, 7 Nov 2026 21:14:05 -0800 Subject: [PATCH] Bar menu: line the icons up from the measured window inset Centring on the assumed 4 * s padding overshot: the owner saw the icons about as far left as they had been right. Measure where the first icon actually starts inside the menu window each frame and place the window so that point sits on the parent icon's left edge (4 * s until the first measure). Co-Authored-By: Claude Opus 5.5 --- src/RynthCore.Engine/ImGui/ImGuiBar.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/RynthCore.Engine/ImGui/ImGuiBar.cs b/src/RynthCore.Engine/ImGui/ImGuiBar.cs index e0ef8ff..f1dbfcb 100644 --- a/src/RynthCore.Engine/ImGui/ImGuiBar.cs +++ b/src/RynthCore.Engine/ImGui/ImGuiBar.cs @@ -81,6 +81,8 @@ internal static class ImGuiBar // means the bar wasn't drawn: start from a closed dropdown). private static readonly BarMenuHover _menuHover = new(); private static bool _overMenu; + // The menu window's measured left inset (first icon x minus window x); -1 until measured. AC thread. + private static float _menuInsetX = -1f; private static readonly List<(ButtonInfo Button, Vector2 Min, Vector2 Max)> _menuRects = new(); private const ImGuiWindowFlags MenuFlags = ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoDocking @@ -583,9 +585,12 @@ internal static class ImGuiBar UI.Sections.SectionBarMenuItem[] items = owner.Menu; Vector2 display = ImGuiNET.ImGui.GetIO().DisplaySize; - float width = square.X + 8f * s; // WindowPadding (4, 3) each side + // Where the menu's first icon starts inside its window, as last measured (the window padding + // as ImGui actually applied it); 4 * s, the padding asked for, until the first measure. + float inset = _menuInsetX >= 0f ? _menuInsetX : 4f * s; + float width = square.X + 2f * inset; float height = items.Length * square.Y + (items.Length - 1) * ButtonGap * s + 6f * s; - float x = (min.X + max.X - width) * 0.5f, y = max.Y; // centred under the icon + float x = min.X - inset, y = max.Y; // icons straight under the parent if (display.X > 1 && display.Y > 1) { if (y + height > display.Y && min.Y - height >= 0f) y = min.Y - height; // flush above instead @@ -604,6 +609,7 @@ internal static class ImGuiBar // NoFocusOnAppearing leaves a re-shown menu behind a panel focused since: lift it // every frame (no focus change, so another window's text edit stays active). MenuToFront(); + _menuInsetX = ImGuiNET.ImGui.GetCursorScreenPos().X - ImGuiNET.ImGui.GetWindowPos().X; _overMenu = ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenBlockedByActiveItem); foreach (UI.Sections.SectionBarMenuItem item in items) {