Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combobox in a menu button isn't functional #3202

Open
bananaturtlesandwich opened this issue Aug 4, 2023 · 0 comments
Open

combobox in a menu button isn't functional #3202

bananaturtlesandwich opened this issue Aug 4, 2023 · 0 comments
Labels
bug Something is broken

Comments

@bananaturtlesandwich
Copy link

Describe the bug
when using a combobox in a menu button it doesn't work :/
also clicking buttons makes the dialog close normally but that's covered in #335

To Reproduce
Steps to reproduce the behavior:
compile this with eframe as a dependency (just a quick test thing i made not the use case)

fn main() -> Result<(), eframe::Error> {
    let mut list: Vec<String> = Vec::new();
    let mut index = None;
    eframe::run_simple_native("combo test", Default::default(), move |ctx, _| {
        use eframe::egui;
        egui::CentralPanel::default().show(ctx, |ui| {
            let mut show_combo = |ui: &mut egui::Ui| {
                ui.horizontal(|ui| {
                    let mut remove_at = None;
                    egui::ComboBox::from_id_source("select")
                        .width(125.0)
                        .selected_text(match index {
                            // for some reason this is necessary
                            Some(i) => &list[i] as &str,
                            None => "none",
                        })
                        .show_ui(ui, |ui| {
                            if ui.selectable_label(index.is_none(), "none").clicked() {
                                index = None;
                            }
                            for (i, pak) in list.iter().enumerate() {
                                ui.horizontal(|ui| {
                                    if ui.selectable_label(index == Some(i), pak).clicked() {
                                        index = Some(i);
                                    }
                                    if ui.button("x").clicked() {
                                        remove_at = Some(i);
                                        if index == remove_at {
                                            index = None
                                        }
                                        if index.is_some_and(|index| index > i) {
                                            index.as_mut().map(|i| *i -= 1);
                                        }
                                    }
                                });
                            }
                        });
                    if let Some(i) = remove_at {
                        list.remove(i);
                    }
                    if ui.button("+").clicked() {
                        list.push("test".to_string())
                    }
                })
            };
            show_combo(ui);
            ui.menu_button("test", show_combo);
        });
    })
}

Expected behavior
selecting something in the first combobox works fine while selecting something in the menu button combobox does nothing and the selected is the same
the same for clicking the remove button

Desktop (please complete the following information):

  • OS: windows
  • Version: 10
@bananaturtlesandwich bananaturtlesandwich added the bug Something is broken label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant