8000 Add a `Slider::update_while_editing(bool)` API by mbernat · Pull Request #5978 · emilk/egui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Add a Slider::update_while_editing(bool) API #5978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub struct Slider<'a> {
custom_parser: Option<NumParser<'a>>,
trailing_fill: Option<bool>,
handle_shape: Option<HandleShape>,
update_while_editing: bool,
}

impl<'a> Slider<'a> {
Expand Down Expand Up @@ -167,6 +168,7 @@ impl<'a> Slider<'a> {
custom_parser: None,
trailing_fill: None,
handle_shape: None,
update_while_editing: true,
}
}

Expand Down Expand Up @@ -641,6 +643,16 @@ impl<'a> Slider<'a> {
let normalized = normalized_from_value(value, self.range(), &self.spec);
lerp(position_range, normalized as f32)
}

/// Update the value on each key press when text-editing the value.
///
/// Default: `true`.
/// If `false`, the value will only be updated when user presses enter or deselects the value.
#[inline]
pub fn update_while_editing(mut self, update: bool) -> Self {
self.update_while_editing = update;
self
}
}

impl Slider<'_> {
Expand Down Expand Up @@ -900,7 +912,8 @@ impl Slider<'_> {
.min_decimals(self.min_decimals)
.max_decimals_opt(self.max_decimals)
.suffix(self.suffix.clone())
.prefix(self.prefix.clone());
.prefix(self.prefix.clone())
.update_while_editing(self.update_while_editing);

match self.clamping {
SliderClamping::Never => {}
Expand Down
Loading
0