Skip to content

Commit cfb10a0

Browse files
authored
Improve ComboBox doc example (#7116)
Improves the `ComboBox` example with some code that shows how to handle changes in the `ComboBox`’s selection. The approach is based on the advice given in #923 . I hope this saves future me (and hopefully others) a web search for how to do this. * [x] I have followed the instructions in the PR template
1 parent bdbe655 commit cfb10a0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/egui/src/containers/combo_box.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ pub type IconPainter = Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>;
1616
///
1717
/// ```
1818
/// # egui::__run_test_ui(|ui| {
19-
/// # #[derive(Debug, PartialEq)]
19+
/// # #[derive(Debug, PartialEq, Copy, Clone)]
2020
/// # enum Enum { First, Second, Third }
2121
/// # let mut selected = Enum::First;
22+
/// let before = selected;
2223
/// egui::ComboBox::from_label("Select one!")
2324
/// .selected_text(format!("{:?}", selected))
2425
/// .show_ui(ui, |ui| {
@@ -27,6 +28,10 @@ pub type IconPainter = Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>;
2728
/// ui.selectable_value(&mut selected, Enum::Third, "Third");
2829
/// }
2930
/// );
31+
///
32+
/// if selected != before {
33+
/// // Handle selection change
34+
/// }
3035
/// # });
3136
/// ```
3237
#[must_use = "You should call .show*"]

0 commit comments

Comments
 (0)