Skip to content

Commit 009bfe5

Browse files
authored
Add a Slider::update_while_editing(bool) API (#5978)
* Closes #5976 * [x] I have followed the instructions in the PR template - The `scripts/check.sh` fails in `cargo-deny` because of a security vulnerability in `crossbeam-channel` but this is also present on `master`. https://github.com/user-attachments/assets/a964c968-bb76-4e56-88e1-d1e3d51a401a
1 parent 501905b commit 009bfe5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/egui/src/widgets/slider.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub struct Slider<'a> {
117117
custom_parser: Option<NumParser<'a>>,
118118
trailing_fill: Option<bool>,
119119
handle_shape: Option<HandleShape>,
120+
update_while_editing: bool,
120121
}
121122

122123
impl<'a> Slider<'a> {
@@ -167,6 +168,7 @@ impl<'a> Slider<'a> {
167168
custom_parser: None,
168169
trailing_fill: None,
169170
handle_shape: None,
171+
update_while_editing: true,
170172
}
171173
}
172174

@@ -641,6 +643,16 @@ impl<'a> Slider<'a> {
641643
let normalized = normalized_from_value(value, self.range(), &self.spec);
642644
lerp(position_range, normalized as f32)
643645
}
646+
647+
/// Update the value on each key press when text-editing the value.
648+
///
649+
/// Default: `true`.
650+
/// If `false`, the value will only be updated when user presses enter or deselects the value.
651+
#[inline]
652+
pub fn update_while_editing(mut self, update: bool) -> Self {
653+
self.update_while_editing = update;
654+
self
655+
}
644656
}
645657

646658
impl Slider<'_> {
@@ -900,7 +912,8 @@ impl Slider<'_> {
900912
.min_decimals(self.min_decimals)
901913
.max_decimals_opt(self.max_decimals)
902914
.suffix(self.suffix.clone())
903-
.prefix(self.prefix.clone());
915+
.prefix(self.prefix.clone())
916+
.update_while_editing(self.update_while_editing);
904917

905918
match self.clamping {
906919
SliderClamping::Never => {}

0 commit comments

Comments
 (0)