4 ms·
This is a really interesting approach to writing graphical user interfaces, if you have written any GUI code ever this is highly recommended reading. The differ
by kaib 14y ago
This is a really interesting approach to writing graphical user interfaces, if you have written any GUI code ever this is highly recommended reading. The differences are subtle but extremely important. Here is a simple example that both renders a button and tests if it has been clicked:
if button("label", 100, 100) {
buttonAction();
}
There are two main benefits to IMGUI's. First, you don't need to package your data from whatever store it is into some GUI widget format. The canonical example is a long list or any other data intensive format that you want the user to be able to explore. In a classical GUI there is a lot of data packing and unpacking to be done to handle this.
The second benefit is that your UI's can be much more dynamic and reactive. Because rendering can be nested inside conditional statements and similar it's easy to create bespoke details easily that would be very hard with a traditional GUI framework.
The main limitation with IMGUI's is that they are easier to implement on a system that has pretty constant screen refresh and where you can control the pixels on the screen directly. It is possible to implement an IMGUI on top of a classical GUI framework but that is usually not worth the effort, the classical framework will kill most of the benefits of IMGUI.
A second word of warning is that while IMGUI's tend to result in 40-50% less code that code will be more intensive. This is definitely a technique you want to utilize when you need to hit those high notes and create something world changing.
For a concrete example of IMGUI's in the wild take a look at the editor at http://tinkercad.com http://tinkercad.com. The whole user interface is done as an IMGUI system which is a big reason why we have been able to create things like our unique manipulation widget.
- keeperofdakeys 14y agoManually checking if buttons are pressed seems very wrong to me, I want some kind of event framework to associate a 'button' area to an action. Then when a click is fired, work out which button this maps to, and execute the specific action. I don't see how IMGUI specifically can add features over other methods either.
- seanmcdirmid 14y agoIt requires a twist in your thinking for sure. We are so used to events, but don't realize how user unfriendly they can be. Polling is quite usable, and its rather easy to modularize polling code without any callbacks or inverted control flow.
- repsilat 14y agoIf you have an object-oriented language (or near enough) with usable function types you can still emulate "traditional" GUI things if you really want to. Behold: class ButtonObj method call(): if(button(label, loc) callback() member Rect loc member String label member Func callback list displayList = []; displayList.add(ButtonObj("label", 100, 100, buttonAction)) Func eventLoop(): for i in displayList: i.call()