Skip to main content

card

Function card 

Source
pub fn card<V: 'static>(
    theme: &Theme,
    id: impl Into<SharedString>,
    items: &[Item],
    cursor: &Cursor,
    closing: Option<Instant>,
    window: &mut Window,
    cx: &mut Context<'_, V>,
    on: impl Fn(&mut V, Hit, &mut Window, &mut Context<'_, V>) + 'static,
) -> Div
Expand description

The panel a menu drops: every Item as a row, in a popover::popover_card, with a further panel hanging off each submenu row the Cursor holds open. id prefixes the rows’ element ids, so two menus open at once keep their hover state apart. In a test build each action and submenu row answers to the debug selector {id}/{label}.

The root panel is returned unanchored: mount it through one of popover’s anchored layers (popover::anchored_menu_below, popover::menu_at, …). Childed bare, it paints in flow, under every later sibling. Submenu panels are anchored here.

Every panel is capped at the window’s height less the snap margin either side, and scrolls its rows past that. A submenu hangs off its row wherever the row has scrolled to, outside the parent’s clip.

The pointer moves the cursor rather than lighting a row of its own, so a submenu can only ever hang off the row that is live. Everything the pointer does arrives as a Hit, dismissal included.

closing is the popup’s, the same instant its anchored layer is given: every open submenu panel plays its exit with the root card.