1
0
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:


![image](https://github.com/emilk/egui/assets/1148717/53b0dda7-14c9-43be-a073-ad49865e69a6)
This commit is contained in:
Emil Ernerfeldt
2024-05-29 11:47:10 +02:00
committed by GitHub
parent a768d74411
commit ffbc63e147
3 changed files with 30 additions and 6 deletions

View File

@@ -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],
);
});
})
}