Skip to content

Commit 742da95

Browse files
ardocratAdvocat
andauthored
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](https://github.com/rust-windowing/winit/blob/47b938dbe78702d521c2c7a43b6f741a3bb8cb0b/src/platform_impl/android/keycodes.rs#L237C42-L237C53) as `NamedKey::BrowserBack`. Added convertion to `Key::Escape` at `egui-winit` module. --------- Co-authored-by: Advocat <[email protected]>
1 parent a126be4 commit 742da95

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/egui-winit/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ fn key_from_named_key(named_key: winit::keyboard::NamedKey) -> Option<egui::Key>
11441144
NamedKey::F33 => Key::F33,
11451145
NamedKey::F34 => Key::F34,
11461146
NamedKey::F35 => Key::F35,
1147+
1148+
NamedKey::BrowserBack => Key::BrowserBack,
11471149
_ => {
11481150
log::trace!("Unknown key: {named_key:?}");
11491151
return None;

crates/egui/src/data/key.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ pub enum Key {
183183
F33,
184184
F34,
185185
F35,
186+
187+
/// Back navigation key from multimedia keyboard.
188+
/// Android sends this key on Back button press.
189+
/// Does not work on Web.
190+
BrowserBack,
186191
// When adding keys, remember to also update:
187192
// * crates/egui-winit/src/lib.rs
188193
// * Key::ALL
@@ -307,6 +312,8 @@ impl Key {
307312
Self::F33,
308313
Self::F34,
309314
Self::F35,
315+
// Navigation keys:
316+
Self::BrowserBack,
310317
];
311318

312319
/// Converts `"A"` to `Key::A`, `Space` to `Key::Space`, etc.
@@ -435,6 +442,8 @@ impl Key {
435442
"F34" => Self::F34,
436443
"F35" => Self::F35,
437444

445+
"BrowserBack" => Self::BrowserBack,
446+
438447
_ => return None,
439448
})
440449
}
@@ -588,6 +597,8 @@ impl Key {
588597
Self::F33 => "F33",
589598
Self::F34 => "F34",
590599
Self::F35 => "F35",
600+
601+
Self::BrowserBack => "BrowserBack",
591602
}
592603
}
593604
}
@@ -596,7 +607,7 @@ impl Key {
596607
fn test_key_from_name() {
597608
assert_eq!(
598609
Key::ALL.len(),
599-
Key::F35 as usize + 1,
610+
Key::BrowserBack as usize + 1,
600611
"Some keys are missing in Key::ALL"
601612
);
602613

0 commit comments

Comments
 (0)