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

Fix disabled widgets "eating" focus #5370

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

lucasmerlin
Copy link
Collaborator

@lucasmerlin lucasmerlin commented Nov 14, 2024

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 the Harness but for now this should do.

@lucasmerlin lucasmerlin force-pushed the lucas/fix-disabled-widgets-eating-focus branch from 01faa55 to 3dfacda Compare November 14, 2024 10:50
@lucasmerlin lucasmerlin added accessibility More accessible to e.g. the visually impaired egui labels Nov 14, 2024
Copy link

Preview available at https://egui-pr-preview.github.io/pr/5370-lucas/fix-disabled-widgets-eating-focus
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

@lucasmerlin lucasmerlin added the bug Something is broken label Nov 15, 2024
Copy link
Collaborator

@abey79 abey79 left a 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 🤩

Comment on lines +12 to +29

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());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it

@emilk emilk merged commit 9ecc0b2 into master Nov 26, 2024
48 of 49 checks passed
@emilk emilk deleted the lucas/fix-disabled-widgets-eating-focus branch November 26, 2024 13:31
lucasmerlin added a commit that referenced this pull request Nov 28, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility More accessible to e.g. the visually impaired bug Something is broken egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disabled widgets prevent focus from going to next widget
3 participants