Bar dropdown: clock guard in BarMenuHover, shared letter fallback

The hover timer resets on a backwards clock (pop-out's own ImGui context) or a frame gap over 0.5 s; the guard is pure and tested. The dropdown's letter fallback uses the same helper as IconFor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 20:16:09 -08:00
commit f8d55c7c2a
3 changed files with 51 additions and 8 deletions

View file

@ -673,6 +673,7 @@ internal static class Program
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
Check(h.OpenFor == "a", "(setup) open on a");
Feed(h, "a", 0.30, 0.90);
h.Update(null, false, 1.0);
h.Update(null, false, 1.10);
h.Update(null, true, 1.20);
@ -682,6 +683,7 @@ internal static class Program
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
Feed(h, "a", 0.30, 0.90);
h.Update(null, false, 1.0);
h.Update(null, false, 1.29);
Check(h.OpenFor == "a", "gone for 0.29 s: still open");
@ -691,6 +693,7 @@ internal static class Program
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
Feed(h, "a", 0.30, 1.90);
h.Update("b", false, 2.0);
Check(h.OpenFor == "b", "an open dropdown switches to another icon at once");
@ -699,15 +702,37 @@ internal static class Program
h.Update("a", false, 0.20);
h.Close();
Check(h.OpenFor == null, "Close() closes");
h.Update("a", false, 0.30);
Feed(h, "a", 0.30, 4.90);
h.Update("a", false, 5.0);
Check(h.OpenFor == null, "still hovering the same icon: not reopened");
h.Update(null, false, 5.10);
Feed(h, null, 5.20, 5.90);
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");
// The popped-out bar draws in another ImGui context whose clock starts near 0.
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
h.Update(null, false, 1000.0);
h.Update(null, false, 0.05);
Check(h.OpenFor == null, "the clock jumping back (a pop-out's own context): reset, closed");
// A bar that wasn't drawn for a while sends no frames.
h = new BarMenuHover();
h.Update("a", false, 0.0);
h.Update("a", false, 0.20);
h.Update("a", false, 0.20 + BarMenuHover.ResetGap + 0.01);
Check(h.OpenFor == null, "a forward gap of more than 0.5 s: reset, closed");
}
// Frames from..to every 0.1 s (a real run draws every frame; the timer resets on a gap over 0.5 s).
private static void Feed(BarMenuHover h, string? hovered, double from, double to)
{
for (double t = from; t <= to + 1e-9; t += 0.1) h.Update(hovered, false, t);
}
private static void BarMenuReload()