From 91fbc533059f9a006eeebb5a4d48e064d83fb8a7 Mon Sep 17 00:00:00 2001 From: pjht Date: Mon, 29 Jan 2024 15:28:17 -0600 Subject: [PATCH] Fix conflicts between mouse and keyboard on switches --- src/frontpanel/switch.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/frontpanel/switch.rs b/src/frontpanel/switch.rs index 59bf3a0..d27ed9b 100644 --- a/src/frontpanel/switch.rs +++ b/src/frontpanel/switch.rs @@ -85,7 +85,8 @@ impl Widget for ThreePosSwitch<'_> { let down_shortcut_released = self.down_shortcut.map_or(false, |shortcut| { ui.input_mut(|input| input.key_released(shortcut.logical_key) && shortcut.modifiers == input.modifiers) }); - if resp.drag_started() { + let old_state = *self.state; + if resp.dragged() { let interact_pos = resp.interact_pointer_pos().unwrap(); let sw_center = painter.clip_rect().left_top() + vec2(5.0, 12.0); if interact_pos.y > sw_center.y { @@ -93,19 +94,17 @@ impl Widget for ThreePosSwitch<'_> { } else { *self.state = SwitchState::Up; }; - resp.mark_changed(); } else if up_shortcut_pressed { *self.state = SwitchState::Up; - resp.mark_changed(); } else if down_shortcut_pressed { *self.state = SwitchState::Down; - resp.mark_changed(); } else if resp.drag_released() || up_shortcut_released || down_shortcut_released { *self.state = SwitchState::Neut; - resp.mark_changed(); } if *self.state != SwitchState::Neut && !resp.dragged() && ui.input(|input| input.keys_down.is_empty()) { *self.state = SwitchState::Neut; + } + if *self.state != old_state { resp.mark_changed(); } resp