rio_window/platform/modifier_supplement.rs
1use crate::event::KeyEvent;
2use crate::keyboard::Key;
3
4/// Additional methods for the `KeyEvent` which cannot be implemented on all
5/// platforms.
6pub trait KeyEventExtModifierSupplement {
7 /// Identical to `KeyEvent::text` but this is affected by <kbd>Ctrl</kbd>.
8 ///
9 /// For example, pressing <kbd>Ctrl</kbd>+<kbd>a</kbd> produces `Some("\x01")`.
10 fn text_with_all_modifiers(&self) -> Option<&str>;
11
12 /// This value ignores all modifiers including,
13 /// but not limited to <kbd>Shift</kbd>, <kbd>Caps Lock</kbd>,
14 /// and <kbd>Ctrl</kbd>. In most cases this means that the
15 /// unicode character in the resulting string is lowercase.
16 ///
17 /// This is useful for key-bindings / shortcut key combinations.
18 ///
19 /// In case `logical_key` reports `Dead`, this will still report the
20 /// key as `Character` according to the current keyboard layout. This value
21 /// cannot be `Dead`.
22 fn key_without_modifiers(&self) -> Key;
23}
24
25impl KeyEventExtModifierSupplement for KeyEvent {
26 #[inline]
27 fn text_with_all_modifiers(&self) -> Option<&str> {
28 self.platform_specific
29 .text_with_all_modifiers
30 .as_ref()
31 .map(|s| s.as_str())
32 }
33
34 #[inline]
35 fn key_without_modifiers(&self) -> Key {
36 self.platform_specific.key_without_modifiers.clone()
37 }
38}