Skip to content

Commit

Permalink
Fix text fields (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrarier2111 authored Mar 3, 2024
1 parent 818ec6b commit ad1b30f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit ad1b30f

Please sign in to comment.