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

Track the global focus state of the UI #1859

Merged
merged 3 commits into from
Jul 29, 2022
Merged

Conversation

mwcampbell
Copy link
Contributor

Closes #1845.

@mwcampbell mwcampbell marked this pull request as ready for review July 27, 2022 16:01
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Very nice, I like it! But please add some docstrings to the two fn has_focus to explain which one heeds RawInput::has_focus, and why

egui/src/response.rs Show resolved Hide resolved
@mwcampbell
Copy link
Contributor Author

Another option would be to make the Focus::id field pub(crate) (I have to do that anyway on my AccessKit branch), then replace Memory::has_focus with a new Context::has_focus function that checks both the memory and raw input. Then Response::has_focus can simply call Context::has_focus. Of course, I'd have to fix the widgets that directly call Memory::has_focus, but it would be more consistent that way.

@emilk
Copy link
Owner

emilk commented Jul 29, 2022

@mwcampbell I like that approach!

@mwcampbell
Copy link
Contributor Author

@emilk On closer investigation, I don't think my suggested solution will work. The most obvious reason is that other functions in Memory call Memory::has_focus. So I would at least have to keep that function and make it internal or pub(crate). But also, in some cases where Memory::has_focus is used, we don't want the outcome to depend on whether the window has focus. For example, if you put a DragValue into keyboard editing mode, then move focus away from the window, then come back, you probably don't want the DragValue to switch to a button in the meantime. So I think I just have to document the difference between Response::has_focus and Memory::has_focus, or even add a second function in Response that takes global focus into account. Sometimes widgets really should check the global focus, e.g. when determining whether to render a border around a text edit.

@emilk
Copy link
Owner

emilk commented Jul 29, 2022

Let's just go with added docstrings for now!

@emilk emilk merged commit c6c6d2d into emilk:master Jul 29, 2022
@mwcampbell mwcampbell deleted the global-focus branch July 29, 2022 11:27
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.

Global focus tracking
2 participants