Skip to main content

DropdownOption

Struct DropdownOption 

Source
pub struct DropdownOption<Msg = Callback> { /* private fields */ }
Expand description

One choice in a DropdownButton’s list.

options takes plain strings and is still the right call for the common case; this is what a choice is when it is not one. A colour swatch beside a name, a flag, a two-line entry with a subtitle, a heading — and a choice that is there but cannot be picked, which no string can say.

A choice carries no message: options and options_widgets both map the chosen index to one, so that a list built from an application’s own vector says what it means once.

use frus_widgets::{Container, DropdownButton, DropdownOption};
use frus_core::Color;

let swatch = |c: Color| Container::<Msg>::new().width(14.0).height(14.0).color(c);
let menu = DropdownButton::new("Amber", Msg::Toggle).options_widgets(
    true,
    vec![
        DropdownOption::widget(swatch(Color::rgb8(255, 193, 7))),
        DropdownOption::widget(swatch(Color::rgb8(3, 169, 244))),
        DropdownOption::new("Out of stock").enabled(false),
    ],
    Msg::Pick,
);

Implementations§

Source§

impl<Msg> DropdownOption<Msg>

Source

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

A choice of words — what options builds.

Source

pub fn widget(child: impl Widget<Msg> + 'static) -> Self

A choice the caller draws.

It is laid out in the room the words would have had, with the tick’s column kept clear, and it grows: a choice of words is a row tall, a choice of anything else is at least that and as much more as it needs.

Source

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

Whether this choice can be picked, over the list’s own availability.

A choice that cannot be picked is still drawn, still announced, and still ticked if it is the one selected — which happens, and is the reason it is drawn rather than left out: a list that hides what it cannot offer cannot show what was already chosen.

Auto Trait Implementations§

§

impl<Msg = Callback> !RefUnwindSafe for DropdownOption<Msg>

§

impl<Msg = Callback> !Send for DropdownOption<Msg>

§

impl<Msg = Callback> !Sync for DropdownOption<Msg>

§

impl<Msg = Callback> !UnwindSafe for DropdownOption<Msg>

§

impl<Msg> Freeze for DropdownOption<Msg>
where Option<Rc<dyn Widget<Msg>>>: Freeze,

§

impl<Msg> Unpin for DropdownOption<Msg>
where Option<Rc<dyn Widget<Msg>>>: Unpin,

§

impl<Msg> UnsafeUnpin for DropdownOption<Msg>
where Option<Rc<dyn Widget<Msg>>>: UnsafeUnpin,

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> 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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.