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 https://github.com/emilk/egui/discussions/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
This commit is contained in:
parent
bdbe655852
commit
cfb10a04f5
|
|
@ -16,9 +16,10 @@ pub type IconPainter = Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>;
|
|||
///
|
||||
/// ```
|
||||
/// # egui::__run_test_ui(|ui| {
|
||||
/// # #[derive(Debug, PartialEq)]
|
||||
/// # #[derive(Debug, PartialEq, Copy, Clone)]
|
||||
/// # enum Enum { First, Second, Third }
|
||||
/// # let mut selected = Enum::First;
|
||||
/// let before = selected;
|
||||
/// egui::ComboBox::from_label("Select one!")
|
||||
/// .selected_text(format!("{:?}", selected))
|
||||
/// .show_ui(ui, |ui| {
|
||||
|
|
@ -27,6 +28,10 @@ pub type IconPainter = Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>;
|
|||
/// ui.selectable_value(&mut selected, Enum::Third, "Third");
|
||||
/// }
|
||||
/// );
|
||||
///
|
||||
/// if selected != before {
|
||||
/// // Handle selection change
|
||||
/// }
|
||||
/// # });
|
||||
/// ```
|
||||
#[must_use = "You should call .show*"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue