-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix disabled widgets "eating" focus #5370
Conversation
01faa55
to
3dfacda
Compare
Preview available at https://egui-pr-preview.github.io/pr/5370-lucas/fix-disabled-widgets-eating-focus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! With such a beautiful test 🤩
|
||
harness.press_key(egui::Key::Tab); | ||
harness.run(); | ||
|
||
let button_1 = harness.get_by_name("Button 1"); | ||
assert!(button_1.is_focused()); | ||
|
||
harness.press_key(egui::Key::Tab); | ||
harness.run(); | ||
|
||
let button_3 = harness.get_by_name("Button 3"); | ||
assert!(button_3.is_focused()); | ||
|
||
harness.press_key(egui::Key::Tab); | ||
harness.run(); | ||
|
||
let button_1 = harness.get_by_name("Button 1"); | ||
assert!(button_1.is_focused()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it
* Closes #686 * Closes #839 * #5370 should be merged before this * [x] I have followed the instructions in the PR template This adds modals to egui. This PR - adds a new `Modal` struct - adds `Memory::set_modal_layer` to limit focus to a layer and above (used by the modal struct, but could also be used by custom modal implementations) - adds `Memory::allows_interaction` to check if a layer is behind a modal layer, deprecating `Layer::allows_interaction` Current problems: - ~When a button is focused before the modal opens, it stays focused and you also can't hit tab to focus the next widget. Seems like focus is "stuck" on that widget until you hit escape. This might be related to #5359 fixed! Possible future improvements: - The titlebar from `window` should be made into a separate widget and added to the modal - The state whether the modal is open should be stored in egui (optionally), similar to popup and menu. Ideally before this we would refactor popup state to unify popup and menu --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
For the test I added a
Harness::press_key
function. We should eventually add these to kittest, probably via a trait one can implement for theHarness
but for now this should do.