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) {