Add mnemonic support
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 67
Description
(Probably part of https://github.com/emilk/egui/issues/167)
Egui is currently nice enough to use with Tab/Shift+Tab, but it would be even nicer if there was support for mnemonics (also called accelerators sometimes) because it allows activating any UI element (e.g. button, text entry) without tabbing through all the UI to reach it. In the GTK toolkit (and maybe others? I only know GTK so I can't tell but it's likely the same for e.g. Qt), it is indicated by adding an underscore before the letter that should be used as mnemonic, so for example `_Save` or `P_references`.
I think a proper place to have the mnemonic indicated would be [the WidgetInfo's label field](https://docs.rs/egui/0.12.0/egui/struct.WidgetInfo.html#structfield.label). I suppose that if someone really wants to use a raw underscore in the label then an exception with a double underscore could be added.
A proper implementation of mnemonics should make sure of the following things:
- Holding Alt should underline the mnemonics letter on all the widgets
- Pressing Alt and a character should focus _and activate_ (if applicable) the element linked to the mnemonic, if there is only one widget with this mnemonic.
- in case multiple elements share the same mnemonic, none of them should be activated when using the mnemonic but instead the focus should switch between them on each mnemonic activation, which would allow to activate one particular element even if they share the mnemonic.
- Caps should be treated as non caps so that `_Save` doesn't require pressing Alt+Shift+S but instead just Alt+S.
- The keyboard layout and the various modifiers needed to enter the given character shouldn't break things apart. For example in my keyboard layout the `2` mnemonic requires me to press Alt+Shift+
Ideally it should be possible to have a standalone label that would handle the mnemonic _for an other widget_ (like a label next to a single line entry), but I don't think that would be easily compatible with the immediate-mode nature of egui?
Please let me know if anything is unclear :)
Contributor guide
Assessment
This issue has not been assessed yet.