Skip to content

Commit

Permalink
Merge e8fd2e1 into 4498f9b
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Oct 7, 2018
2 parents 4498f9b + e8fd2e1 commit 38cd671
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/widgets/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TextInput {
let mut parent_div = Dom::new(NodeType::Div).with_class("__azul-native-input-text");

if let Some(default_callback_id) = self.default_callback_id {
parent_div.push_default_callback_id(On::MouseOver, default_callback_id);
parent_div.push_default_callback_id(On::KeyDown, default_callback_id);
}

parent_div.with_child(Dom::new(NodeType::Label(field.text.clone())).with_class("__azul-native-input-text-label"))
Expand All @@ -73,11 +73,8 @@ fn update_text_field_inner<T: Layout>(data: &mut TextInputState, app_state_no_da
if keyboard_state.current_virtual_keycodes.contains(&VirtualKeyCode::Back) {
data.text.pop();
} else {
let mut keys = keyboard_state.current_keys.iter().cloned().collect::<String>();
if keyboard_state.shift_down {
keys = keys.to_uppercase();
}
data.text += &keys;
// This next unwrap is safe as there will always be character in the iterator.
keyboard_state.latest_key.map(|key| data.text.push(if keyboard_state.shift_down { key.to_uppercase().next().unwrap() } else { key }));
}
UpdateScreen::Redraw
}
4 changes: 4 additions & 0 deletions src/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct KeyboardState
pub super_down: bool,
/// Currently pressed keys, already converted to characters
pub current_keys: HashSet<char>,
/// Holds the key that was pressed last if there is Some. Holds None otherwise.
pub latest_key: Option<char>,
/// Currently pressed virtual keycodes - this is essentially an "extension"
/// of `current_keys` - `current_keys` stores the characters, but what if the
/// pressed key is not a character (such as `ArrowRight` or `PgUp`)?
Expand Down Expand Up @@ -321,6 +323,7 @@ impl WindowState
if let Some(vk) = virtual_keycode {
if let Some(ch) = virtual_key_code_to_char(*vk) {
self.keyboard_state.current_keys.insert(ch);
self.keyboard_state.latest_key = Some(ch);
}
self.keyboard_state.current_virtual_keycodes.insert(*vk);
}
Expand All @@ -330,6 +333,7 @@ impl WindowState
if let Some(vk) = virtual_keycode {
if let Some(ch) = virtual_key_code_to_char(*vk) {
self.keyboard_state.current_keys.remove(&ch);
self.keyboard_state.latest_key = None;
}
self.keyboard_state.current_virtual_keycodes.remove(vk);
}
Expand Down

0 comments on commit 38cd671

Please sign in to comment.