Dear ImGui – Bloat-free graphical user interface library for C++
Dear ImGui is amazing software with great ideas, but at this point I feel like the &quot;immediate&quot; is a problematic lie much like how &quot;immediate mode&quot; graphics rendering hasn&#x27;t been immediate in years. I think the most appropriate way to describe these libraries is &quot;imperative&quot;, because you&#x27;re constructing retained state by running imperative code and the library is responsible for figuring out how to do what you want it to do.<p>Any properly functioning UI with the features needed by more than a handful of users ends up having to retain a considerable amount of state. This doesn&#x27;t mean that you need to construct a huge graph of interconnected object goo, but a bunch of C&#x2F;C++ calling functions every frame with no retained state won&#x27;t cut it. Libraries like Dear ImGui and Nuklear largely solve this with a combination of wasted energy (by running your code repeatedly) and magical hidden state (managing retained state in the background for you automatically).<p>The fact that retained state does end up existing but behind the curtain means that annoying problems manifest themselves due to it being out of your control. For example, a textbox needs to maintain the current selection along with a scroll offset in its viewport, along with an undo&#x2F;redo history. You might decide to drop some of that but some of it has to stick. In Nuklear&#x27;s case, it relies on stb_textedit to do a lot of the heavy lifting (great library!) and retains state for you behind the scenes. Because the state management is automatic based on the small amount of information Nuklear has, doing something like collapsing a hideable panel makes the textbox &quot;disappear&quot; at which point the scroll offset, selection and undo&#x2F;redo history vanish. The user may have accidentally collapsed the panel (or the program did it for them), and you&#x27;ve now responded to that input by throwing away something very important. You certainly <i>could</i> retain all this state inside your application (whether or not there&#x27;s an API for it in the library is another question), but now you have to come up with a solution for tracking and storing all that state.<p>Other comments have already mentioned the &quot;page tearing&quot; problem (needing an extra frame to respond to state changes, etc) which is one manifestation of this fundamental issue - that retained state is in fact necessary and hiding it creates new problems - but there are other challenges that are easier to ignore. Accessibility is a major one, and current IMGUI libraries are entirely ill-prepared to address it. Another issue is internationalization - not only is RTL text an issue, but complex character sets require shaping (an expensive operation) which also requires caching and additional infrastructure that is going to clash painfully with the very simple &quot;just draw some text&quot; model used by most of these libraries. International text input is also very stateful and you&#x27;ll find that interacting with IMEs is quite difficult if you aren&#x27;t careful about things. (This is especially bad because SDL2 itself has a botched IME implementation, so users of non-western character sets are screwed right out of the gate.)<p>I&#x27;ve been using Nuklear over the past couple years for some development tools and the experience soured me on IMGUI libraries in general because I kept running into these problems that, in retrospect, should not have been a surprise. The UI had lots of rough edges you&#x27;d feel when using it, it was ugly (until I aggressively patched it to address this), it was slow, etc. Dear ImGui is likely higher quality than Nuklear (not that I can say for sure, because I never got it to work due to integration problems) but the fundamental design principles are largely the same and it has its own set of limitations. I&#x27;m hopeful that as time passes these libraries will continue to improve, but I&#x27;ve personally moved on to accepting that a good UI needs retained state and I&#x27;m focusing on ways to make constructing that state as easy as possible without leaving users who need accessibility or foreign character sets out in the cold.<p>Some less relevant footnotes:<p>* The performance obsession demonstrated in some of these libraries is an active hindrance and in some cases actually sabotages performance. Text rendering in Nuklear is &quot;simple&quot; but for remotely adequate performance you end up having to build your own layout cache and take other steps to compensate for the fact that text is not &quot;simple&quot; at all. To avoid running out of memory, you need to come up with a GC for your layout cache. Solving various problems like page tearing will require you to run the whole layout&#x2F;rasterization process for your UI multiple times, so now your fast &quot;immediate mode&quot; code is actually doing all its work repeatedly, burning CPU. So far tearing out Nuklear and replacing it with my own retained mode framework has improved performance and reduced code size.<p>* The degree to which Dear ImGui and Nuklear value convenience is, in my opinion, counter-productive - for example the ability to just drop it in and get a vertex buffer + texture pair with text is great but it turns out to mean that the library is doing a bunch of stuff (like font management) itself and replacing that with something modern is actually... very hard. I think the correct approach here is to take steps to make integration easy instead of going for full &#x27;just clone the repo and run make&#x27; convenience. I had to aggressively modify Nuklear to have any hope of integrating proper text support at all (and then I couldn&#x27;t upstream my changes because it turns out that the &quot;single-header&quot; Nuklear library is not actually single-header. another convenience-oriented lie... we&#x27;re programmers, we can handle extra header files, can&#x27;t we?)<p>* Accessibility is really, really hard. More people need it than you&#x27;d expect. You need to plan for it in advance, and if you didn&#x27;t it will be very hard to fix after the fact. I can&#x27;t say for certain whether Dear ImGui will be able to transition smoothly into an accessible world, but Nuklear&#x27;s design is woefully unprepared. Every element ideally has a human-readable description (for screen readers) and role (button, etc), and your UI needs to have a coherent structure that can be explored by a screen reader. For users with diminished vision you need robust support for adjustable sizes and theming (so you can improve readability and contrast). You also need to consider alternate input methods - full keyboard, game controller, touch - while these libraries are mostly designed for keyboard+mouse.