Coder Social home page Coder Social logo

Comments (5)

UUSim avatar UUSim commented on May 14, 2024 63

Ouch! A very big sorry indeed! I did not see that.

For other users making the same mistake (not reading the troubleshooting tips in the cpp that is..), here is the help section covering this issue:

  • some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget).
    to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer.
    when you call Button("OK") the button shows "OK" and also use "OK" as an ID.
  • ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows.
    within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts.
    so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc.
    some functions like TreeNode() implicitly creates a scope for you by calling PushID()
  • when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes.
    depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense!
    • e.g. When displaying a single object, using a static string as ID will preserve your node open/closed state when the targeted object change
    • e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object
  • when passing a label you can optionally specify extra unique ID information within the same string using "##". This helps solving the simpler collision cases.
    • e.g. "Label" display "Label" and uses "Label" as ID
    • e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID
    • e.g. "##Foobar" display an empty label and uses "##Foobar" as ID

In my case, I used the final option.

from imgui.

xaxxon avatar xaxxon commented on May 14, 2024 25

and use label###ID if you don't want the label to be part of the ID

from imgui.

ocornut avatar ocornut commented on May 14, 2024 3

This is indeed a common question especially for first-time users of immediate mode GUI library.
I have now added an "index" at the very top of the file, listing all sections in the file so hopefully people will be more aware of the existence of the FAQ.

from imgui.

xythobuz avatar xythobuz commented on May 14, 2024

Looking at imgui.cpp line 115ff (if you are confused about the meaning or use of ID in ImGui), I think there is already a solution to your problem: Either use PushID() or PopID(), or add extra ID information to the label using "Yes##Foo".

from imgui.

JG-Adams avatar JG-Adams commented on May 14, 2024

This ought to be made automatic by IamGui. Because, it can be a security issue, performance, memory, and a waste of codespace. calling push and pop, and keeping track of id. (Deep nesting issue)

If I understand this right, it is queued into the Graphic library for every draw instruction made?
If that is the case, it should go from 0-on by itself allowing every button to be accessed regardless of name.
Why use namespace to begin with? It is not cache friendly. (Array would work)
Just my thought. Cause, I expected it to always work until recently.

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.