Picker
Chooses one value from a set. A style decides how: a menu with search, groups and keyboard control, radio buttons, a segmented bar, picture tiles, cards, or your own.
Default
ui.add(
Picker::new("fruit", &mut state.fruit)
.placeholder("Select a fruit")
.items(FRUITS.map(|(value, label)| (Some(value), label)))
.width(200.0),
);
Groups and disabled options
ui.add(
Picker::new("country", &mut state.country)
.placeholder("Select a country")
.group(
"Europe",
[
PickerOption::new(Some("de"), "Germany"),
PickerOption::new(Some("it"), "Italy"),
PickerOption::new(Some("ch"), "Switzerland").disabled(true),
],
)
.group(
"Asia",
[
PickerOption::new(Some("jp"), "Japan"),
PickerOption::new(Some("kr"), "South Korea"),
],
)
.width(200.0),
);
Search and clear
ui.add(
Picker::new("language", &mut state.language)
.placeholder("Language")
.items([
(Some("rust"), "Rust"),
(Some("go"), "Go"),
(Some("zig"), "Zig"),
(Some("swift"), "Swift"),
(Some("kotlin"), "Kotlin"),
(Some("ruby"), "Ruby"),
(Some("elixir"), "Elixir"),
])
.searchable(true)
.search_placeholder("Search...")
.highlight_matches(true)
.cleanable(true)
.width(200.0),
);
Sizes
let sizes = [Size::XSmall, Size::Small, Size::Medium, Size::Large];
for (index, size) in sizes.into_iter().enumerate() {
ui.add(
Picker::new(("size", index), &mut state.sizes[index])
.items([
(0, "Extra small"),
(1, "Small"),
(2, "Medium"),
(3, "Large"),
])
.size(size),
);
}
Title prefix
ui.add(
Picker::new("ui", &mut state.ui)
.items([("egui", "egui"), ("slint", "Slint"), ("iced", "iced")])
.title_prefix("UI: "),
);
Menu width and height
ui.add(
Picker::new("framework", &mut state.framework)
.items([
("next", "Next.js"),
("svelte", "SvelteKit"),
("nuxt", "Nuxt.js"),
("remix", "Remix"),
("astro", "Astro"),
("solid", "SolidStart"),
("qwik", "Qwik City"),
("fresh", "Fresh"),
])
.icon(super::empty::glyph(ui.ctx(), "search"))
.width(160.0)
.menu_width(280.0)
.menu_max_height(160.0),
);
Disabled
let mut value = "banana";
ui.add(
Picker::new("disabled", &mut value)
.items(FRUITS)
.disabled(true)
.width(200.0),
);
Empty
ui.add(
Picker::new("empty", &mut state.empty)
.placeholder("No options yet")
.searchable(true)
.empty_text("Nothing to choose from.")
.width(200.0),
);
Radio: delivery
ui.vertical(|ui| {
ui.set_max_width(320.0);
ui.add(
Picker::new("delivery", &mut state.delivery)
.style(&picker_styles::Radio)
.entry(
PickerOption::new(Delivery::Standard, "Standard delivery")
.description("Arrives in 3 to 5 business days."),
)
.entry(
PickerOption::new(Delivery::Express, "Express delivery")
.description("Arrives the next business day."),
)
.entry(
PickerOption::new(Delivery::Pickup, "Store pickup")
.description("Unavailable for this order.")
.disabled(true),
),
);
});
Radio: billing cycle
ui.add(
Picker::new("billing", &mut state.billing)
.style(&picker_styles::Radio)
.horizontal()
.items([
(Billing::Monthly, "Monthly"),
(Billing::Yearly, "Yearly"),
(Billing::Lifetime, "Lifetime"),
]),
);
Radio: sizes
let sizes = [Size::XSmall, Size::Small, Size::Medium, Size::Large];
let labels = ["Extra small", "Small", "Medium", "Large"];
for (index, (size, label)) in sizes.into_iter().zip(labels).enumerate() {
ui.add(
Picker::new(("radio-size", index), &mut state.radio_size)
.style(&picker_styles::Radio)
.item(index, label)
.size(size),
);
}
Segmented
ui.add(
Picker::new("period", &mut state.period)
.style(&picker_styles::Segmented)
.items([(0, "Day"), (1, "Week"), (2, "Month")]),
);
Tiles: Match system is half dark, half light
ui.add(
Picker::new("appearance", &mut state.appearance)
.style(&picker_styles::Tiles)
.items([(0, "Match system"), (1, "Dark"), (2, "Light")])
.pictures(&|ui, index, preview| {
match index {
0 => halves(ui, preview, looks, false),
1 => halves(ui, preview, &[looks[0], looks[0]], true),
_ => halves(ui, preview, &[looks[1], looks[1]], true),
}
PickerPicture::Shown
}),
);
Cards: a pair shares the taller card’s height
ui.add(
Picker::new("scope", &mut state.scope)
.style(&picker_styles::Cards)
.entry(
PickerOption::new(0, "Everything")
.description("All 48 playlists, and the 2,316 tracks in them."),
)
.entry(
PickerOption::new(1, "Chosen playlists")
.description("Only the playlists you tick, and the tracks in them."),
),
);
Cards: narrow, stacked
let skin_pictures = |ui: &egui::Ui, index: usize, picture: egui::Rect| match SKINS[index].1 {
Thumb::Picture => {
paint_skin_picture(ui, picture, index);
PickerPicture::Shown
}
Thumb::Placeholder => PickerPicture::Loading,
Thumb::Failed => PickerPicture::Missing,
};
Picture cards: a picture, a placeholder, a failed picture
ui.add(
Picker::new("skin", &mut state.skin)
.style(&picker_styles::PictureCards)
.items(
SKINS
.iter()
.enumerate()
.map(|(index, (name, _))| (index, *name)),
)
.pictures(&skin_pictures),
);
Styles
let styles: [&dyn PickerStyle; 3] = [
&picker_styles::Menu,
&picker_styles::Segmented,
&picker_styles::Radio,
];
for (index, style) in styles.into_iter().enumerate() {
ui.add(
Picker::new(("style", index), &mut state.every[index])
.items([(0, "Day"), (1, "Week"), (2, "Month")])
.horizontal()
.style(style),
);
}
Environment
ui.control_size(Size::Small, |ui| {
ui.picker_style(picker_styles::Segmented, |ui| {
ui.add(Picker::new("env-period", &mut state.period).items([
(0, "Day"),
(1, "Week"),
(2, "Month"),
]));
ui.add(
Picker::new("env-billing", &mut state.billing)
.items([(Billing::Monthly, "Monthly"), (Billing::Yearly, "Yearly")]),
);
});
});
Your own style
ui.add(
Picker::new("density", &mut state.density)
.style(&Chips)
.items([(0, "Compact"), (1, "Comfortable"), (2, "Spacious")]),
);
The story above is gallery/src/stories/picker.rs, running in your browser. Every snippet on this page is cut from it.