From 41c9de27341f5eec0e996390c7cf02e22949108f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 27 Mar 2021 10:35:40 +0100 Subject: [PATCH] Add new ComboBox builder to replace the combo_box_with_label function --- egui/src/containers/combo_box.rs | 151 +++++++++++++++--- egui_demo_lib/src/apps/demo/font_book.rs | 12 +- egui_demo_lib/src/apps/demo/widget_gallery.rs | 13 +- egui_demo_lib/src/apps/demo/widgets.rs | 12 +- 4 files changed, 155 insertions(+), 33 deletions(-) diff --git a/egui/src/containers/combo_box.rs b/egui/src/containers/combo_box.rs index c4498fbb..7e64f076 100644 --- a/egui/src/containers/combo_box.rs +++ b/egui/src/containers/combo_box.rs @@ -1,9 +1,139 @@ use crate::{style::WidgetVisuals, *}; use epaint::Shape; +// TODO: this should be builder struct so we can set options like width. + /// A drop-down selection menu with a descriptive label. /// -/// See also [`combo_box`]. +/// ``` +/// # #[derive(Debug, PartialEq)] +/// # enum Enum { First, Second, Third } +/// # let mut selected = Enum::First; +/// # let mut ui = &mut egui::Ui::__test(); +/// egui::ComboBox::from_label( "Select one!") +/// .selected_text(format!("{:?}", selected)) +/// .show_ui(ui, |ui| { +/// ui.selectable_value(&mut selected, Enum::First, "First"); +/// ui.selectable_value(&mut selected, Enum::Second, "Second"); +/// ui.selectable_value(&mut selected, Enum::Third, "Third"); +/// } +/// ); +/// ``` +pub struct ComboBox { + id_source: Id, + label: Option