Fix conflicts between mouse and keyboard on switches

This commit is contained in:
pjht 2024-01-29 15:28:17 -06:00
parent 494236d71e
commit 91fbc53305
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -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