pub struct Combo<Msg: Clone> { /* private fields */ }Expand description
A combo / select / dropdown widget.
See the module-level documentation for the full wiring pattern.
Build via combo and configure with the chained builders.
Implementations§
Source§impl<Msg: Clone> Combo<Msg>
impl<Msg: Clone> Combo<Msg>
Sourcepub fn new(state: ComboState, items: Vec<String>) -> Self
pub fn new(state: ComboState, items: Vec<String>) -> Self
Construct a combo over items driven by state. Both arguments
are taken by value because the widget tree is rebuilt every
frame; clone the app’s state slice into here.
Sourcepub fn description(self, s: impl Into<String>) -> Self
pub fn description(self, s: impl Into<String>) -> Self
Optional descriptive paragraph drawn below the label.
Sourcepub fn placeholder(self, s: impl Into<String>) -> Self
pub fn placeholder(self, s: impl Into<String>) -> Self
Placeholder for the trigger’s text edit when the query is empty.
Sourcepub fn helper(self, s: impl Into<String>) -> Self
pub fn helper(self, s: impl Into<String>) -> Self
Helper / informative text below the trigger. Hidden when an error message is set.
Sourcepub fn error(self, s: impl Into<String>) -> Self
pub fn error(self, s: impl Into<String>) -> Self
Error message below the trigger. Replaces the helper text and applies the destructive theme tokens to the trigger surface.
Sourcepub fn disabled(self, yes: bool) -> Self
pub fn disabled(self, yes: bool) -> Self
Render in the disabled style. Activations / selections still emit
messages — the consumer is responsible for ignoring them in
update().
Sourcepub fn multi_select(self, yes: bool) -> Self
pub fn multi_select(self, yes: bool) -> Self
Allow multiple items to be selected at once. Selected items are rendered as chips above the trigger.
Sourcepub fn searchable(self, yes: bool) -> Self
pub fn searchable(self, yes: bool) -> Self
Make the trigger an editable text field that filters the popup
list as the user types. Without searchable, the trigger is a
pressable button that displays the current selection.
Sourcepub fn max_chips_visible(self, n: usize) -> Self
pub fn max_chips_visible(self, n: usize) -> Self
Cap on the number of selection chips drawn above the trigger
before falling back to a “+N more” indicator. Default 4.
Sourcepub fn anchor_id(self, id: WidgetId) -> Self
pub fn anchor_id(self, id: WidgetId) -> Self
Stable identifier of the trigger pill. The popup looks the rect of this widget up in the previous frame’s layout snapshot to place itself flush below the trigger. Apps with several combos that may open simultaneously must give each a distinct id.
Sourcepub fn popup_gap(self, px: f32) -> Self
pub fn popup_gap(self, px: f32) -> Self
Vertical gap (logical pixels) between the bottom of the trigger
and the top of the popup panel. Default 4.
Sourcepub fn popup_width(self, px: f32) -> Self
pub fn popup_width(self, px: f32) -> Self
Width of the popup in logical pixels. Default 320.
Sourcepub fn popup_max_height(self, px: f32) -> Self
pub fn popup_max_height(self, px: f32) -> Self
Maximum height of the popup before it scrolls internally. Default
280. The popup never grows past this height; it shrinks to fit
the filtered item list when shorter.
Sourcepub fn on_query_change(self, f: impl Fn(String) -> Msg + 'static) -> Self
pub fn on_query_change(self, f: impl Fn(String) -> Msg + 'static) -> Self
Callback fired with the new query string on every keystroke
inside the trigger’s search field. Required when searchable( true ).
Sourcepub fn on_toggle_open(self, msg: Msg) -> Self
pub fn on_toggle_open(self, msg: Msg) -> Self
Message emitted when the user activates the trigger to toggle the popup open / closed (tap on the trigger pill or press the down-arrow icon button).
Sourcepub fn on_select_idx(self, f: impl Fn(usize) -> Msg + 'static) -> Self
pub fn on_select_idx(self, f: impl Fn(usize) -> Msg + 'static) -> Self
Callback fired with the index of the item the user selects from
the popup. The application’s update() should add that index to
state.selected (multi-select) or replace it (single-select).
Sourcepub fn on_unselect_idx(self, f: impl Fn(usize) -> Msg + 'static) -> Self
pub fn on_unselect_idx(self, f: impl Fn(usize) -> Msg + 'static) -> Self
Callback fired with the index of a chip the user dismisses
(tapping its ×). Multi-select only.
Sourcepub fn on_dismiss(self, msg: Msg) -> Self
pub fn on_dismiss(self, msg: Msg) -> Self
Message emitted when the user taps outside the popup. Typically
flips state.is_open back to false in update().
Sourcepub fn filtered_indices(&self) -> Vec<usize>
pub fn filtered_indices(&self) -> Vec<usize>
Return the indices of items that match the current query (case
insensitive contains match). Empty query passes every item.
Source§impl<Msg: Clone + 'static> Combo<Msg>
impl<Msg: Clone + 'static> Combo<Msg>
Sourcepub fn popup(&self) -> Option<Element<Msg>>
pub fn popup(&self) -> Option<Element<Msg>>
Build the popup as a Stack-overlayable element.
Returns None when the combo is closed.
The returned element is meant to be layered on top of the rest
of the application’s view tree in the same surface — typically
by wrapping the app’s view() output in a stack
and pushing this element when it is Some. It already contains:
- A full-surface dismiss layer behind the panel — a transparent
pressablethat firesCombo::on_dismisswhen the user taps anywhere outside the panel. - The panel itself, centred horizontally and anchored 80 px from
the top of the available rect, with the filtered item list
inside a scrolling viewport bounded by
Combo::popup_widthandCombo::popup_max_height.
The popup centres modal-style — it does not anchor to the trigger
position because the trigger’s screen-space rect is not known at
view() time. For a trigger-anchored popup, drive the popup’s
position from a runtime hint the application stores after the
first hit-test.
Sourcepub fn overlay(&self) -> Option<OverlaySpec<Msg>>
pub fn overlay(&self) -> Option<OverlaySpec<Msg>>
Build the OverlaySpec that the application should return from
App::overlays when this combo is open.
Returns None when the combo is closed.
Unlike Combo::popup, the overlay is rendered as a real Wayland
xdg-popup child of the application’s main window — it can extend
outside the parent surface (the canonical select / dropdown
behaviour) and is positioned by the compositor relative to the
trigger pill rect from the previous frame’s layout. The
OverlayId is derived from Combo::anchor_id so two combos
with distinct anchor ids get distinct overlay ids automatically.
The spec’s view is the panel itself (background, border, padding,
rounded corners and the bounded scrolling item list). No extra
dismiss layer is needed: tap-outside dismissal is handled by the
usual ltk mechanism — wire App::on_tap to
close the combo, or rely on the spec’s on_dismiss which fires
when the compositor sends popup_done.
Auto Trait Implementations§
impl<Msg> Freeze for Combo<Msg>where
Msg: Freeze,
impl<Msg> !RefUnwindSafe for Combo<Msg>
impl<Msg> !Send for Combo<Msg>
impl<Msg> !Sync for Combo<Msg>
impl<Msg> Unpin for Combo<Msg>where
Msg: Unpin,
impl<Msg> !UnwindSafe for Combo<Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more