From 824b492b9274613ba9b54912835c90421b48b73a Mon Sep 17 00:00:00 2001 From: Maor Malka Date: Sun, 11 Jan 2026 18:58:20 -0500 Subject: [PATCH 1/2] added support for double click reset to a known value --- examples/example_knob.rs | 3 ++- src/config.rs | 2 ++ src/widget.rs | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/examples/example_knob.rs b/examples/example_knob.rs index ac015a3..72e8f4d 100644 --- a/examples/example_knob.rs +++ b/examples/example_knob.rs @@ -87,7 +87,8 @@ impl eframe::App for KnobDemo { .with_background_arc(self.show_bg_arc) .with_show_filled_segments(self.show_filled) .with_colors(self.knob_color, self.line_color, self.text_color) - .with_step(self.use_step.then_some(0.02)); + .with_step(self.use_step.then_some(0.02)) + .with_double_click_reset(0.5); if *label == "Wiper, Sweep" { knob = knob.with_sweep_range(0.25, 0.75).with_size(50.0); diff --git a/src/config.rs b/src/config.rs index 8f85683..ad27bc9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,6 +16,7 @@ pub struct KnobConfig { pub(crate) show_filled_segments: bool, pub(crate) min_angle: f32, pub(crate) max_angle: f32, + pub(crate) reset_value: Option, } impl KnobConfig { @@ -36,6 +37,7 @@ impl KnobConfig { drag_sensitivity: 0.005, show_background_arc: true, show_filled_segments: true, + reset_value: None, } } } diff --git a/src/widget.rs b/src/widget.rs index 370cd67..d5831df 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -53,7 +53,7 @@ impl<'a> Knob<'a> { return self; } - self.config.min_angle = + self.config.min_angle = start_angle_normalized.rem_euclid(1.0) * std::f32::consts::TAU + std::f32::consts::PI / 2.0; self.config.max_angle = self.config.min_angle + range.max(0.0) * std::f32::consts::TAU; self @@ -156,6 +156,13 @@ impl<'a> Knob<'a> { self } + /// Sets a reset value to return to on doubleclick event. + /// + /// Default is 0.005. + pub fn with_double_click_reset(mut self, reset_value: f32) -> Self { + self.config.reset_value = Some(reset_value); + self + } } impl Widget for Knob<'_> { @@ -168,7 +175,7 @@ impl Widget for Knob<'_> { let renderer = KnobRenderer::new(&self.config, current_value, self.min, self.max); let adjusted_size = renderer.calculate_size(ui); - let (rect, response) = ui.allocate_exact_size(adjusted_size, Sense::drag()); + let (rect, response) = ui.allocate_exact_size(adjusted_size, Sense::click_and_drag()); let mut response = response; if response.dragged() { @@ -189,6 +196,10 @@ impl Widget for Knob<'_> { } response.mark_changed(); + } else if response.double_clicked() { + if let Some(reset_value) = self.config.reset_value { + *self.value = reset_value + } } let knob_rect = renderer.calculate_knob_rect(rect); From 4e8975c955f09ff4804d38134b28e7ed4f2ca93d Mon Sep 17 00:00:00 2001 From: Daniel Dada Date: Mon, 12 Jan 2026 09:06:25 +0300 Subject: [PATCH 2/2] Updated doc comment for with_double_click_reset --- src/widget.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/widget.rs b/src/widget.rs index d5831df..cb6410a 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -157,8 +157,6 @@ impl<'a> Knob<'a> { } /// Sets a reset value to return to on doubleclick event. - /// - /// Default is 0.005. pub fn with_double_click_reset(mut self, reset_value: f32) -> Self { self.config.reset_value = Some(reset_value); self