top | item 42454848

(no title)

joeld42 | 1 year ago

ImGui doesn't have "components" like a traditional toolkit. If you want a custom component you just make a regular function like:

MyCustomThing::MyWidget( "name", whatever_value );

And it gets the current rectangle from a global context, can allocate some of that rectangle space for itself, draw things, react to events, etc. It's more complicated when the widget needs to store state, but ImGui has pretty well established conventions for how to do that, which basically boils down to hashing the widget name or ID and storing your state there. And when you try, you find you need a lot less state than you might expect. Of course if you have custom data that already has state (e.g. an object passed into your widget), you can use and modify that directly which is great.

It's a very different way of thinking, and it does have some challenges but it usually ends up being a lot simpler and more robust than a "retained mode" gui.

discuss

order

No comments yet.