1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

Add Slider::clamp_to_range(bool)

This commit is contained in:
Emil Ernerfeldt
2021-01-25 19:55:08 +01:00
parent 2219e135fa
commit 6d57a24f35
3 changed files with 38 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ pub struct Sliders {
pub min: f64,
pub max: f64,
pub logarithmic: bool,
pub clamp_to_range: bool,
pub smart_aim: bool,
pub integer: bool,
pub value: f64,
@@ -20,6 +21,7 @@ impl Default for Sliders {
min: 0.0,
max: 10000.0,
logarithmic: true,
clamp_to_range: false,
smart_aim: true,
integer: false,
value: 10.0,
@@ -33,6 +35,7 @@ impl Sliders {
min,
max,
logarithmic,
clamp_to_range,
smart_aim,
integer,
value,
@@ -56,6 +59,7 @@ impl Sliders {
ui.add(
Slider::i32(&mut value_i32, (*min as i32)..=(*max as i32))
.logarithmic(*logarithmic)
.clamp_to_range(*clamp_to_range)
.smart_aim(*smart_aim)
.text("i32 demo slider"),
);
@@ -64,6 +68,7 @@ impl Sliders {
ui.add(
Slider::f64(value, (*min)..=(*max))
.logarithmic(*logarithmic)
.clamp_to_range(*clamp_to_range)
.smart_aim(*smart_aim)
.text("f64 demo slider"),
);
@@ -101,13 +106,21 @@ impl Sliders {
ui.radio_value(integer, false, "f64");
});
ui.label("(f32, usize etc are also possible)");
ui.advance_cursor(8.0);
ui.checkbox(logarithmic, "Logarithmic");
ui.label("Logarithmic sliders are great for when you want to span a huge range, i.e. from zero to a million.");
ui.label("Logarithmic sliders can include infinity and zero.");
ui.advance_cursor(8.0);
ui.checkbox(clamp_to_range, "Clamp to range");
ui.label("If true, the slider will clamp incoming and outgoing values to the given range.");
ui.label("If false, the slider can shows values outside its range, and you can manually enter values outside the range.");
ui.advance_cursor(8.0);
ui.checkbox(smart_aim, "Smart Aim");
ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23");
ui.advance_cursor(8.0);
egui::reset_button(ui, self);
}