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

Allow sliders to be centred #4854

Open
RuboGubo opened this issue Jul 20, 2024 · 1 comment
Open

Allow sliders to be centred #4854

RuboGubo opened this issue Jul 20, 2024 · 1 comment

Comments

@RuboGubo
Copy link

Is your feature request related to a problem? Please describe.

You cant currently, I've tried using ui.vertical_centered() but it doesn't seem to work.

Describe the solution you'd like
make ui.vertical_centered() work

Describe alternatives you've considered
an option on the struct itself?

Additional context
n/a

@YgorSouza
Copy link
Contributor

This is part of #4378. It's because the slider is made of multiple widgets and doesn't know how to calculate its size before drawing.

Currently you can center a slider without the numeric value and the text like this:

let spacing = &ui.style().spacing;
let size = [spacing.slider_width, spacing.slider_rail_height];
ui.vertical_centered(|ui| {
    ui.add_sized(
        size,
        egui::Slider::new(&mut self.value, 0..=120).show_value(false),
    );
});

image

To center a slider with text and numeric value, you have to calculate the size manually and include it in the add_sized call, or store the size on each frame to use it in the next frame, as discussed in #3468. #4631 is meant to improve this user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants