From b032dce6b3397bc36f66abdca656f4b889ab56ba Mon Sep 17 00:00:00 2001 From: threadexception Date: Sun, 3 Mar 2024 20:41:18 +0100 Subject: [PATCH] Fix text fields --- src/ui/mod.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 07dc0852..1aa2a59f 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -436,20 +436,25 @@ impl Container { } return; } + let chr = { + key.to_text().and_then(|text| { + if !down || text.len() != 1 { + None + } else { + let chr = text.chars().next().unwrap(); + if chr < ' ' && chr != '\x08' { + return None; + } + Some(chr) + } + }) + }; for el in self.focusable_elements.iter().flat_map(|v| v.upgrade()) { if el.is_focused() { el.key_press(game, key.clone(), down, ctrl_pressed); - } - } - } - - pub fn key_type(&mut self, game: &mut crate::Game, c: char) { - if c < ' ' && c != '\x08' { - return; - } - for el in self.focusable_elements.iter().flat_map(|v| v.upgrade()) { - if el.is_focused() { - el.key_type(game, c); + if let Some(chr) = chr { + el.key_type(game, chr); + } } } }