Code Monkey home page Code Monkey logo

Comments (3)

GamingMinds-DanielC avatar GamingMinds-DanielC commented on September 26, 2024

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.

from imgui.

ocornut avatar ocornut commented on September 26, 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.

from imgui.

tenpn avatar tenpn commented on September 26, 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)

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.