leftclick on a keybind setting will exit set mode

This commit is contained in:
Mark 2024-05-13 19:52:34 +02:00
parent 46fdb20953
commit 0c0c535d2c

View File

@ -99,6 +99,7 @@ pub struct KeybindInput {
id: KeyActionId, id: KeyActionId,
changing: bool, changing: bool,
keybinds_should_be_updated: Arc<AtomicBool>, keybinds_should_be_updated: Arc<AtomicBool>,
has_keyboard_focus: bool,
} }
impl KeybindInput { impl KeybindInput {
pub fn new( pub fn new(
@ -131,14 +132,19 @@ impl KeybindInput {
id, id,
changing: false, changing: false,
keybinds_should_be_updated, keybinds_should_be_updated,
has_keyboard_focus: false,
} }
} }
} }
impl GuiElem for KeybindInput { impl GuiElem for KeybindInput {
fn mouse_pressed(&mut self, button: MouseButton) -> Vec<GuiAction> { fn mouse_pressed(&mut self, button: MouseButton) -> Vec<GuiAction> {
if let MouseButton::Left = button { if let MouseButton::Left = button {
if !self.has_keyboard_focus {
self.changing = true; self.changing = true;
self.config.request_keyboard_focus = true; self.config.request_keyboard_focus = true;
} else {
self.changing = false;
}
vec![GuiAction::ResetKeyboardFocus] vec![GuiAction::ResetKeyboardFocus]
} else { } else {
vec![] vec![]
@ -183,6 +189,7 @@ impl GuiElem for KeybindInput {
} }
} }
fn draw(&mut self, info: &mut DrawInfo, g: &mut Graphics2D) { fn draw(&mut self, info: &mut DrawInfo, g: &mut Graphics2D) {
self.has_keyboard_focus = info.has_keyboard_focus;
if info.has_keyboard_focus && self.changing { if info.has_keyboard_focus && self.changing {
let half_width = 2.0; let half_width = 2.0;
let thickness = 2.0 * half_width; let thickness = 2.0 * half_width;