mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Improved text edit with cursor that can be moved with arrow keys
This commit is contained in:
@@ -48,7 +48,13 @@ pub fn input_event(
|
||||
raw_input.mouse_pos = None;
|
||||
}
|
||||
ReceivedCharacter(ch) => {
|
||||
raw_input.events.push(Event::Text(ch.to_string()));
|
||||
if !should_ignore_char(ch) {
|
||||
if ch == '\r' {
|
||||
raw_input.events.push(Event::Text("\n".to_owned()));
|
||||
} else {
|
||||
raw_input.events.push(Event::Text(ch.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyboardInput { input, .. } => {
|
||||
if let Some(virtual_keycode) = input.virtual_keycode {
|
||||
@@ -103,6 +109,26 @@ pub fn input_event(
|
||||
}
|
||||
}
|
||||
|
||||
fn should_ignore_char(chr: char) -> bool {
|
||||
// Glium sends some keys as chars:
|
||||
match chr {
|
||||
'\u{7f}' | // backspace
|
||||
'\u{f728}' | // delete
|
||||
'\u{f700}' | // up
|
||||
'\u{f701}' | // down
|
||||
'\u{f702}' | // left
|
||||
'\u{f703}' | // right
|
||||
'\u{f729}' | // home
|
||||
'\u{f72b}' | // end
|
||||
'\u{f72c}' | // page up
|
||||
'\u{f72d}' | // page down
|
||||
'\u{f710}' | // print screen
|
||||
'\u{f704}' | '\u{f705}' // F1, F2, ...
|
||||
=> true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate_virtual_key_code(key: glutin::VirtualKeyCode) -> Option<emigui::Key> {
|
||||
use VirtualKeyCode::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user