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§
- Split
Button - 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_HEIGHTraised to the density’starget_size(24 / 32 / 44 dp). The identity at Compact.- split_
button_ icon_ label_ gap SPLIT_BUTTON_ICON_LABEL_GAPscaled by the density’sspacing_factor(1.00 / 1.15 / 1.30).- split_
button_ min_ width SPLIT_BUTTON_MIN_WIDTHraised to the density’starget_size(24 / 32 / 44 dp). The identity at Compact.- split_
button_ padding_ horizontal SPLIT_BUTTON_PADDING_HORIZONTALscaled by the density’sspacing_factor(1.00 / 1.15 / 1.30).- split_
button_ padding_ vertical SPLIT_BUTTON_PADDING_VERTICALscaled by the density’sspacing_factor(1.00 / 1.15 / 1.30).