pub struct Select<'a, T: PartialEq + Clone> { /* private fields */ }Expand description
A styled drop-down select.
Bind the selection to any PartialEq + Clone type — an enum, an index,
or a String — and supply a list of (value, label) pairs. Labels
accept &'static str, String, or any Cow<'a, str>, so static option
lists don’t allocate.
#[derive(Clone, PartialEq)]
enum Unit { Us, Ms, S }
let mut unit = Unit::Ms;
ui.add(Select::new("unit", &mut unit).options([
(Unit::Us, "μs"),
(Unit::Ms, "ms"),
(Unit::S, "s"),
]));For string-valued selects where each option is both the value and the
label, use Select::strings:
let mut unit = String::from("ms");
ui.add(Select::strings("unit", &mut unit, ["us", "ms", "s"]));Implementations§
Source§impl<'a, T: PartialEq + Clone> Select<'a, T>
impl<'a, T: PartialEq + Clone> Select<'a, T>
Sourcepub fn new(id_salt: impl Hash, value: &'a mut T) -> Self
pub fn new(id_salt: impl Hash, value: &'a mut T) -> Self
Create a select keyed by id_salt and bound to value.
Add selectable options via Select::options.
Sourcepub fn label(self, label: impl Into<WidgetText>) -> Self
pub fn label(self, label: impl Into<WidgetText>) -> Self
Show a label above the select.
Source§impl<'a> Select<'a, String>
impl<'a> Select<'a, String>
Sourcepub fn strings<I, S>(
id_salt: impl Hash,
value: &'a mut String,
options: I,
) -> Self
pub fn strings<I, S>( id_salt: impl Hash, value: &'a mut String, options: I, ) -> Self
Convenience constructor for string-valued selects. Each item is used as both the value and the displayed label.
let mut unit = String::from("ms");
ui.add(Select::strings("unit", &mut unit, ["us", "ms", "s"]));Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for Select<'a, T>
impl<'a, T> RefUnwindSafe for Select<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for Select<'a, T>where
T: Send,
impl<'a, T> Sync for Select<'a, T>where
T: Sync,
impl<'a, T> Unpin for Select<'a, T>where
T: Unpin,
impl<'a, T> UnsafeUnpin for Select<'a, T>
impl<'a, T> !UnwindSafe for Select<'a, T>
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
Mutably borrows from an owned value. Read more