Fix conflicts between mouse and keyboard on switches
This commit is contained in:
parent
494236d71e
commit
91fbc53305
@ -85,7 +85,8 @@ impl Widget for ThreePosSwitch<'_> {
|
|||||||
let down_shortcut_released = self.down_shortcut.map_or(false, |shortcut| {
|
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)
|
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 interact_pos = resp.interact_pointer_pos().unwrap();
|
||||||
let sw_center = painter.clip_rect().left_top() + vec2(5.0, 12.0);
|
let sw_center = painter.clip_rect().left_top() + vec2(5.0, 12.0);
|
||||||
if interact_pos.y > sw_center.y {
|
if interact_pos.y > sw_center.y {
|
||||||
@ -93,19 +94,17 @@ impl Widget for ThreePosSwitch<'_> {
|
|||||||
} else {
|
} else {
|
||||||
*self.state = SwitchState::Up;
|
*self.state = SwitchState::Up;
|
||||||
};
|
};
|
||||||
resp.mark_changed();
|
|
||||||
} else if up_shortcut_pressed {
|
} else if up_shortcut_pressed {
|
||||||
*self.state = SwitchState::Up;
|
*self.state = SwitchState::Up;
|
||||||
resp.mark_changed();
|
|
||||||
} else if down_shortcut_pressed {
|
} else if down_shortcut_pressed {
|
||||||
*self.state = SwitchState::Down;
|
*self.state = SwitchState::Down;
|
||||||
resp.mark_changed();
|
|
||||||
} else if resp.drag_released() || up_shortcut_released || down_shortcut_released {
|
} else if resp.drag_released() || up_shortcut_released || down_shortcut_released {
|
||||||
*self.state = SwitchState::Neut;
|
*self.state = SwitchState::Neut;
|
||||||
resp.mark_changed();
|
|
||||||
}
|
}
|
||||||
if *self.state != SwitchState::Neut && !resp.dragged() && ui.input(|input| input.keys_down.is_empty()) {
|
if *self.state != SwitchState::Neut && !resp.dragged() && ui.input(|input| input.keys_down.is_empty()) {
|
||||||
*self.state = SwitchState::Neut;
|
*self.state = SwitchState::Neut;
|
||||||
|
}
|
||||||
|
if *self.state != old_state {
|
||||||
resp.mark_changed();
|
resp.mark_changed();
|
||||||
}
|
}
|
||||||
resp
|
resp
|
||||||
|
Loading…
Reference in New Issue
Block a user