Added get_focused_item() to request the current nav focus #2258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
name: Pull Request
about: Create a pull request to help us improve
title: Added get_focused_item() to request the current nav focus
assignees: @hoffstadt
Description:
Currently there's no easy way to determine which widget is focused. Yes, there's
is_item_focused
, but it only gives a True/False test on a particular widget. You can't ask DPG, "what UUID is currently holding the focus?" - you have to either loop through all widgets checking the state of each one individually, or bind a focus handler to every widget so that you can store the focused ID somewhere.This PR adds a function to DPG to request current focus.
Here's the test program I used:
Concerning Areas:
These changes are implemented much like
get_active_window
is. As a result, the focused item ID is stored inGContext->itemRegistry
, which adds a dependency onmvItemRegistry
tomvAppItemState
.Technically,
mvAppItemState
doesn't need to know aboutmvItemRegistry
. I'd say bothfocusedItem
andactiveWindow
should reside inGContext
rather thanitemRegistry
. Please let me know what you think on this.I can modify the fix so that
focusedItem
(or bothfocusedItem
andactiveWindow
) are inGContext
and there are no unnecessary dependencies.