Bar: hover dropdown for a plugin window's barMenu

BarMenuHover (pure timer: 0.15 s open, 0.30 s close, switch at once, no reopen after a click until the icon is left), the dropdown drawn under the bar icon, and a barMenu-only plugin reload now reaches the bar (WindowPlan.MenuSignature, refreshed in PluginWindows.Sync without re-registering the panel).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 20:09:48 -08:00
commit 60a7bddf59
7 changed files with 266 additions and 9 deletions

View file

@ -1,7 +1,7 @@
# Bar icon dropdown: plugin API v94
Branch `up/bar-menu`, from `up/web-panel` (0ef12d7). Not deployed. The API number 94 is provisional, as 93 is
(upstream may take it first; it renumbers on merge). This change is the manifest only; a later change draws it.
(upstream may take it first; it renumbers on merge). The manifest is parsed here; the bar draws it (below).
## What changed
@ -10,7 +10,7 @@ Branch `up/bar-menu`, from `up/web-panel` (0ef12d7). Not deployed. The API numbe
(`SectionBarMenuItem` records; `Menu` is the never-null view).
- Validation, with the window always kept: the id is a short lower-case word and unique in the menu, the tooltip is
non-empty and capped at 48 characters, the command is a single `/...` chat command (the same rule as a contribution's),
the icon is one Phosphor glyph or empty (an empty icon is kept). An item failing any of these is dropped; items past
the icon is one Phosphor glyph or empty (an icon that is not a glyph is kept as an empty icon, and the bar draws the tooltip's first letter). An item with a bad id, tooltip or command is dropped; items past
`MaxBarMenuItems` (6) are ignored; a `barMenu` that is not an array is ignored.
- `PluginContractVersion.Current` and the SDK's `RynthCoreSdkApiVersion` (`RynthCore.PluginSdk.targets`) go to 94.
No function table change. Engines before v94 ignore the key, so a plugin can declare it unconditionally.
@ -21,4 +21,14 @@ Branch `up/bar-menu`, from `up/web-panel` (0ef12d7). Not deployed. The API numbe
break, over-long), empty id, duplicate id, empty tooltip, empty icon kept, 20 items capped to 6, a non-array
`barMenu`, no key, and the 48-character tooltip cap. `tools/PluginManifestTests` pins the SDK and engine numbers together.
Not yet tested in game.
Not yet tested in game.
## The dropdown
- Hovering a plugin window's bar icon for 0.15 s drops a column of icon buttons flush below it (flush above when it would
cross the bottom of the screen; clamped sideways). It stays while the mouse is over the icon or the column, and for
0.30 s after it leaves both. Another icon's dropdown replaces it at once. Clicking an item runs its command as a player
chat command (the hotkey path) and closes the dropdown. The icon's own click still toggles the window.
- A plugin reload that changes only `barMenu` reaches the bar: `PluginWindows.Sync` refreshes the hosted declaration
(`WindowPlan.MenuSignature`) without re-registering the panel, and bumps the version so the bar rebuilds its buttons.
- Timing is `ImGui/BarMenuHover.cs` (pure; `SectionsTests` `BarMenuHoverTiming`). Drawing is in-game only.

View file

@ -0,0 +1,64 @@
// ============================================================================
// RynthCore.Engine - ImGui/BarMenuHover.cs
// The timing of the bar icon dropdown (a plugin window's "barMenu", plugin API
// v94): pure, so tools/SectionsTests compiles it as is. ImGuiBar feeds it once
// a frame.
//
// An icon must be hovered OpenDelay before its dropdown opens (a sweep of the
// mouse across the bar opens nothing). Once open, the dropdown stays while the
// mouse is over the icon or the dropdown, and for CloseDelay after it leaves
// both (the gap between them is crossed within that). Hovering another icon
// while one is open switches at once. After a click (Close) the same icon does
// not reopen until the mouse has left it and hovered it again.
// ============================================================================
namespace RynthCore.Engine.ImGuiBackend;
internal sealed class BarMenuHover
{
public const double OpenDelay = 0.15, CloseDelay = 0.30;
private string? _hovered; // the icon being hovered, and since when (_hoverStart)
private double _hoverStart;
private double? _leftAt; // when the mouse left both the icon and the dropdown (open only)
private string? _closedByClick; // the icon hovered when Close() ran: ignored until it is left
/// <summary>The bar button id whose dropdown is open, else null.</summary>
public string? OpenFor { get; private set; }
/// <summary>
/// Once per frame. <paramref name="hoveredButton"/>: id of the menu-bearing bar button under the mouse, else null.
/// <paramref name="overMenu"/>: the mouse is over the open dropdown. <paramref name="now"/>: seconds.
/// </summary>
public void Update(string? hoveredButton, bool overMenu, double now)
{
if (_closedByClick != null && hoveredButton != _closedByClick) _closedByClick = null;
string? hovered = hoveredButton != null && hoveredButton == _closedByClick ? null : hoveredButton;
if (hovered != _hovered) { _hovered = hovered; _hoverStart = now; }
if (OpenFor != null)
{
if (hovered != null) { OpenFor = hovered; _leftAt = null; }
else if (overMenu) _leftAt = null;
else
{
_leftAt ??= now;
if (now - _leftAt.Value >= CloseDelay) { OpenFor = null; _leftAt = null; }
}
}
else if (hovered != null && now - _hoverStart >= OpenDelay)
{
OpenFor = hovered;
_leftAt = null;
}
}
/// <summary>An item was clicked, or the bar went away.</summary>
public void Close()
{
OpenFor = null;
_leftAt = null;
_closedByClick = _hovered;
}
}

View file

@ -11,6 +11,9 @@
// draws that asked for one (its manifest's "windows" with "bar", UI/Sections/
// PluginWindows.cs; an engine panel such a window has taken over loses its own
// button), reload (RL) and pop out.
// A plugin window with a "barMenu" (plugin API v94) drops a column of icon buttons below its
// bar icon after the mouse rests on it (BarMenuHover: open and close delays); a click runs that
// item's chat command. The icon's own click still toggles the window.
// A button whose window is open, docked or popped out, draws highlighted in the
// theme's accent (RynthTheme.BarButtonOpen*); the ILT and Scripts buttons while
// any window in their menu is (UI/BarOpenState.cs; one IsOpen lookup a key).
@ -71,7 +74,18 @@ internal static class ImGuiBar
// the button toggles it through ScriptWindowRegistry, like the Scripts menu does.
// OpenKey: the panel whose open state lights the button (BarOpenState.KeyFor).
private sealed record ButtonInfo(string Title, string Id, string Icon, bool Letter, string Tooltip,
string OpenKey, ScriptWindow? Window = null);
string OpenKey, ScriptWindow? Window = null, UI.Sections.SectionBarMenuItem[]? Menu = null);
// The bar icon dropdown (a plugin window's "barMenu"): the timer, last frame's "mouse is over the
// dropdown", the menu-bearing buttons' rects this frame, and when the timer was last fed (a gap
// means the bar wasn't drawn: start from a closed dropdown).
private static BarMenuHover _menuHover = new();
private static bool _overMenu;
private static double _menuFedAt = double.NegativeInfinity;
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
| ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNav;
// The open check every highlight uses (one set lookup a key), as one delegate: no allocation a frame.
private static readonly Func<string, bool> IsOpenCheck = ImGuiPanelHost.IsOpen;
@ -468,7 +482,11 @@ internal static class ImGuiBar
SafeImGui.SetItemTooltip(collapsed ? "Show the bar" : "Fold the bar to this button");
PhosphorIcons.DrawCentered(dl, iconFont, collapsed ? PhosphorIcons.CaretRight : PhosphorIcons.CaretLeft, cPos, caretSize,
caretHot ? RynthTheme.RcLabel : 0xFF9A9A9Au);
if (collapsed) return;
double menuNow = ImGuiNET.ImGui.GetTime();
if (menuNow - _menuFedAt > 0.5) _menuHover = new BarMenuHover(); // the bar wasn't drawn for a while
_menuFedAt = menuNow;
_menuRects.Clear();
if (collapsed) { _menuHover.Update(null, false, menuNow); _overMenu = false; return; }
// Rows (header): perRow icons a row, each row from iconsX (under the first icon);
// RL and pop out go at the end of the first row (NextSlot, or after the icons when
@ -487,6 +505,7 @@ internal static class ImGuiBar
ImFontPtr letterFont = ImGuiFonts.Get(UiFont.UiBold11);
// A button whose window is open (docked or popped out) draws in the theme's accent
// (BarOpenState); a menu button (ILT, Scripts) while any window it lists is open.
string? menuHovered = null;
foreach (ButtonInfo b in _buttons!)
{
NextSlot(ref slot, perRow, iconsX, s, iconFont, popped);
@ -496,7 +515,12 @@ internal static class ImGuiBar
if (b.Window != null) ScriptWindowRegistry.PlayerSetVisible(b.Window, !open);
else PanelRouter.Toggle(b.Title);
}
SafeImGui.SetItemTooltip(b.Tooltip);
if (b.Menu != null)
{
if (ImGuiNET.ImGui.IsItemHovered()) menuHovered = b.Id;
_menuRects.Add((b, ImGuiNET.ImGui.GetItemRectMin(), ImGuiNET.ImGui.GetItemRectMax()));
}
if (_menuHover.OpenFor != b.Id) SafeImGui.SetItemTooltip(b.Tooltip); // the dropdown sits where it would show
}
// The ILT section: one button, only on Infinite Leaftide with ILT panels registered
@ -533,6 +557,68 @@ internal static class ImGuiBar
// Drawn after the bar buttons' style is popped, so the menu has the normal look.
ScriptsMenu(scripts);
IltMenu();
_menuHover.Update(menuHovered, _overMenu, menuNow);
DrawBarMenu(s, square, iconFont, letterFont);
}
/// <summary>
/// The bar icon dropdown of the button <see cref="BarMenuHover.OpenFor"/> names: a column of square icon
/// buttons flush under the icon (flush above it when that would cross the bottom of the screen), clamped
/// to the screen sideways. Its own window, not a popup, so the bar keeps its hover. A click runs the
/// item's chat command as the player's. AC thread, inside the bar window.
/// </summary>
private static void DrawBarMenu(float s, Vector2 square, ImFontPtr iconFont, ImFontPtr letterFont)
{
_overMenu = false;
string? openFor = _menuHover.OpenFor;
if (openFor == null) return;
ButtonInfo? owner = null;
Vector2 min = default, max = default;
foreach (var r in _menuRects)
if (r.Button.Id == openFor) { owner = r.Button; min = r.Min; max = r.Max; break; }
if (owner?.Menu == null || owner.Menu.Length == 0) { _menuHover.Close(); return; }
UI.Sections.SectionBarMenuItem[] items = owner.Menu;
Vector2 display = ImGuiNET.ImGui.GetIO().DisplaySize;
float width = square.X + 8f * s; // WindowPadding (4, 3) each side
float height = items.Length * square.Y + (items.Length - 1) * ButtonGap * s + 6f * s;
float x = min.X, y = max.Y;
if (display.X > 1 && display.Y > 1)
{
if (y + height > display.Y && min.Y - height >= 0f) y = min.Y - height; // flush above instead
x = Math.Max(0f, Math.Min(x, display.X - width));
}
ImGuiNET.ImGui.SetNextWindowPos(new Vector2(x, y), ImGuiCond.Always);
PushBarWindowStyle(s);
PushBarButtonStyle(s);
bool begun = ImGuiNET.ImGui.Begin("##rc_bar_menu", MenuFlags);
bool clicked = false;
try
{
if (begun)
{
_overMenu = ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);
foreach (UI.Sections.SectionBarMenuItem item in items)
{
bool letter = item.Icon.Length == 0;
string glyph = letter ? (item.Tooltip.Length > 0 ? item.Tooltip.Substring(0, 1) : "?") : item.Icon;
if (IconButton(owner.Id + "_m_" + item.Id, letter ? letterFont : iconFont, glyph, square, RynthTheme.BarText))
{
AcMainThreadQueue.EnqueueChatCommand(item.Command.Trim(), ChatCommandOrigin.Player);
clicked = true;
}
SafeImGui.SetItemTooltip(item.Tooltip);
}
}
}
finally
{
ImGuiNET.ImGui.End();
PopBarButtonStyle();
PopBarWindowStyle();
}
if (clicked) { _menuHover.Close(); _overMenu = false; }
}
/// <summary>
@ -836,7 +922,7 @@ internal static class ImGuiBar
bool letter = false;
string icon = w.Icon.Length > 0 ? w.Icon : IconFor(w.Title, out letter);
list.Add(new ButtonInfo(w.Title, "##bar_pw_" + w.Plugin + "_" + w.Id, icon, letter, w.Title,
BarOpenState.KeyFor(w.Title, null)));
BarOpenState.KeyFor(w.Title, null), Menu: w.Menu.Length > 0 ? w.Menu : null));
}
// Plugin script windows that asked for a button (RynthSort, Oracle, ...): after the
// engine's own. Only while the plugin is loaded and has submitted the window.

