mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
ComboBox: fix justified layout of popup if wider than parent button (#4570)
* Closes https://github.com/emilk/egui/issues/4452 The `ComboBox` popup has a justified layout to make selection of items easier. Thanks to [the new sizing pass logic](https://github.com/emilk/egui/issues/4535) we don't have to know the final width in advance: 
This commit is contained in:
@@ -9,6 +9,12 @@ fn main() -> eframe::Result<()> {
|
||||
let options = eframe::NativeOptions::default();
|
||||
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
if ui.button("Reset egui memory").clicked() {
|
||||
ctx.memory_mut(|mem| *mem = Default::default());
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.label("The menu should be as wide as the widest button");
|
||||
ui.menu_button("Click for menu", |ui| {
|
||||
let _ = ui.button("Narrow").clicked();
|
||||
@@ -20,6 +26,23 @@ fn main() -> eframe::Result<()> {
|
||||
ui.label("A separator:");
|
||||
ui.separator();
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
let alternatives = [
|
||||
"Short",
|
||||
"Min",
|
||||
"Very very long text that will extend",
|
||||
"Short",
|
||||
];
|
||||
let mut selected = 1;
|
||||
|
||||
egui::ComboBox::from_label("ComboBox").show_index(
|
||||
ui,
|
||||
&mut selected,
|
||||
alternatives.len(),
|
||||
|i| alternatives[i],
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user