shell: Documentation updates

* rearrange enum 'Key' and impl 'From<Key>' in lexical order
* add documentation for public definitions
* rearrange key_event.scancode in lexical order
* add Tabulator identifier key (K_TAB)
Signed-off-by: default avatarRalf Zerres <ralf.zerres@networkx.de>
parent f634ffb3
......@@ -7,22 +7,6 @@ use orbtk_utils::Point;
/// Represents a keyboard key.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum Key {
Unknown,
Backspace,
Up,
Down,
Delete,
Left,
Right,
Space,
Enter,
Control,
ShiftL,
ShiftR,
Alt,
Escape,
Home,
CapsLock,
A(bool),
B(bool),
C(bool),
......@@ -49,21 +33,33 @@ pub enum Key {
X(bool),
Y(bool),
Z(bool),
Hash,
Alt,
At,
Zero,
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Backslash,
Backspace,
BraceLeft,
BraceRight,
CapsLock,
Control,
CurlyBraceLeft,
CurlyBraceRight,
Delete,
Down,
Dot,
QuestionMark,
Eight,
Enter,
Escape,
ExclamationMark,
Five,
Four,
Hash,
Home,
Left,
Right,
ShiftL,
ShiftR,
Space,
Nine,
Numpad0,
Numpad1,
Numpad2,
......@@ -74,19 +70,24 @@ pub enum Key {
Numpad7,
Numpad8,
Numpad9,
NumpadDivide,
NumpadMultiply,
NumpadSubtract,
NumpadAdd,
NumpadEnter,
NumpadDivide,
NumpadDot,
Slash,
Backslash,
NumpadMultiply,
NumpadSubtract,
One,
QuestionMark,
Quote,
BraceLeft,
BraceRight,
CurlyBraceLeft,
CurlyBraceRight,
Six,
Seven,
Slash,
Tab,
Two,
Three,
Unknown,
Up,
Zero,
}
impl From<Key> for &'static str {
......@@ -144,33 +145,33 @@ impl From<Key> for &'static str {
Key::X(true) => "X",
Key::Y(true) => "Y",
Key::Z(true) => "Z",
Key::Hash => "#",
Key::At => "@",
Key::Zero => "0",
Key::One => "1",
Key::Two => "2",
Key::Three => "3",
Key::Backslash => "\\",
Key::BraceLeft => "[",
Key::BraceRight => "]",
Key::CurlyBraceLeft => "{",
Key::CurlyBraceRight => "}",
Key::Dot => ".",
Key::Eight => "8",
Key::ExclamationMark => "!",
Key::Four => "4",
Key::Five => "5",
Key::Six => "6",
Key::Seven => "7",
Key::Eight => "8",
Key::Hash => "#",
Key::Nine => "9",
Key::Space => " ",
Key::Dot => ".",
Key::QuestionMark => "?",
Key::ExclamationMark => "!",
Key::NumpadDivide => "/",
Key::NumpadMultiply => "*",
Key::NumpadSubtract => "-",
Key::NumpadAdd => "+",
Key::Slash => "/",
Key::One => "1",
Key::QuestionMark => "?",
Key::Quote => "'",
Key::Backslash => "\\",
Key::BraceLeft => "[",
Key::BraceRight => "]",
Key::CurlyBraceLeft => "{",
Key::CurlyBraceRight => "}",
Key::Seven => "7",
Key::Six => "6",
Key::Slash => "/",
Key::Space => " ",
Key::Three => "3",
Key::Two => "2",
Key::Zero => "0",
_ => "",
}
}
......@@ -384,26 +385,27 @@ pub enum MouseButton {
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum ButtonState {
Down,
Up,
}
/// Represents a mouse event.
#[derive(PartialEq, Clone, Copy, Debug)]
pub struct MouseEvent {
pub position: Point,
/// The mouse Button
pub button: MouseButton,
/// The point of the active mouse position
pub position: Point,
/// The mouse button state
pub state: ButtonState,
}
/// Represents a keyboard key event.
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct KeyEvent {
pub key: Key,
/// The state of the Button
pub state: ButtonState,
/// The key identifier
pub key: Key,
/// The text string
pub text: String,
}
......@@ -195,22 +195,23 @@ where
key_event.character.to_string()
} else {
match key_event.scancode {
orbclient::K_ALT => key = Key::Alt,
orbclient::K_BKSP => key = Key::Backspace,
orbclient::K_LEFT => key = Key::Left,
orbclient::K_RIGHT => key = Key::Right,
orbclient::K_UP => key = Key::Up,
orbclient::K_DOWN => key = Key::Down,
orbclient::K_CAPS => key = Key::CapsLock,
orbclient::K_CTRL => key = Key::Control,
orbclient::K_DEL => key = Key::Delete,
orbclient::K_DOWN => key = Key::Down,
orbclient::K_ENTER => key = Key::Enter,
orbclient::K_CTRL => key = Key::Control,
orbclient::K_LEFT_SHIFT => key = Key::ShiftL,
orbclient::K_RIGHT_SHIFT => key = Key::ShiftR,
orbclient::K_ALT => key = Key::Alt,
orbclient::K_ESC => key = Key::Escape,
orbclient::K_CAPS => key = Key::CapsLock,
orbclient::K_HOME => {
key = Key::Home;
}
orbclient::K_LEFT => key = Key::Left,
orbclient::K_LEFT_SHIFT => key = Key::ShiftL,
orbclient::K_RIGHT => key = Key::Right,
orbclient::K_RIGHT_SHIFT => key = Key::ShiftR,
orbclient::K_TAB => key = Key::Tab,
orbclient::K_UP => key = Key::Up,
_ => key = Key::Unknown,
};
String::default()
......
......@@ -127,7 +127,7 @@ where
self.update = true;
}
// todo tmp solution to map touch events to mouse vent
// TODO: cleanup given temporary solution to map touch events to mouse event
while let Some(event) = self.event_state.touch_start_events.borrow_mut().pop() {
self.adapter.mouse_event(MouseEvent {
position: Point::new(
......@@ -310,25 +310,26 @@ fn get_key(code: &str, key: String) -> (Key, String) {
let mut text = String::from("");
let code = match code {
"Backspace" => Key::Backspace,
"Delete" => Key::Delete,
"ControlLeft" | "ControlRight" => Key::Control,
"ShiftLeft" => Key::ShiftL,
"ShiftRight" => Key::ShiftR,
"AltLeft" => Key::Alt,
"AltRight" => Key::Alt,
"ArrowUp" => Key::Up,
"ArrowLeft" => Key::Left,
"ArrowRight" => Key::Right,
"ArrowDown" => Key::Down,
"Escape" => Key::Escape,
"Enter" => Key::Enter,
"OSLeft" | "OSRight" => Key::Home,
"Backspace" => Key::Backspace,
"CapsLock" => Key::CapsLock,
_ => {
text = key.clone();
Key::from(key.chars().next().unwrap())
}
"ControlLeft" | "ControlRight" => Key::Control,
"Delete" => Key::Delete,
"Enter" => Key::Enter,
"Escape" => Key::Escape,
"OSLeft" | "OSRight" => Key::Home,
"ShiftLeft" => Key::ShiftL,
"ShiftRight" => Key::ShiftR,
"Tab" => Key::Tab,
};
(code, text)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment