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>
impl<Msg> DropdownOption<Msg>
Sourcepub fn widget(child: impl Widget<Msg> + 'static) -> Self
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.
Sourcepub fn enabled(self, enabled: bool) -> Self
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.