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

Layout::bottom_up -> ui.horizontal -> ui.button with style.spacing.button_padding increases size downward #1657

Closed
lunixbochs opened this issue May 21, 2022 · 2 comments
Labels
bug Something is broken layout Related to widget layout

Comments

@lunixbochs
Copy link
Contributor

lunixbochs commented May 21, 2022

(egui 0.18.1 on macOS 12.x with winit + wgpu backend)

When you nest these elements, then increase the vertical padding in style.spacing.button_padding, the button grows downward rather than upward, which causes a few problems.

ui.with_layout(egui::Layout::bottom_up(egui::Align::Center))
  ui.horizontal()
    ui.button()

I'm using a bottom-up layout because I'm trying to put multiple buttons horizontally at the bottom of a fixed size window below the content. The buttons do appear there, but if I add button_padding, the button expands downward to grow the window rather than upward with the layout.

I had to use .fixed_size for this demonstration, because if I use e.g. .default_size, the window becomes infinitely tall (presumably no matter how big the window is, the button grows it vertically every frame)

egui::Window::new("test")
    .fixed_size((160., 160.))
    .show(ctx, |ui| {
        ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
            ui.horizontal(|ui| {
                ui.button("bottom button");
            }); 
        }); 
    }); 

egui::Window::new("test 2")
    .fixed_size((160., 160.))
    .show(ctx, |ui| {
        ui.style_mut().spacing.button_padding = (16.0, 64.0).into();
        ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
            ui.horizontal(|ui| {
                ui.button("bottom button");
            }); 
        }); 
    }); 

Screen Shot 2022-05-21 at 5 44 05 AM

@lunixbochs lunixbochs added the bug Something is broken label May 21, 2022
@lunixbochs lunixbochs changed the title Layout::bottom_up with style.spacing.button_padding increases size downward Layout::bottom_up -> ui.horizontal -> ui.button with style.spacing.button_padding increases size downward May 21, 2022
@lunixbochs
Copy link
Contributor Author

lunixbochs commented May 21, 2022

Being more explicit about the layout seems to have helped, using a left_to_right().with_cross_align(Max) behaved about as I wanted.

egui::Window::new("test")
    .vscroll(false)
    .fixed_size((160., 160.))
    .show(ctx, |ui| {
        ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
            ui.with_layout(egui::Layout::left_to_right().with_cross_align(egui::Align::Max), |ui| {
                ui.button("bottom button");
            }); 
        }); 
    }); 

egui::Window::new("test 2")
    .vscroll(false)
    .fixed_size((160., 160.))
    .show(ctx, |ui| {
        ui.style_mut().spacing.button_padding = (16.0, 20.0).into();
        ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
            ui.with_layout(egui::Layout::left_to_right().with_cross_align(egui::Align::Max), |ui| {
                ui.button("bottom button");
            }); 
        }); 
    }); 

Is my issue then due the the assumed initial_size in ui.horizontal()?
Can ui.horizontal() be adapted to behave a bit better with bottom-up layout?

@emilk emilk added the layout Related to widget layout label May 21, 2022
@emilk
Copy link
Owner

emilk commented May 21, 2022

This is one of those "difficult to do in immediate mode" things. I think I'll close this in favor of #pass

@emilk emilk closed this as completed May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken layout Related to widget layout
Projects
None yet
Development

No branches or pull requests

2 participants