Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard shortcut helpers #2202

Merged
merged 17 commits into from Oct 31, 2022
Merged

Keyboard shortcut helpers #2202

merged 17 commits into from Oct 31, 2022

Conversation

emilk
Copy link
Owner

@emilk emilk commented Oct 30, 2022

This adds egui::KeyboardShortcut which is Modifiers + Key.

You can check it with input.consume_shortcut.
You can format it to text using Context::format_shortcut.
You can set that text on buttons (e.g. for menus) with Button::shortcut_text.

Screen Shot 2022-10-31 at 09 11 25

If you use Modifiers::COMMAND, egui will check it against the Mac Command key (⌘) on Mac, but check against Ctrl on other platforms. This means how the shortcut is formatted depends on the OS you are running on. This is difficult to know when compiling for wasm32, so egui now also has Context::set_os and Context::os to set/get that. set_os is meant for egui integrartions. eframe will guess the OS from the User-Agent string when on web. On native it will use target_os.

Bonus 1: You can now ask eframe about the User-Agent string when on web using frame.info().web_info.user_agent.
Bonus 2: You can now query if epaint/egui can show some characters by using Fonts::has_glyph(s).

TODO:

  • PR description
  • Changelogs
  • Menu button support

@emilk emilk marked this pull request as ready for review October 31, 2022 08:20
@emilk emilk merged commit 02b9d2d into master Oct 31, 2022
@emilk emilk deleted the keyboard-shortcuts branch October 31, 2022 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants