Skip to main content

Module split_button

Module split_button 

Source
Expand description

SplitButton — a button split into two regions sharing a single frame.

The left region is the default action: it shows the label of the currently-selected item and, on click, fires that item’s command (behaving like a regular Button). The right region is a narrow chevron zone that, on click, opens a MenuList of related actions. Picking an action from the dropdown fires it and promotes its index to become the new default for the session (IntelliJ’s “remember last used” convention).

SplitButton reuses MenuItem verbatim for the dropdown rows — the caller passes real MenuItem values via .item(...), so icons, shortcut labels, enabled flags, and separators all come for free.

let _w = SplitButton::new()
    .item(MenuItem::new(lit!("Run")).on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.run"))))
    .item(MenuItem::new(lit!("Run Tests")).on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.run-tests"))))
    .separator()
    .item(MenuItem::new(lit!("Debug")).on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.debug"))))
    .variant(ButtonVariant::Plain);

§Touch and pen

The action half is a target in its own right and needs nothing. The chevron half is 22 dp wide at every density — a dimension below the conformance floor cannot be routed through dp, which is a floor and would widen the paint at Compact — so it declares a Widget::hit_outset instead, with the whole shortfall on its leading edge: the trailing edge is the control’s own frame, and an outset never escapes its parent.

That means a direct pointer aiming between the halves gets the chevron, and a precise pointer gets exactly what is painted (hit_outset is zero for one). Of the two halves the action half is the wider, so it is the one that lends the dp — and the press it loses at its trailing edge is a press aimed at the chevron.

Structs§

SplitButton
A button split into a default-action region and a chevron dropdown region.

Constants§

SPLIT_BUTTON_BORDER_WIDTH
SPLIT_BUTTON_CHEVRON_ICON_SIZE
SPLIT_BUTTON_CHEVRON_WIDTH
SPLIT_BUTTON_CORNER_RADIUS
SPLIT_BUTTON_DIVIDER_WIDTH
SPLIT_BUTTON_HEIGHT
SplitButton design tokens.
SPLIT_BUTTON_ICON_LABEL_GAP
Gap between an optional main-region leading icon and the label.
SPLIT_BUTTON_MIN_WIDTH
SPLIT_BUTTON_PADDING_HORIZONTAL
SPLIT_BUTTON_PADDING_VERTICAL

Functions§

split_button_height
SPLIT_BUTTON_HEIGHT raised to the density’s target_size (24 / 32 / 44 dp). The identity at Compact.
split_button_icon_label_gap
SPLIT_BUTTON_ICON_LABEL_GAP scaled by the density’s spacing_factor (1.00 / 1.15 / 1.30).
split_button_min_width
SPLIT_BUTTON_MIN_WIDTH raised to the density’s target_size (24 / 32 / 44 dp). The identity at Compact.
split_button_padding_horizontal
SPLIT_BUTTON_PADDING_HORIZONTAL scaled by the density’s spacing_factor (1.00 / 1.15 / 1.30).
split_button_padding_vertical
SPLIT_BUTTON_PADDING_VERTICAL scaled by the density’s spacing_factor (1.00 / 1.15 / 1.30).