View file

@ -104,7 +104,17 @@ internal static class PluginWindows
foreach ((string title, SectionWindowDecl w) in want)
{
string sig = WindowPlan.Signature(w);
if (Live.TryGetValue(title, out Hosted? h) && h.Signature == sig) continue;
if (Live.TryGetValue(title, out Hosted? h) && h.Signature == sig)
{
// Same panel, but the bar's dropdown may differ (a plugin reload with a new "barMenu"):
// refresh the declaration without re-registering the panel, and let the bar rebuild.
if (WindowPlan.MenuSignature(h.Decl) != WindowPlan.MenuSignature(w))
{
Live[title] = h with { Decl = w };
changed = true;
}
continue;
}
SectionWindowDecl decl = w;
Func<IImGuiPanel> face = () => new PluginWindowFace(decl.Plugin, decl.Surface, decl.Title, decl.FitHeight, decl.MinWidth, decl.DrawScale);
if (takeOvers.Contains(title))

View file

@ -67,4 +67,11 @@ internal static class WindowPlan
public static string Signature(SectionWindowDecl w) =>
string.Join("|", w.Plugin, w.Surface, w.Icon, w.Width, w.Height, w.MinWidth, w.MinHeight, w.Bar, w.EdgeToEdge, w.TakeOver,
w.Frameless, w.FitHeight);
/// <summary>
/// What the bar's dropdown shows for a window (its "barMenu"): kept apart from <see cref="Signature"/> because
/// a menu change must reach the bar without re-registering the panel (that would reset the window's state).
/// </summary>
public static string MenuSignature(SectionWindowDecl w) =>
string.Join("\n", System.Linq.Enumerable.Select(w.Menu, i => string.Join("\t", i.Id, i.Tooltip, i.Icon, i.Command)));
}

View file

