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 <noreply@anthropic.com>
This commit is contained in:
parent
0e9ce0ac88
commit
ddb26d1336
1 changed files with 8 additions and 2 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue