Support for Back button Key on Android (#7073)
When your press a Back button on Android (for example at
`native-activity`), [Winit translates this
key](47b938dbe7/src/platform_impl/android/keycodes.rs (L237C42-L237C53))
as `NamedKey::BrowserBack`. Added convertion to `Key::Escape` at
`egui-winit` module.
---------
Co-authored-by: Advocat <advocat@ogr.local>
This commit is contained in:
parent
a126be4dc1
commit
742da95bd7
|
|
@ -1144,6 +1144,8 @@ fn key_from_named_key(named_key: winit::keyboard::NamedKey) -> Option<egui::Key>
|
|||
NamedKey::F33 => Key::F33,
|
||||
NamedKey::F34 => Key::F34,
|
||||
NamedKey::F35 => Key::F35,
|
||||
|
||||
NamedKey::BrowserBack => Key::BrowserBack,
|
||||
_ => {
|
||||
log::trace!("Unknown key: {named_key:?}");
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -183,6 +183,11 @@ pub enum Key {
|
|||
F33,
|
||||
F34,
|
||||
F35,
|
||||
|
||||
/// Back navigation key from multimedia keyboard.
|
||||
/// Android sends this key on Back button press.
|
||||
/// Does not work on Web.
|
||||
BrowserBack,
|
||||
// When adding keys, remember to also update:
|
||||
// * crates/egui-winit/src/lib.rs
|
||||
// * Key::ALL
|
||||
|
|
@ -307,6 +312,8 @@ impl Key {
|
|||
Self::F33,
|
||||
Self::F34,
|
||||
Self::F35,
|
||||
// Navigation keys:
|
||||
Self::BrowserBack,
|
||||
];
|
||||
|
||||
/// Converts `"A"` to `Key::A`, `Space` to `Key::Space`, etc.
|
||||
|
|
@ -435,6 +442,8 @@ impl Key {
|
|||
"F34" => Self::F34,
|
||||
"F35" => Self::F35,
|
||||
|
||||
"BrowserBack" => Self::BrowserBack,
|
||||
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
|
@ -588,6 +597,8 @@ impl Key {
|
|||
Self::F33 => "F33",
|
||||
Self::F34 => "F34",
|
||||
Self::F35 => "F35",
|
||||
|
||||
Self::BrowserBack => "BrowserBack",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -596,7 +607,7 @@ impl Key {
|
|||
fn test_key_from_name() {
|
||||
assert_eq!(
|
||||
Key::ALL.len(),
|
||||
Key::F35 as usize + 1,
|
||||
Key::BrowserBack as usize + 1,
|
||||
"Some keys are missing in Key::ALL"
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue