Skip to main content

MaterialSelect

Struct MaterialSelect 

Source
pub struct MaterialSelect<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> MaterialSelect<'a>

Source

pub fn new(selected: &'a mut Option<usize>) -> Self

Create a new select component.

§Arguments
  • selected - Mutable reference to the currently selected option value
§Example
let mut selection = None;
let select = MaterialSelect::new(&mut selection);
Source

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

Add an option to the select component.

§Arguments
  • value - Unique identifier for this option
  • text - Display text for this option
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .option(1, "First Option")
    .option(2, "Second Option"));
Source

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

Set placeholder text shown when no option is selected.

§Arguments
  • placeholder - The placeholder text to display
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .placeholder("Choose your option"));
Source

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

Set label text that floats above the field when focused or has content.

§Arguments
  • label - The label text to display
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .label("Color"));
Source

pub fn variant(self, variant: SelectVariant) -> Self

Set the visual variant of the select component.

§Arguments
  • variant - The variant (Filled or Outlined)
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .variant(SelectVariant::Outlined));
Source

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

Enable or disable the select component.

§Arguments
  • enabled - Whether the select should be enabled (true) or disabled (false)
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .enabled(false)); // Disabled select
Source

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

Set a fixed width for the select component.

§Arguments
  • width - The width in pixels
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .width(300.0)); // Fixed width of 300 pixels
Source

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

Set error text to display below the select component.

§Arguments
  • text - The error message text
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .error_text("This field is required")); // Error message
Source

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

Set helper text to display below the select component.

§Arguments
  • text - The helper message text
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .helper_text("Select an option from the list")); // Helper text
Source

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

Set an icon to display at the start of the select field.

§Arguments
  • icon - The icon identifier (e.g., “home”, “settings”)
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .leading_icon("settings")); // Gear icon on the left
Source

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

Set an icon to display at the end of the select field (overrides default dropdown arrow).

§Arguments
  • icon - The icon identifier (e.g., “check”, “close”)
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .trailing_icon("check")); // Check icon on the right
Source

pub fn keep_open_on_select(self, keep_open: bool) -> Self

Set whether to keep the dropdown open after selecting an option.

§Arguments
  • keep_open - If true, the dropdown remains open after selection; if false, it closes (default behavior)
§Example
let mut selection = None;
ui.add(MaterialSelect::new(&mut selection)
    .keep_open_on_select(true)); // Dropdown stays open after selection
Source

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

Enable filtering of options by typing.

§Arguments
  • enable - If true, allows filtering options by text input

Enable search highlighting while typing.

§Arguments
  • enable - If true, highlights matching options while typing
Source

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

Mark the field as required.

§Arguments
  • required - If true, marks the field as required
Source

pub fn menu_width(self, width: f32) -> Self

Set independent menu width.

§Arguments
  • width - The width of the menu in pixels
Source

pub fn menu_max_height(self, height: f32) -> Self

Set maximum menu height.

§Arguments
  • height - The maximum height of the menu in pixels
Source

pub fn border_radius(self, radius: f32) -> Self

Set border radius for menu.

§Arguments
  • radius - The border radius in pixels
Source

pub fn menu_alignment(self, alignment: MenuAlignment) -> Self

Set menu alignment.

§Arguments
  • alignment - The menu alignment (Start or End)

Trait Implementations§

Source§

impl<'a> Widget for MaterialSelect<'a>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MaterialSelect<'a>

§

impl<'a> RefUnwindSafe for MaterialSelect<'a>

§

impl<'a> Send for MaterialSelect<'a>

§

impl<'a> Sync for MaterialSelect<'a>

§

impl<'a> Unpin for MaterialSelect<'a>

§

impl<'a> UnsafeUnpin for MaterialSelect<'a>

§

impl<'a> !UnwindSafe for MaterialSelect<'a>

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> Downcast for T
where T: Any,

Source§

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

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

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

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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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