diff --git a/Cargo.lock b/Cargo.lock index eac4a89f..4b54c851 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1396,7 +1396,7 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "iced_baseview" version = "0.0.3" -source = "git+https://github.com/robbert-vdh/iced_baseview.git?branch=feature/update-baseview#5d09ba42d28923d144c8b7339a9f3f5e1252b37b" +source = "git+https://github.com/robbert-vdh/iced_baseview.git?branch=feature/update-baseview#1439b4212fc94a5eff12450621cd03f880cf1b56" dependencies = [ "baseview", "copypasta", diff --git a/nih_plug_iced/src/widgets/param_slider.rs b/nih_plug_iced/src/widgets/param_slider.rs index 497943ee..ec2d0152 100644 --- a/nih_plug_iced/src/widgets/param_slider.rs +++ b/nih_plug_iced/src/widgets/param_slider.rs @@ -13,7 +13,6 @@ use super::ParamMessage; /// /// TODO: There are currently no styling options at all /// TODO: Handle Shift+drag for granular drag -/// TODO: Handle Double click for reset /// TODO: Handle Alt+click for text entry pub struct ParamSlider<'a, P: Param, Renderer: text::Renderer> { state: &'a mut State, @@ -34,6 +33,11 @@ pub struct ParamSlider<'a, P: Param, Renderer: text::Renderer> { pub struct State { drag_active: bool, keyboard_modifiers: keyboard::Modifiers, + /// Track clicks for double clicks. + last_click: Option, + /// Will be set to `true` if we just reset the parameter since you could otherwise reset the + /// parameter and then move your mouse around to still set it a non-default value. + ignore_changes: bool, } impl<'a, P: Param, Renderer: text::Renderer> ParamSlider<'a, P, Renderer> { @@ -116,17 +120,23 @@ impl<'a, P: Param, Renderer: text::Renderer> Widget self.state.drag_active = true; // Immediately trigger a parameter update if the value would be different, or - // reset the parameter if Ctrl is held - if self.state.keyboard_modifiers.control() { + // reset the parameter if Ctrl is held or the parameter is being double clicked + let click = mouse::Click::new(cursor_position, self.state.last_click); + self.state.last_click = Some(click); + if self.state.keyboard_modifiers.control() + || matches!(click.kind(), mouse::click::Kind::Double) + { self.set_normalized_value( shell, self.setter.default_normalized_param_value(self.param), ); + self.state.ignore_changes = true; } else { self.set_normalized_value( shell, util::remap_rect_x_coordinate(&bounds, cursor_position.x), ); + self.state.ignore_changes = false; } return event::Status::Captured; @@ -143,7 +153,11 @@ impl<'a, P: Param, Renderer: text::Renderer> Widget } Event::Mouse(mouse::Event::CursorMoved { .. }) | Event::Touch(touch::Event::FingerMoved { .. }) => { - if self.state.drag_active && bounds.contains(cursor_position) { + // Don't do anything when we just reset the parameter because that would be weird + if !self.state.ignore_changes + && self.state.drag_active + && bounds.contains(cursor_position) + { self.set_normalized_value( shell, util::remap_rect_x_coordinate(&bounds, cursor_position.x),