ltk

Struct Combo

Source
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>

Source

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.

Source

pub fn label(self, s: impl Into<String>) -> Self

Bold label drawn above the trigger.

Source

pub fn description(self, s: impl Into<String>) -> Self

Optional descriptive paragraph drawn below the label.

Source

pub fn placeholder(self, s: impl Into<String>) -> Self

Placeholder for the trigger’s text edit when the query is empty.

Source

pub fn helper(self, s: impl Into<String>) -> Self

Helper / informative text below the trigger. Hidden when an error message is set.

Source

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.

Source

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().

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn popup_width(self, px: f32) -> Self

Width of the popup in logical pixels. Default 320.

Source

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.

Source

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 ).

Source

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).

Source

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).

Source

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.

Source

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().

Source

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>

Source

pub fn trigger(&self) -> Element<Msg>

Build the trigger: label / description / chips (multi-select) / pill with text-edit + arrow / helper or error row. Returns an Element ready to drop into App::view.

Source

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:

  1. A full-surface dismiss layer behind the panel — a transparent pressable that fires Combo::on_dismiss when the user taps anywhere outside the panel.
  2. 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_width and Combo::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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more