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

Jumping the user to a different part of the GUI #7583

Closed
tenpn opened this issue May 14, 2024 · 3 comments
Closed

Jumping the user to a different part of the GUI #7583

tenpn opened this issue May 14, 2024 · 3 comments
Labels

Comments

@tenpn
Copy link

tenpn commented May 14, 2024

Version/Branch of Dear ImGui:

1.90.1

Back-ends:

Psydack's UImGui port v4.1.0

Compiler, OS:

Windows 10, Unity 2023.2.13

Full config/build information:

No response

Details:

I have multiple windows started with Begin, each with CollapsingHeaders, each of those with some TreeNodes. Often the windows are all tabbed together but they might not be.

At certain points in the application I'd like to be able to bring a particular window to the front, and unfold headers/trees down to a particular point.

I saw SetKeyboardFocusHere, but if my window isn't even rendering, I am not running the subtree that needs to own the focus to call it.

do I have to do something like if (ImGui::Begin("window") || IsPartOfFocusTree("window")) in every part of my code?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@GamingMinds-DanielC
Copy link
Contributor

Before calling ImGui::Begin() for your window, you can call ImGui::SetNextWindowFocus() to bring it to the front and focus it. For tree nodes and collapsing headers you can use ImGui::SetNextItemOpen() and ImGui::SetScrollHereY() to scroll to the current cursor position.

@ocornut ocornut added focus tree tree nodes labels May 14, 2024
@ocornut
Copy link
Owner

ocornut commented May 14, 2024

It's not a trivial problem to solve in a generic manner here, as they are many variations of desired behavior and/or things are implemented.

(1) You ought to focus the window:
ImGui::SetWindowFocus("name") (or ImGui::SetNextWindowFocus() before Begin())

(2) As for the tree open-state itself, depending on how you store your focus request (as a path?), if you can compute their ImGuiID you might access the storage directly (ImGui::GetStateStorage()->SetBool(), see #7553) so you might incrementally as you render the tree use data from your focus request path to call ImGui::SetNextItemOpen(true / false) on tree nodes.

(3) And you want to see scrolling for which you can use ImGui::SetScrollHereY().


Other notes:

  • SetScrollHereXXX()/SetKeyboardFocusHere()` are rather old APIs and for the later its parameter is inconsistent with most other API, but it generally works. The underlying functions have been quite reworked/improved but haven't made it to public API yet, but I expect things to evolve toward a generally saner set of ActivateItem()/ScrollToItem()/FocusItem() functions with a bunch of nice flags.
  • Test Engine has ways to do all of this in much more simple standardized way, but it's not designed for the same thing and would likely be weird/overkill to use for this situation.

@tenpn
Copy link
Author

tenpn commented May 15, 2024

Thank you folks! A combo of SetWindowFocus(name) and SetNextItemOpen seemed to work. Luckily my code is mostly autogenerated, so I only had to add it to two places to work everywhere. (SetNextWindowFocus didn't seem to work, maybe because I was attempting to focus the same frame that I was adding new windows)

@tenpn tenpn closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants