1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

implement vertical slider orientation (#875)

This commit is contained in:
Bruce Reif (Buswolley)
2021-11-13 03:03:10 -08:00
committed by GitHub
parent 0bad1d0c99
commit 491739b580
2 changed files with 172 additions and 69 deletions

View File

@@ -12,6 +12,7 @@ pub struct Sliders {
pub clamp_to_range: bool,
pub smart_aim: bool,
pub integer: bool,
pub vertical: bool,
pub value: f64,
}
@@ -24,6 +25,7 @@ impl Default for Sliders {
clamp_to_range: false,
smart_aim: true,
integer: false,
vertical: false,
value: 10.0,
}
}
@@ -54,6 +56,7 @@ impl super::View for Sliders {
clamp_to_range,
smart_aim,
integer,
vertical,
value,
} = self;
@@ -70,6 +73,12 @@ impl super::View for Sliders {
*min = min.clamp(type_min, type_max);
*max = max.clamp(type_min, type_max);
let orientation = if *vertical {
SliderOrientation::Vertical
} else {
SliderOrientation::Horizontal
};
if *integer {
let mut value_i32 = *value as i32;
ui.add(
@@ -77,6 +86,7 @@ impl super::View for Sliders {
.logarithmic(*logarithmic)
.clamp_to_range(*clamp_to_range)
.smart_aim(*smart_aim)
.orientation(orientation)
.text("i32 demo slider"),
);
*value = value_i32 as f64;
@@ -86,6 +96,7 @@ impl super::View for Sliders {
.logarithmic(*logarithmic)
.clamp_to_range(*clamp_to_range)
.smart_aim(*smart_aim)
.orientation(orientation)
.text("f64 demo slider"),
);
@@ -100,6 +111,7 @@ impl super::View for Sliders {
}
ui.separator();
ui.label("Slider range:");
ui.add(
Slider::new(min, type_min..=type_max)
@@ -121,6 +133,11 @@ impl super::View for Sliders {
ui.radio_value(integer, true, "i32");
ui.radio_value(integer, false, "f64");
});
ui.horizontal(|ui| {
ui.label("Slider orientation:");
ui.radio_value(vertical, false, "Horizontal");
ui.radio_value(vertical, true, "Vertical");
});
ui.label("(f32, usize etc are also possible)");
ui.add_space(8.0);