Context menus: stable placement and submenu hover intent (#594) #606

Merged
charles merged 1 commit from fix/594-menu-placement into dailyuse 2026-11-15 08:15:51 +00:00
Owner

Closes #594 (for dailyuse; the textchat nightly the report came from gets its own PR, linked below).

What was wrong

Reproduced headlessly with tests/menu_placement.rs (every menu kind at each corner, edge and the centre of 640×480 and 900×600 windows, cursor resting on each submenu row for 8 frames, then moving into the submenu):

  • Submenus closed on the way in (123 of 126 faults). Rows that are not submenus close an open submenu when hovered (on_enter(on_submenu(None))), and Anchored handed the same cursor to both cards. Moving diagonally from a submenu row toward its submenu crosses other rows of the main card, which closed it. The web client avoids this with floating-ui's safePolygon.
  • A submenu could cover its own row (3 faults). When a submenu fit on neither side, place shifted it on the x axis back into the window, over the main card and the row that opened it. With a 344 px submenu in a 640 px window it sat right on its row.
  • No per-frame oscillation on dailyuse. Here the main card is placed on its own. The owner's bouncing is on textchat, where Anchored placed the main card and the submenu as one block. A submenu that ran past the bottom or right edge moved the whole block, main card included, so the cursor ended up over another row, the submenu closed, the block moved back, and the cycle repeated every frame. (iced's mouse_area re-checks hover whenever its bounds change, even without cursor motion.) That one is fixed in the textchat PR.

What changed (widgets/context_menu.rs)

  • Placement is decided at open, and again when the window changes size. The main card stays where it opened while the menu is open, and is moved only to stay inside the window if its rows grow. A submenu keeps the side it chose for as long as it is open. Both are kept in the widget's tree state.
  • Submenu sides follow Base UI's submenu positioner (inline-end/start, side and alignment flip, fallback axis): right of the row with tops aligned, else bottoms aligned, else the same on the left, else under or above the row. It is shifted only along the row's edge, so it never covers its own row.
  • Safe triangle. While the cursor is over the submenu, or inside the triangle from where it left the row to the submenu's near edge, the main card gets a levitated cursor. So crossing rows on the way in doesn't close the submenu, and leaving that path still does.
  • Rows keep their mouse_area whether or not a submenu is open, so their state survives open and close.
  • Cards report themselves to widget operations (CARD_ID), so tests can find them wherever a menu is drawn.

Looks are unchanged: every existing golden passes as-is (FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green).

Menus still can't be drawn outside the window. iced overlays live in the window surface, and Wayland gives no way to position a separate popup window, so the fix is stable in-window placement like the web client's.

Tests

crates/fluxer-ui/tests/menu_placement.rs covers the message, channel, voice channel, category, guild, user, DM and voice participant menus, plus a thread-shaped menu (wide and long submenus). It also checks that leaving the safe path still closes the submenu and that a window resize places the menu again. On the old widget 4 of the 5 menu tests fail. tests/headless gains Harness::sized, menu_cards, placed_texts and hover_frames, which runs frames the way iced does, keeping the tree.

Not covered (follow-ups)

  • A menu taller than the window (the message menu is about 600 px) isn't scrollable. The web client caps it at 100vh - 1.5rem with a scroller.
  • The safe triangle has no timeout: a cursor resting inside it keeps the submenu open. floating-ui closes it after a short stop.
  • The main card still flips above the cursor at the bottom edge and is shifted at the right edge. Base UI's context menu instead shifts at the bottom and flips its alignment at the right. I left this alone to keep looks and goldens unchanged.
  • Other popouts (widgets/popout.rs, profile popout, expression picker, stream hover card) don't have the submenu fault. They re-place on size changes, as the web's autoUpdate does, and nothing hover-driven changes their size.

🤖 Generated with Claude Code

