Skip to content

Menus and commands: trigger content, command items as chains, checked command items, run_with, per-menu width #325

Closed

Description

@samitbasu

Gaps found by a consumer moving onto v0.1.0-m8.26:

  1. A dropdown trigger can't hold custom content or a trailing icon. DropdownChain has a leading icon only. The consumer paints glyphs and a chevron over plain triggers (~70 lines). Proposal: DropdownChain::children(..) as on ButtonChain, and/or .trailing_icon(..) / .chevron().
  2. No check or radio item bound to a command. Menu::command always builds a plain item, and Commands::find is pub(crate), so the app can't read a command's chord. Proposal: m.command(id).checked(Mark), and a public chord read.
  3. Menu::command returns (). A command item can't be .inset(), .icon(), .destructive() or .focus_on_open(), so command items don't line up with marked ones. Proposal: return the ItemChain pre-filled with title, shortcut and enablement, finished with .add().
  4. A command's run/enabled are fn(&mut A) only. Proposal: an optional run_with(fn(&mut A, &Shell)).
  5. Menu width is style-wide only. Proposal: DropdownChain::min_width(..).
  6. A closed menu stays in the tree through its exit animation, so headless tests must advance time. Proposal: an "is open" query on Placed.

Activity

  1. added
    consumer
    on Nov 17, 2026
  2. samitbasu commented on Nov 18, 2026

    @samitbasu
    OwnerAuthor

    Design note for #325 (no code yet)

    Read against main at c8b928c (v0.1.0-m8.43). For each item: where it lives now, the smallest API that closes the gap, what it breaks, how it meets #315 (the options layer) and #320 (.named everywhere), and a rough size. Q marks a choice for the user, with my recommendation first.

    1. Dropdown trigger content and a trailing chevron

    Now

    • DropdownChain (src/owned/menu.rs:736) holds a Face and ButtonOptions. It builds its trigger with ButtonChain::new(..) at menu.rs:832.
    • Its only content option is a leading icon (menu.rs:772).
    • ButtonChain already has children (src/owned/button.rs:438) and Face::Empty(name) (button.rs:47), so the trigger can hold any content. The dropdown just doesn't pass it through.
    • The select trigger already draws a trailing Chevron::Down (src/owned/select.rs:240).

    Smallest API

    • DropdownChain::children(body), forwarded to the ButtonChain it builds. It's the same signature as ButtonChain::children, used with Face::Empty(name) or alongside a label.
    • DropdownChain::chevron(): a trailing Chevron::Down drawn as the select draws its own, at the style's indicator size and in the trigger's text colour.

    Q1.1: how to spell a trailing glyph.

    • (a) .chevron(), the stock down-chevron only. Recommended: it covers the case the consumer paints by hand, matches the select, and leaves no glyph or size choice to the caller.
    • (b) .trailing_icon(Icon) on ButtonOptions, so every button gets it. More general, but a second icon slot on every button is a wider API, and children already covers anything unusual.
    • (c) Both.

    Q1.2: where the chevron sits. Is it decorative only, kept out of the accessible name? Recommended: yes. The trigger already announces HasPopup::Menu and expanded.

    Q1.3: the chevron's look. Its size, its gap after the label, and whether it rotates while the menu is open are the user's pick. I'll render candidates beside the select trigger before it lands.

    2. Check and radio items bound to a command, and a public chord read

    Now

    • Menu::command (menu.rs:276) always builds an Action item.
    • Check and radio items exist only as plain items: checkbox_item (menu.rs:312) and radio_item (menu.rs:330).
    • A Command (src/commands.rs:44) has a title, a run, enabled: fn(&A) -> bool and a chord. Command::chord() is already public (commands.rs:309).
    • But the table only gives an app Commands::iter() (commands.rs:427), with no keys. Commands::find is pub(crate) (commands.rs:431), and so is Builder::command (src/builder.rs:703). So the app can't look a command up by its key.

    Q2.1: where the checked state lives.

    • (a) On the command (recommended): Command::new(..).checked(fn(&A) -> Mark) for an on/off command, and .chosen(fn(&A) -> Mark) for one of a set.
      • Menu::command then draws a check or dot item with the matching role (MenuItemCheckBox / MenuItemRadio).
      • Every reader of the table agrees, because the state is defined once: menus, a command button, a native menu bar walking iter().
      • This follows the rule that policy shared by several sites is encoded once.
    • (b) On the item (the issue's proposal): m.command(id).checked(Mark). Smaller, but each menu that shows the command restates its state, and a native menu bar can't see it.

    Q2.2: the chord read.

    3. Menu::command returns a pre-filled chain finished by .add()

    Now

    • Menu::command (menu.rs:276) returns (). It builds the item itself: title, formatted shortcut, enablement from the command, and the activation.
    • So a command item can't take .inset(), .icon() (menu.rs:608, :614), .destructive() or .focus_on_open() (menu.rs:629, :644).

    Smallest API

    • Menu::command(id) -> ItemChain<'_, 'f, A, CommandItem>, with title, shortcut, enablement and the command's check or dot (item 2) filled in, and finished by .add().
    • An unknown id still reports UnknownCommand and adds a disabled item, through the same chain.

    Q3.1: what the chain lets the caller override.

    • Recommended:
      • inset, icon, destructive and focus_on_open are allowed.
      • enablement can only disable further: the item is enabled only while the command is enabled and the caller allows it, so a menu can never run a command its table says can't run.
      • shortcut (the display text) is not offered, because the table owns the chord.
    • The alternative is to allow everything and let the caller be wrong. Not recommended.

    Q3.2: the finisher's name. .add() (recommended): it matches ButtonChain::add, MountChain::add and the issue. The alternative is .done(). Nothing else in the library uses that.

    Breaks: yes.

    • Every m.command(id); becomes m.command(id).add();.
    • ItemChain is #[must_use], so an unfinished one is a warning, an error under -D warnings. Every call site is found at compile time.
    • One breaking tag; the migration is mechanical.

    Note on the asymmetry with buttons.

    • ButtonChain::command(id) (button.rs:452) is a finisher, because a button keeps its own label.
    • A menu item's label is the command's title, so command starts the chain there.

    #315 and #320:

    4. run_with(fn(&mut A, &Shell))

    Now

    • Run::Plain(fn(&mut A)) (commands.rs:228) comes from Command::new (commands.rs:257).
    • Command::fire already holds a &Shell (commands.rs:323) and passes it only to paste.
    • enabled is fn(&A) -> bool (commands.rs:52).

    Q4.1: how a command that gets the shell is spelled.

    • (a) Recommended: a constructor, Command::with_shell(title, fn(&mut A, &Shell)), beside Command::paste(title, run).
      • A command has one run, so the constructor picks it.
      • The command stays Copy, made of fn pointers.
    • (b) .run_with(..) on a built command, replacing the run new was given. That reads as two runs, and it is easy to set both.

    Q4.2: whether enabled gets the shell too.

    5. Per-menu width

    Now

    • MenuStyle::min_width (src/contract.rs:691) is applied to every menu box at menu.rs:570.
    • There's no per-menu override on DropdownChain, or on NodeHandle::context_menu (builder.rs:1987).

    Q5.1: the shape.

    • (a) Recommended: menu_classes(Tw) on DropdownChain, merged over the menu box's classes.
      • It covers a width (min_w_px, w_px) and anything else a box takes (max_h), with no new numeric argument.
      • It follows classes(Tw) on the trigger.
    • (b) min_width(Distance): exactly what was asked, and typed (no naked float). But the next request (a max height, a fixed width) needs another method.

    Q5.2: context menus too.

    6. An "is open" query on Placed

    Now

    • Placed::overlays() and Placed::overlay(key) (src/roots.rs:367, :400) include an overlay that is still on screen during its exit. OverlayRef::is_exiting() (roots.rs:476) tells them apart.
    • But a dropdown's menu overlay is keyed (key, Part::Menu) with a private Part, so an app can't name it.
    • Whether a dropdown is open is held in Kept (menu.rs:36).

    Q6.1: what the query reads.

    • (a) Recommended: Placed::menu_open(key) -> bool for the dropdown key. It is true exactly while the menu is logically open, and false on the frame it closes, whatever the exit animation is doing. No time needs advancing in tests.
    • (b) Placed::dropdown_menu(key) -> Option<OverlayRef> and let callers check is_exiting(). More general, but every caller writes the same two-step check.

    A doc fix, separately. Placed::overlay's doc says "None when it is not open", yet it returns an exiting overlay. Either the doc or the behaviour should change.

    Proposed PR split

    1. Commands (items 3, 2 and 4). One breaking tag: the command chain with .add(), checked and chosen commands, Commands::get with Command::shortcut_text, and Command::with_shell. They change the same two files and their tests, and the .add() migration happens once.
      • About M+, about 300 lines.
      • Needs Q2.1, Q2.2, Q3.1, Q3.2, Q4.1 and Q4.2 first.
      • A UI trial for the check and dot command items.
    2. Dropdown (items 1 and 5). Additive: children, chevron() and menu_classes.
      • S+, about 100 lines.
      • Needs Q1.1, Q1.2, Q5.1 and Q5.2.
      • A render round for Q1.3 and a UI trial.
    3. Testing (item 6). Placed::menu_open and the overlay doc fix.
      • S. Needs Q6.1 and Q6.2.
      • It could ride with PR 2 if the user prefers fewer PRs.

    Order:

  3. samitbasu commented on Nov 18, 2026

    @samitbasu
    OwnerAuthor

    Decisions (user, 2026-11-17), on the design note:

    • Checked/chosen state lives on the command: Command::checked(..) / .chosen(..).
    • m.command(id) returns a pre-filled ItemChain finished by .add() (breaking). Enablement only ANDs with the command's.
    • Shell access: a Command::with_shell(title, |app, shell| …) constructor.
    • Per-menu width: menu_classes(tw) on the dropdown.

    The other flagged questions take the note's recommendations, listed in each PR for review. The chevron's look gets a render round in the dropdown PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    consumer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions