Context menus: a submenu never moves the main card (#594, textchat) #608

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

Refs #594. This is the textchat half: the nightly the owner runs. The dailyuse half is #606. The two context_menu.rs files have diverged, so they get separate PRs.

The bounce, reproduced

The owner's report: right-click a message, hover a submenu row, the submenu opens, the main menu moves up, the cursor is now over a row that doesn't expand, the submenu closes, the menu moves back down, and this repeats every frame.

Cause (widgets/context_menu.rs, view and Anchored::layout on textchat): the main card and the open submenu were laid out as one block, row![main, column![space(offset), submenu]], and that block was moved back inside the window. A submenu running past the bottom or right edge moved the whole block, main card included. iced 0.14's mouse_area re-checks hover whenever its bounds change, even on a redraw with a still cursor. So on the next frame another row was under the cursor, its on_enter closed or switched the submenu, the block jumped back, and the cycle repeated.

tests/menu_placement.rs shows it headlessly, frame by frame with the tree kept: thread 640x480 at (4, 240) row "Mute thread": submenu open/closed by frame [None, Some(5), Some(6), Some(5), Some(6), Some(5), Some(6), Some(5)]. Main cards also moved as soon as a submenu opened, in the message and participant menus. On the old widget, 4 of 5 tests failed with 169 faults.

Fix

  • Each card is placed on its own, and placement is decided at open and kept, except when the window changes size. The main card stays where it opened.
  • Submenu placement: right of the menu, else left, with its top aligned to the row and otherwise its bottom. When neither side has room it goes under or above the row. It is shifted only along the row's edge, so it never covers its row. This is Base UI's submenu positioner, as in the web client.
  • Safe triangle (floating-ui safePolygon): crossing other rows on the way into the submenu no longer closes it. Leaving that path still does.
  • Rows keep their mouse_area whether or not a submenu is open.

Golden

control_bar_sharing changes. The stream menu used to sit 15 px higher because its "Stream quality" submenu was open, which is this bug. Now the menu stays where it opened and the submenu is bottom-aligned with its row. I looked at the image before regenerating it. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is 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.

🤖 Generated with Claude Code

Refs #594. This is the `textchat` half: the nightly the owner runs. The `dailyuse` half is #606. The two `context_menu.rs` files have diverged, so they get separate PRs. ## The bounce, reproduced The owner's report: right-click a message, hover a submenu row, the submenu opens, the **main menu moves up**, the cursor is now over a row that doesn't expand, the submenu closes, the menu moves back down, and this repeats every frame. Cause (`widgets/context_menu.rs`, `view` and `Anchored::layout` on `textchat`): the main card and the open submenu were laid out as **one block**, `row![main, column![space(offset), submenu]]`, and that block was moved back inside the window. A submenu running past the bottom or right edge moved the whole block, main card included. iced 0.14's `mouse_area` re-checks hover whenever its bounds change, even on a redraw with a still cursor. So on the next frame another row was under the cursor, its `on_enter` closed or switched the submenu, the block jumped back, and the cycle repeated. `tests/menu_placement.rs` shows it headlessly, frame by frame with the tree kept: `thread 640x480 at (4, 240) row "Mute thread": submenu open/closed by frame [None, Some(5), Some(6), Some(5), Some(6), Some(5), Some(6), Some(5)]`. Main cards also moved as soon as a submenu opened, in the message and participant menus. On the old widget, 4 of 5 tests failed with 169 faults. ## Fix - **Each card is placed on its own**, and placement is decided at open and kept, except when the window changes size. The main card stays where it opened. - **Submenu placement:** right of the menu, else left, with its top aligned to the row and otherwise its bottom. When neither side has room it goes under or above the row. It is shifted only along the row's edge, so it never covers its row. This is Base UI's submenu positioner, as in the web client. - **Safe triangle (floating-ui `safePolygon`):** crossing other rows on the way into the submenu no longer closes it. Leaving that path still does. - Rows keep their `mouse_area` whether or not a submenu is open. ## Golden `control_bar_sharing` changes. The stream menu used to sit 15 px higher because its "Stream quality" submenu was open, which is this bug. Now the menu stays where it opened and the submenu is bottom-aligned with its row. I looked at the image before regenerating it. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The owner's report: on the message menu, hovering a submenu row opens the
submenu, the main menu moves, the cursor is now over another row, the
submenu closes, the menu moves back, and so on every frame.

Cause: Anchored placed the main card and the open submenu as one block
(a row of the main card and a spaced-down submenu) and moved that block
back inside the window. A submenu running past the bottom or right edge
moved the whole block, main card included. iced's mouse_area re-checks
hover whenever its bounds change, so the next frame hovered another row,
whose on_enter closed (or switched) the submenu, the block moved back, and
the cycle repeated without the cursor moving.

Now each card is placed on its own and the placement is kept while the menu
is open (again when the window changes size): the main card stays where it
opened; the submenu goes right of the menu, else left, top-aligned else
bottom-aligned with its row, else under or above the row, moved back inside
only along the row's edge so it never covers its row. 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
it, so crossing other rows on the way in does not close the submenu.

The control_bar_sharing golden changes accordingly: the stream menu no
longer jumps 15 px up because its "Stream quality" submenu is open; the
submenu is bottom-aligned with its row instead.

tests/menu_placement.rs (message, voice participant and a thread-shaped
menu at every corner and edge of 640x480 and 900x600): before, 4 of 5 tests
failed with 169 faults, among them the open/close oscillation
([None, Some(5), Some(6), Some(5), Some(6), ...]) and main cards moving
when the submenu opened.

Refs #594

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
charles merged commit 3208c854bc into textchat 2026-11-15 08:15:48 +00:00
Sign in to join this conversation.
No description provided.