Closes #594 (for `dailyuse`; the `textchat` nightly the report came from gets its own PR, linked below). ## What was wrong Reproduced headlessly with `tests/menu_placement.rs` (every menu kind at each corner, edge and the centre of 640×480 and 900×600 windows, cursor resting on each submenu row for 8 frames, then moving into the submenu): - **Submenus closed on the way in (123 of 126 faults).** Rows that are not submenus close an open submenu when hovered (`on_enter(on_submenu(None))`), and `Anchored` handed the same cursor to both cards. Moving diagonally from a submenu row toward its submenu crosses other rows of the main card, which closed it. The web client avoids this with floating-ui's `safePolygon`. - **A submenu could cover its own row (3 faults).** When a submenu fit on neither side, `place` shifted it on the x axis back into the window, over the main card and the row that opened it. With a 344 px submenu in a 640 px window it sat right on its row. - **No per-frame oscillation on `dailyuse`.** Here the main card is placed on its own. The owner's bouncing is on `textchat`, where `Anchored` placed the main card and the submenu as **one block**. A submenu that ran past the bottom or right edge moved the whole block, main card included, so the cursor ended up over another row, the submenu closed, the block moved back, and the cycle repeated every frame. (iced's `mouse_area` re-checks hover whenever its bounds change, even without cursor motion.) That one is fixed in the textchat PR. ## What changed (`widgets/context_menu.rs`) - **Placement is decided at open**, and again when the window changes size. The main card stays where it opened while the menu is open, and is moved only to stay inside the window if its rows grow. A submenu keeps the side it chose for as long as it is open. Both are kept in the widget's tree state. - **Submenu sides follow Base UI's submenu positioner** (`inline-end`/`start`, side and alignment flip, fallback axis): right of the row with tops aligned, else bottoms aligned, else the same on the left, else under or above the row. It is shifted only along the row's edge, so it never covers its own row. - **Safe triangle.** While the cursor is over the submenu, or inside the triangle from where it left the row to the submenu's near edge, the main card gets a levitated cursor. So crossing rows on the way in doesn't close the submenu, and leaving that path still does. - Rows keep their `mouse_area` whether or not a submenu is open, so their state survives open and close. - Cards report themselves to widget operations (`CARD_ID`), so tests can find them wherever a menu is drawn. Looks are unchanged: every existing golden passes as-is (`FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green). Menus still can't be drawn outside the window. iced overlays live in the window surface, and Wayland gives no way to position a separate popup window, so the fix is stable in-window placement like the web client's. ## Tests `crates/fluxer-ui/tests/menu_placement.rs` covers the message, channel, voice channel, category, guild, user, DM and voice participant menus, plus a thread-shaped menu (wide and long submenus). It also checks that leaving the safe path still closes the submenu and that a window resize places the menu again. On the old widget 4 of the 5 menu tests fail. `tests/headless` gains `Harness::sized`, `menu_cards`, `placed_texts` and `hover_frames`, which runs frames the way iced does, keeping the tree. ## Not covered (follow-ups) - A menu taller than the window (the message menu is about 600 px) isn't scrollable. The web client caps it at `100vh - 1.5rem` with a scroller. - The safe triangle has no timeout: a cursor resting inside it keeps the submenu open. floating-ui closes it after a short stop. - The main card still flips above the cursor at the bottom edge and is shifted at the right edge. Base UI's context menu instead shifts at the bottom and flips its alignment at the right. I left this alone to keep looks and goldens unchanged. - Other popouts (`widgets/popout.rs`, profile popout, expression picker, stream hover card) don't have the submenu fault. They re-place on size changes, as the web's `autoUpdate` does, and nothing hover-driven changes their size. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Context menus are placed once, when they open (and again when the window
changes size), instead of re-derived each frame: the main card stays where
it opened and a submenu keeps the side it took while it is open.

A submenu is placed as Base UI's submenu positioner does in the web client:
right of its row, top-aligned, else bottom-aligned, else the same on the
left, else under or above the row; it is shifted back into the window only
along the row's edge, so it never covers its own row (before, a wide
submenu with no room on either side was shifted over the main card and its
own row).

Moving from a submenu row into its submenu no longer closes it: while the
cursor is over the submenu, or inside the triangle from where it left the
row to the submenu's near edge (floating-ui's safePolygon), the main card
does not see the cursor, so the rows it crosses do not close the submenu.
The rows keep their mouse area whether or not a submenu is open, so their
state survives a submenu opening or closing.

Tests: tests/menu_placement.rs opens the message, channel, voice channel,
category, guild, user, DM, voice participant and a thread-shaped menu at
every corner and edge of 640x480 and 900x600 windows, rests the cursor on
each submenu row for 8 frames (cards must not move, the submenu must stay
open and clear of its row), then moves it into the submenu (it must stay
open); plus closing still works off the safe path, and a window resize
places the menu again. Before this change 4 of the 5 menu tests failed
(126 faults: 123 submenus closed on the way in, 3 covered their row).

Menus still cannot be drawn outside the window: iced overlays live in the
window surface and Wayland gives no way to position a separate popup
window, so the fix is stable in-window placement, as the web client has.

Refs #594

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

The textchat half (the bounce the owner saw, which only happens there) is #608.

🤖 Generated with Claude Code

The `textchat` half (the bounce the owner saw, which only happens there) is #608. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
charles merged commit 8755cc6e93 into dailyuse 2026-11-15 08:15:51 +00:00
Sign in to join this conversation.
No description provided.