mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Add ComboBox::close_behavior (#5305)
Exposed the underlying PopupCloseBehavior of ComboBox in order to allow more control of ComboBox behavior. This allows ComboBox to be used rather than manually managing a popup directly, while also gaining the convenience features of ComboBox such as popup auto-sizing. * [x] I have followed the instructions in the PR template
This commit is contained in:
committed by
GitHub
parent
ce05b59689
commit
98916489f7
@@ -14,12 +14,33 @@ fn main() -> Result<(), eframe::Error> {
|
||||
struct MyApp {
|
||||
checkbox: bool,
|
||||
number: u8,
|
||||
numbers: [bool; 10],
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
ui.label("PopupCloseBehavior::CloseOnClickAway popup");
|
||||
ui.label("PopupCloseBehavior::CloseOnClick popup");
|
||||
ComboBox::from_label("ComboBox")
|
||||
.selected_text(format!("{}", self.number))
|
||||
.show_ui(ui, |ui| {
|
||||
for num in 0..10 {
|
||||
ui.selectable_value(&mut self.number, num, format!("{num}"));
|
||||
}
|
||||
});
|
||||
|
||||
ui.label("PopupCloseBehavior::CloseOnClickOutside popup");
|
||||
ComboBox::from_label("Ignore Clicks")
|
||||
.close_behavior(PopupCloseBehavior::CloseOnClickOutside)
|
||||
.selected_text("Select Numbers")
|
||||
.show_ui(ui, |ui| {
|
||||
ui.label("This popup will be open even if you click the checkboxes");
|
||||
for (i, num) in self.numbers.iter_mut().enumerate() {
|
||||
ui.checkbox(num, format!("Checkbox {}", i + 1));
|
||||
}
|
||||
});
|
||||
|
||||
ui.label("PopupCloseBehavior::IgnoreClicks popup");
|
||||
let response = ui.button("Open");
|
||||
let popup_id = Id::new("popup_id");
|
||||
|
||||
@@ -31,22 +52,13 @@ impl eframe::App for MyApp {
|
||||
ui,
|
||||
popup_id,
|
||||
&response,
|
||||
PopupCloseBehavior::CloseOnClickOutside,
|
||||
PopupCloseBehavior::IgnoreClicks,
|
||||
|ui| {
|
||||
ui.set_min_width(300.0);
|
||||
ui.label("This popup will be open even if you click the checkbox");
|
||||
ui.set_min_width(310.0);
|
||||
ui.label("This popup will be open until you press the button again");
|
||||
ui.checkbox(&mut self.checkbox, "Checkbox");
|
||||
},
|
||||
);
|
||||
|
||||
ui.label("PopupCloseBehavior::CloseOnClick popup");
|
||||
ComboBox::from_label("ComboBox")
|
||||
.selected_text(format!("{}", self.number))
|
||||
.show_ui(ui, |ui| {
|
||||
for num in 0..10 {
|
||||
ui.selectable_value(&mut self.number, num, format!("{num}"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user