Most GUIs are written such that each button or other element is an object. You have an initialisation phase in which you create the objects, then you call update and render functions, and feed them events (such as mouse clicks). You get back function calls, in which you do stuff.

Fair enough, but it takes a couple of objects and functions to handle even the most simple button. What if each button could be referenced in only one place, and be just be a single function call?

Well, there is a way to do that. There’s a description of the technique here:

http://www.mollyrocket.com/forums/viewtopic.php?t=134&start=0&sid=0517c6f755123b9ffab5fd8165b70afe

Immediate mode GUIs do things differently. Now the input becomes the state, and the GUI elements become functions. Buttons don’t exist at all from one frame to the next. There’s less code (on the user side) and more direct control over the GUI.

There’s a lot of discussion about which type of GUI is ‘more elegant’, ‘simpler’ or ‘more efficient’. These questions are rather subjective. You can do anything either way, and write it well or badly. Some things, such as graphical layout tools, work more naturally in retained mode. Immediate mode lends itself particularly to scripting. Not being an artist, I’m going for immediate mode. Take your pick.

 

Advertisements