@ -34,6 +34,8 @@ internal static class Program
WindowTakeOver();
WindowFrameless();
ManifestBarMenu();
BarMenuHoverTiming();
BarMenuReload();
StackCheckAfterPluginDraw();
Console.WriteLine();
@ -586,7 +588,7 @@ internal static class Program
"chrome and fitHeight are in the signature (a change re-registers)");
}
// -- Bar icon dropdown (v94) --──────
// -- Bar icon dropdown (v94) --
private static string BarMenuManifest(string windowExtra) =>
"{ \"version\": 1, \"windows\": [ { \"id\": \"server\", \"title\": \"DreamWeave\", \"surface\": \"window:server\", \"bar\": true"
@ -644,8 +646,84 @@ internal static class Program
Check(err.Length == 0 && m.Windows.Length == 1 && m.Windows[0].Menu.Length == 0, "barMenu not an array: window kept, no menu");
m = SectionManifestParser.Parse("DW", BarMenuManifest(""), out err);
Check(err.Length == 0 && m.Windows.Length == 1 && m.Windows[0].Menu.Length == 0, "no barMenu key: no menu");
m = SectionManifestParser.Parse("DW", BarMenuManifest(", \"barMenu\": [ { \"id\": \"x\", \"tooltip\": \"X\", \"icon\": \"x\", \"command\": \"/rserver x\" } ]"), out err);
Check(err.Length == 0 && m.Windows[0].Menu.Length == 1 && m.Windows[0].Menu[0].Icon == "" && m.Windows[0].Menu[0].Command == "/rserver x",
"a non-glyph icon keeps the item with Icon \"\"");
}
private static void BarMenuHoverTiming()
{
Case("bar dropdown: hover timer");
var h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.10);
Check(h.OpenFor == null, "hovering for 0.10 s: not open yet");
h.Update("a", false, 0.16);
Check(h.OpenFor == "a", "hovering for 0.16 s: open");
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.10);
h.Update(null, false, 0.11);
h.Update(null, false, 0.20);
h.Update(null, false, 0.30);
Check(h.OpenFor == null, "a sweep across the icon (0.10 s) never opens it");
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
Check(h.OpenFor == "a", "(setup) open on a");
h.Update(null, false, 1.0);
h.Update(null, false, 1.10);
h.Update(null, true, 1.20);
h.Update(null, true, 1.25);
Check(h.OpenFor == "a", "leaving the icon and reaching the dropdown 0.20 s later: still open (the gap is covered)");
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
h.Update(null, false, 1.0);
h.Update(null, false, 1.29);
Check(h.OpenFor == "a", "gone for 0.29 s: still open");
h.Update(null, false, 1.31);
Check(h.OpenFor == null, "gone for 0.31 s: closed");
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
h.Update("b", false, 2.0);
Check(h.OpenFor == "b", "an open dropdown switches to another icon at once");
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
h.Close();
Check(h.OpenFor == null, "Close() closes");
h.Update("a", false, 0.30);
h.Update("a", false, 5.0);
Check(h.OpenFor == null, "still hovering the same icon: not reopened");
h.Update(null, false, 5.10);
h.Update("a", false, 6.0);
Check(h.OpenFor == null, "hovered again but not for OpenDelay yet");
h.Update("a", false, 6.16);
Check(h.OpenFor == "a", "left and hovered again for OpenDelay: reopens");
Check(BarMenuHover.OpenDelay == 0.15 && BarMenuHover.CloseDelay == 0.30, "delays are 0.15 s and 0.30 s");
}
private static void BarMenuReload()
{
Case("bar dropdown: a barMenu-only change is seen by the host");
string one = BarMenuManifest(", \"barMenu\": [ { \"id\": \"a\", \"tooltip\": \"A\", \"icon\": \"\", \"command\": \"/rserver a\" } ]");
SectionWindowDecl w1 = SectionManifestParser.Parse("DW", one, out _).Windows[0];
SectionWindowDecl w1Again = SectionManifestParser.Parse("DW", one, out _).Windows[0];
SectionWindowDecl w2 = SectionManifestParser.Parse("DW", one.Replace("/rserver a", "/rserver b"), out _).Windows[0];
SectionWindowDecl w3 = SectionManifestParser.Parse("DW", BarMenuManifest(""), out _).Windows[0];
Check(WindowPlan.Signature(w1) == WindowPlan.Signature(w2), "(the panel signature ignores the menu: no re-registration)");
Check(WindowPlan.MenuSignature(w1) == WindowPlan.MenuSignature(w1Again), "the same menu parsed twice: same menu signature");
Check(WindowPlan.MenuSignature(w1) != WindowPlan.MenuSignature(w2), "a changed command: new menu signature");
Check(WindowPlan.MenuSignature(w1) != WindowPlan.MenuSignature(w3), "menu removed: new menu signature");
Check(WindowPlan.MenuSignature(w3) == WindowPlan.MenuSignature(w3 with { BarMenu = null }), "no menu is always the same signature");
}
// ImGui 1.91.6's ImGuiErrorRecoveryState, in field order: windows, IDs, tree nodes, colours,
// style vars, fonts, focus scopes, groups, item flags, popups, disabled. The base values are
// the ones a 32-bit probe of our cimgui.dll read inside a panel's body child (2026-10-21).

View file

@ -26,6 +26,8 @@
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\SectionManifest.cs" Link="Engine\SectionManifest.cs" />
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\SectionCatalog.cs" Link="Engine\SectionCatalog.cs" />
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\WindowPlan.cs" Link="Engine\WindowPlan.cs" />
<!-- The bar icon dropdown's hover timer (pure). -->
<Compile Include="..\..\src\RynthCore.Engine\ImGui\BarMenuHover.cs" Link="Engine\BarMenuHover.cs" />
<!-- What a plugin window's draw left on ImGui's stacks (the record ImGuiStackGuard takes). -->
<Compile Include="..\..\src\RynthCore.Engine\ImGui\ImGuiStackState.cs" Link="Engine\ImGuiStackState.cs" />
<Compile Include="..\..\src\RynthCore.Engine\Compatibility\IltDetect.cs" Link="Engine\IltDetect.cs" />