Skip to main content

Select

Struct Select 

Source
pub struct Select { /* private fields */ }
Expand description

A select/dropdown widget with optional fuzzy search

§Keyboard Shortcuts

KeyAction
EnterOpen dropdown (when closed) / Confirm selection (when open)
SpaceToggle dropdown open/close (non-searchable mode only)
Up / kMove to previous option (when open, non-searchable mode)
Down / jMove to next option (when open, non-searchable mode)
UpMove to previous option (when open, searchable mode)
DownMove to next option (when open, searchable mode)
HomeJump to first option (when open)
EndJump to last option (when open)
EscapeClose dropdown and clear search query (when open)
BackspaceDelete last character from search query (when open, searchable mode)
CharAppend character to search query (when open, searchable mode)

Implementations§

Source§

impl Select

Source

pub fn new() -> Self

Create a new select widget

Source

pub fn options(self, options: Vec<impl Into<String>>) -> Self

Set options

Source

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

Add a single option

Source

pub fn searchable(self, enable: bool) -> Self

Enable fuzzy search when dropdown is open

Source

pub fn highlight_fg(self, color: Color) -> Self

Set highlight color for matched characters

Source

pub fn selected(self, index: usize) -> Self

Set selected index, clamped to the valid range

Source

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

Set placeholder text

Source

pub fn fg(self, color: Color) -> Self

Set foreground color

Source

pub fn bg(self, color: Color) -> Self

Set background color

Source

pub fn selected_style(self, fg: Color, bg: Color) -> Self

Set selected item colors

Source

pub fn width(self, width: u16) -> Self

Set fixed width

Source

pub fn focused(self, focused: bool) -> Self

Set focused state

Source

pub fn disabled(self, disabled: bool) -> Self

Set disabled state

Source

pub fn selected_index(&self) -> usize

Get selected index

Source

pub fn value(&self) -> Option<&str>

Get selected value

Source

pub fn get_value(&self) -> Option<&str>

Get selected value (alias for value)

Source

pub fn is_open(&self) -> bool

Check if dropdown is open

Source

pub fn toggle(&mut self)

Toggle dropdown open/close

Source

pub fn open(&mut self)

Open the dropdown

Source

pub fn close(&mut self)

Close the dropdown

Source

pub fn select_next(&mut self)

Select next option

Source

pub fn select_prev(&mut self)

Select previous option

Source

pub fn select_first(&mut self)

Select first option

Source

pub fn select_last(&mut self)

Select last option

Source

pub fn query(&self) -> &str

Get current search query

Source

pub fn set_query(&mut self, query: impl Into<String>)

Set search query and update filter

Source

pub fn clear_query(&mut self)

Clear search query

Source

pub fn is_searchable(&self) -> bool

Check if searchable mode is enabled

Source

pub fn filtered_options(&self) -> &[usize]

Get filtered options (indices into original options)

Source

pub fn visible_count(&self) -> usize

Get number of visible (filtered) options

Source

pub fn get_match(&self, option: &str) -> Option<FuzzyMatch>

Get fuzzy match for an option

Source

pub fn handle_key(&mut self, key: &Key) -> bool

Handle key input, returns true if selection changed

Source

pub fn len(&self) -> usize

Get number of options

Source

pub fn is_empty(&self) -> bool

Check if select has no options

Source§

impl Select

Source

pub fn element_id(self, id: impl Into<String>) -> Self

Set element ID for CSS selector (#id)

Source

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

Add a CSS class

Source

pub fn classes<I, S>(self, classes: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple CSS classes

Trait Implementations§

Source§

impl Clone for Select

Source§

fn clone(&self) -> Select

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Select

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Select

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Interactive for Select

Source§

fn handle_key(&mut self, event: &KeyEvent) -> EventResult

Handle keyboard event Read more
Source§

fn handle_mouse(&mut self, event: &MouseEvent, area: Rect) -> EventResult

Handle mouse event Read more
Source§

fn focusable(&self) -> bool

Check if the widget can receive focus Read more
Source§

fn on_focus(&mut self)

Called when the widget receives focus Read more
Source§

fn on_blur(&mut self)

Called when the widget loses focus Read more
Source§

impl StyledView for Select

Source§

fn set_id(&mut self, id: impl Into<String>)

Set element ID
Source§

fn add_class(&mut self, class: impl Into<String>)

Add a CSS class
Source§

fn remove_class(&mut self, class: &str)

Remove a CSS class
Source§

fn toggle_class(&mut self, class: &str)

Toggle a CSS class
Source§

fn has_class(&self, class: &str) -> bool

Check if has class
Source§

impl View for Select

Source§

fn render(&self, ctx: &mut RenderContext<'_>)

Render the view to the given context Read more
Source§

fn id(&self) -> Option<&str>

Get element ID (for CSS #id selectors) Read more
Source§

fn classes(&self) -> &[String]

Get CSS classes (for CSS .class selectors) Read more
Source§

fn meta(&self) -> WidgetMeta

Get widget metadata for DOM Read more
Source§

fn widget_type(&self) -> &'static str

Get widget type name (for CSS type selectors) Read more
Source§

fn children(&self) -> &[Box<dyn View>]

Get child views (for container widgets) Read more

Auto Trait Implementations§

§

impl !Freeze for Select

§

impl !RefUnwindSafe for Select

§

impl Send for Select

§

impl !Sync for Select

§

impl Unpin for Select

§

impl UnsafeUnpin for Select

§

impl UnwindSafe for Select

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.