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

Grid item uses wrong variable after add_visible #1436

Closed
aalhitennf opened this issue Mar 29, 2022 · 4 comments
Closed

Grid item uses wrong variable after add_visible #1436

aalhitennf opened this issue Mar 29, 2022 · 4 comments
Labels
bug Something is broken

Comments

@aalhitennf
Copy link

aalhitennf commented Mar 29, 2022

Describe the bug
Grid item created with ui.add_enabled_ui after ui.add_visible, uses wrong variable somehow.

To Reproduce
Clone eframe_template and modify update fn to:

impl epi::App for TemplateApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut epi::Frame) {

        let column2_visible = false;
        let column3_enabled = true;

        egui::CentralPanel::default().show(ctx, |ui| {
            // For some reason, value from column2_visible is used in add_enabled_ui
            egui::Grid::new("grid").num_columns(3).show(ui, |ui| {
                ui.label("First column");
                ui.add_visible(column2_visible, egui::Label::new("Second column"));
                ui.add_enabled_ui(column3_enabled, |ui| ui.button("This should be enabled"));
                ui.end_row();
            });

            // But if we use add_visible_ui first, problem goes away
            egui::Grid::new("grid2").num_columns(3).show(ui, |ui| {
                ui.label("First column");
                ui.add_visible_ui(column2_visible, |ui| ui.label("Second column"));
                ui.add_enabled_ui(column3_enabled, |ui| ui.button("This is enabled"));
                ui.end_row();
            });
        });
    }
}

Expected behavior
There should be two buttons, both enabled.

Screenshots
https://i.imgur.com/myix3uu.png

Desktop (please complete the following information):

  • OS: Arch Linux, Windows 10
  • Browser: Not tested in browser

Additional context
This happens with both 0.17.0 and git master.

@aalhitennf aalhitennf added the bug Something is broken label Mar 29, 2022
@emilk
Copy link
Owner

emilk commented Mar 30, 2022

You need to use unique id:s for your Grid:s if they have the same parent. Grid::new("grid1")Grid::new("grid2")

@aalhitennf
Copy link
Author

aalhitennf commented Mar 30, 2022

Copy pasted and forgot to change the id, problem still exists even with unique id:s. e. Updated my post.

@emilk emilk closed this as completed in d09fa63 Apr 3, 2022
@emilk
Copy link
Owner

emilk commented Apr 3, 2022

Thanks for the report!

@emilk
Copy link
Owner

emilk commented Apr 4, 2022

I now added warnings about Id clashes for Grid:s #1452 (even though this issue was not at all about that)

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

2 participants