mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Allow changing handle shape of a slider (#3429)
* Closes #1974 <!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review you PR, but my time is limited! --> --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use egui::*;
|
||||
use egui::{style::HandleShape, *};
|
||||
use std::f64::INFINITY;
|
||||
|
||||
/// Showcase sliders
|
||||
@@ -17,6 +17,7 @@ pub struct Sliders {
|
||||
pub vertical: bool,
|
||||
pub value: f64,
|
||||
pub trailing_fill: bool,
|
||||
pub handle_shape: HandleShape,
|
||||
}
|
||||
|
||||
impl Default for Sliders {
|
||||
@@ -33,6 +34,7 @@ impl Default for Sliders {
|
||||
vertical: false,
|
||||
value: 10.0,
|
||||
trailing_fill: false,
|
||||
handle_shape: HandleShape::Circle,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +69,7 @@ impl super::View for Sliders {
|
||||
vertical,
|
||||
value,
|
||||
trailing_fill,
|
||||
handle_shape,
|
||||
} = self;
|
||||
|
||||
ui.label("You can click a slider value to edit it with the keyboard.");
|
||||
@@ -99,7 +102,8 @@ impl super::View for Sliders {
|
||||
.orientation(orientation)
|
||||
.text("i32 demo slider")
|
||||
.step_by(istep)
|
||||
.trailing_fill(*trailing_fill),
|
||||
.trailing_fill(*trailing_fill)
|
||||
.handle_shape(*handle_shape),
|
||||
);
|
||||
*value = value_i32 as f64;
|
||||
} else {
|
||||
@@ -111,7 +115,8 @@ impl super::View for Sliders {
|
||||
.orientation(orientation)
|
||||
.text("f64 demo slider")
|
||||
.step_by(istep)
|
||||
.trailing_fill(*trailing_fill),
|
||||
.trailing_fill(*trailing_fill)
|
||||
.handle_shape(*handle_shape),
|
||||
);
|
||||
|
||||
ui.label(
|
||||
@@ -132,20 +137,26 @@ impl super::View for Sliders {
|
||||
.logarithmic(true)
|
||||
.smart_aim(*smart_aim)
|
||||
.text("left")
|
||||
.trailing_fill(*trailing_fill),
|
||||
.trailing_fill(*trailing_fill)
|
||||
.handle_shape(*handle_shape),
|
||||
);
|
||||
ui.add(
|
||||
Slider::new(max, type_min..=type_max)
|
||||
.logarithmic(true)
|
||||
.smart_aim(*smart_aim)
|
||||
.text("right")
|
||||
.trailing_fill(*trailing_fill),
|
||||
.trailing_fill(*trailing_fill)
|
||||
.handle_shape(*handle_shape),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.checkbox(trailing_fill, "Toggle trailing color");
|
||||
ui.label("When enabled, trailing color will be painted up until the circle.");
|
||||
ui.label("When enabled, trailing color will be painted up until the handle.");
|
||||
|
||||
ui.separator();
|
||||
|
||||
handle_shape.ui(ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user