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

increase the size of button_padding.y in ui.horizontal(), the widgets will create a step layer. #5029

Closed
rustbasic opened this issue Aug 29, 2024 · 1 comment
Labels
bug Something is broken

Comments

@rustbasic
Copy link
Contributor

rustbasic commented Aug 29, 2024

If increase the size of button_padding.y in ui.horizontal(), the widgets will create a step layer.
It is okay to change item_spacing.

I haven't checked the problematic part in detail.
This is expected to be a problem that has existed for a long time.

bug-20240829

Test Example :

use eframe::egui::*;

fn main() -> eframe::Result {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Ok(Box::<MyApp>::default())),
    )
}

#[derive(Default)]
struct MyApp {
    temp_value: usize,
    _text: String,
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.separator();

            ui.horizontal(|ui| {
                ui.label("TEST");

                ui.horizontal(|ui| {
                    ui.label("TEST");
    
                    ui.horizontal(|ui| {
                        ui.label("TEST");
        
                        ui.horizontal(|ui| {
                            ui.label("TEST");
                        });
                    });
                });
            });

            ui.separator();

            ui.horizontal(|ui| {
                ui.label("TEST");
                if ui.button("⟲").clicked() {
                    self.temp_value = 255;
                }

                ui.horizontal(|ui| {
                    ui.label("TEST");
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
    
                    ui.horizontal(|ui| {
                        ui.label("TEST");
                        if ui.button("⟲").clicked() {
                            self.temp_value = 255;
                        }
        
                        ui.horizontal(|ui| {
                            ui.label("TEST");
                            if ui.button("⟲").clicked() {
                                self.temp_value = 255;
                            }
                        });
                    });
                });
            });

            ui.separator();

            ui.horizontal(|ui| {
                ui.label("TEST");
                ui.add(DragValue::new(&mut self.temp_value));
                if ui.button("⟲").clicked() {
                    self.temp_value = 255;
                }

                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }

                    ui.horizontal(|ui| {
                        ui.label("TEST");
                        ui.add(DragValue::new(&mut self.temp_value));
                        if ui.button("⟲").clicked() {
                            self.temp_value = 255;
                        }

                        ui.horizontal(|ui| {
                            ui.label("TEST");
                            ui.add(DragValue::new(&mut self.temp_value));
                            if ui.button("⟲").clicked() {
                                self.temp_value = 255;
                            }
                        });
                    });
                });
            });

            ui.separator();

            ui.horizontal(|ui| {
                ui.label("TEST");
                ui.add(DragValue::new(&mut self.temp_value));
                if ui.button("⟲").clicked() {
                    self.temp_value = 255;
                }

                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
            });

            ui.separator();

            ui.horizontal(|ui| {
                ui.label("TEST");
                ui.add(DragValue::new(&mut self.temp_value));
                if ui.button("⟲").clicked() {
                    self.temp_value = 255;
                }

                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(Slider::new(&mut self.temp_value, 0..=255));
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(Slider::new(&mut self.temp_value, 0..=255));
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
                ui.horizontal(|ui| {
                    ui.label("TEST");
                    ui.add(Slider::new(&mut self.temp_value, 0..=255));
                    ui.add(DragValue::new(&mut self.temp_value));
                    if ui.button("⟲").clicked() {
                        self.temp_value = 255;
                    }
                });
            });

            ui.separator();

            ctx.settings_ui(ui);
        });
    }
}
@rustbasic rustbasic added the bug Something is broken label Aug 29, 2024
@rustbasic
Copy link
Contributor Author

rustbasic commented Aug 30, 2024

I looked into this issue briefly.

If there is horizontal() inside horizontal(), it seems to go expand by button_padding.
It is okay when the thing inside horizontal() is a Label, but if there is something like a Button, it seems to go expand by button_padding.

It seems to be related to next_space() or next_frame(), which are ultimately called by allocate_ui_with_layout_dyn(), but there is no place where button_padding is used.

20240831-bug

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
1 participant