-
|
How to set the width of a single Slider? It is too short by default |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
If you want to adjust the width without setting a global slider width, you can use scoped UI. This way the style change is only limited to the scope. ui.scope(|ui| {
ui.spacing_mut().slider_width = desired_width;
ui.add(Slider::new(&mut value, 0..=100));
});If you want to make the slider span the whole width of the container, you can use ui.scope(|ui| {
ui.spacing_mut().slider_width = ui.available_width();
ui.add(Slider::new(&mut value, 0..=100));
});If you also want the ui.scope(|ui| {
ui.spacing_mut().slider_width = ui.available_width()
- ui.spacing().interact_size.x
- ui.spacing().button_padding.x;
ui.add(Slider::new(&mut value, 0..=100));
}); |
Beta Was this translation helpful? Give feedback.
Once you change it, it will affect every slider drawn until you change it again. So you can put this line before each slider if you want different sizes, or you can make a type wrapping the slider to add this setting and any others you need, like this:
https://github.com/a-liashenko/TinyPomodoro/blob/06d08df77ef10846910593586dbb44fa7554495c/app/src/app/widgets/styled_slider.rs
Issue #3284 is meant to make this kind of customization simpler so in the future you won't have to do all that, but for now this is the way to do it.