News for hackers. Stuff that matters.
Re:About the IMGUI Paradigm by bgribble on Friday August 23, 2024 @06:47PM (#41333739)
I love the developer experience of Dear ImGUI, even though I use it through Python wrappers that confuse things sometimes. It just slices like a sword through several layers of often-pointless abstraction and puts the control over the main loop right in your hands.

And when you need to read the source to figure something out, it's just a few files of pretty self-evident C-ish code.

Re:About the IMGUI Paradigm by krapp on Friday August 23, 2024 @07:18PM (#41333949)
It should be the go to for general purpose cross-platform application UI development (instead of Electron,) and it's unfortunate that something so good and so useful is only meant for debuggers and editors.
Re:About the IMGUI Paradigm by tom_ on Friday August 23, 2024 @07:43PM (#41334122)
On the flip side, targeting developers tightens the scope quite a lot! If nothing else, it massively increases the chance your target audience can at least get by with left-to-right text and 7-bit ASCII...

Cornut recently did a 10 year retrospective of Dear ImGui: https://github.com/ocornut/imgui/issues/7892 - an interesting read for me, as a Dear ImGui library user for many years now, but worth your time I think even if you aren't a user yourself. There is a specific section about the scope of the library: https://github.com/ocornut/imgui/issues/7892#issuecomment-22...

Re:About the IMGUI Paradigm by fassssst on Friday August 23, 2024 @08:08PM (#41334290)
Only if you don’t care about accessibility and common controls.
Re:About the IMGUI Paradigm by krapp on Friday August 23, 2024 @08:49PM (#41334536)
You might have a point about accessibility, but what common controls does Dear IMGui lack? It has just about every control I can think of.
Re:About the IMGUI Paradigm by badsectoracula on Friday August 23, 2024 @08:57PM (#41334594)
I think fassssst means controls common across applications in how, e.g., in macOS and Windows many applications use the same controls for labels, buttons, checkboxes, radiobuttons, listboxes, editor boxes, etc with a consistent look and feel/behavior (something at especially on macOS people do appreciate).
Re:About the IMGUI Paradigm by nox101 on Friday August 23, 2024 @10:33PM (#41335077)
It's not just that. The OS adds features into the native widgets. Spell checking, translation, IME support, definition lookup, reconversion (CJK). You get them all for free and the OS can add more with every version, the least being password insertion. Render your own UI and that can't happen. That's one reason why Flash died. It meant that a new platform (mobile) couldn't give the user new ways it interact where as HTML could because it was up to the browser/OS to provide the low-level widgets, not the app itself.
Re:About the IMGUI Paradigm by Barrin92 on Friday August 23, 2024 @08:12PM (#41334331)
>general purpose cross-platform application UI development

because of the immediate mode paradigm it's not really a general purpose framework because the constant redrawing is just a complete resource hog in non real-time applications. The reason other graphics frameworks retain internal state (which Imgui exactly avoids) is to only redraw components when necessary.

It's so popular in games and real time visualization because that's one of the domains where you redraw constantly anyway.

Re:About the IMGUI Paradigm by badsectoracula on Friday August 23, 2024 @08:59PM (#41334619)
You don't need to have a constant redraw and IMGUI libraries do keep internal state. In fact both of these are explicitly mentioned in the linked article:

> IMGUI does not mean that the library doesn't retain data.

> IMGUI does not mean it needs a continuous loop nor need to refresh continuously.

Re:About the IMGUI Paradigm by nox101 on Friday August 23, 2024 @10:45PM (#41335120)
First off, Dear ImGUI is not very non-English friendly. CJK, left-right (Arabic), emoji, are all problematic. It's also got issues with accessibility. Sure it's great, for it's intended purpose, game tools. But it's not so great for a banking app.

Second, Electron is not just UI. It's networking, file access, 2d drawing API, vector graphics, video conferencing, video playback, audio playback, video capture, audio capture, USB access, image decompressing, WebGL, WebGPU, WebAssembly, and many other things in a cross platform package.

It's trivial to make an app on one OS and ship on the other OSes without actually owning those OSes or even if you do own those OSes it requires almost zero knowledge of those OSes quirks and tools to make an app. Compare that to most other native cross platform frameworks and that's rarely true. Learning XCode on Mac, GCC/make/autotools on Linux, Visual Studio on windows, etc...

Re:About the IMGUI Paradigm by amelius on Friday August 23, 2024 @06:57PM (#41333811)
Say I have a very long listbox containing thousands of items, and each item has a height that may be different (e.g. a list of font families where each line may have a slightly different line height).

How would IMGUI perform the drawing, given the scrollbar is at (say) 20%?

Re:About the IMGUI Paradigm by troad on Friday August 23, 2024 @08:10PM (#41334306)
I feel like I must be missing something here. Why not store the ID of the top-most visible list item, and just render the next n until you run out of box height? Surely you're not trying to draw thousands of items that aren't even visible on screen?
Re:About the IMGUI Paradigm by tom_ on Friday August 23, 2024 @07:25PM (#41333992)
I'm not sure I've ever used any library that goes to any particular effort to support this sort of thing. The standard assumption for listboxes is that every row has the same height. So you'd probably handle it the same way you would with any other system: accept that there'll be some effort involved, and get the library to do the remainder for you. So, probably, something like let the library know the total height of the contents, have it look after the viewport height and scroll bar position for you, and then draw the viewport contents as required.
Re:About the IMGUI Paradigm by loic-sharma on Friday August 23, 2024 @08:18PM (#41334369)
Your browser goes through extraordinary lengths to support this sort of thing.
Re:About the IMGUI Paradigm by tom_ on Friday August 23, 2024 @09:09PM (#41334673)
I guess I just got old at some point. I simply don't think of web browsers as relevant when it comes to programming.
Re:About the IMGUI Paradigm by badsectoracula on Friday August 23, 2024 @08:40PM (#41334493)
I'm not a fan of IMGUI, but there is nothing about it that prevents caching data (in fact AFAIK most IMGUI libraries do cache data), so it'd be done pretty much the same way as in a regular GUI library: by caching the (unscrolled) item rects, updating the rect cache whenever the listbox size changes, caching the visible (after scrolling) items and updating the cache whenever the listbox size or scroll position change. Might have forgotten some other case, but the idea is the same.
Re:About the IMGUI Paradigm by amelius on Saturday August 24, 2024 @08:43AM (#41337837)
But caching means that you're storing information about the items, which brings you closer to RMGUI.
Re:About the IMGUI Paradigm by TillE on Friday August 23, 2024 @08:49PM (#41334534)
> and each item has a height that may be different

This criterion means you'd have to roll your own solution. Otherwise, ImGuiListClipper exists for exactly this kind of thing.

https://github.com/ocornut/imgui/blob/864a2bf6b824f9c1329d84...

Re:About the IMGUI Paradigm by lylejantzi3rd on Friday August 23, 2024 @07:08PM (#41333878)
> they are different interpretation of what IMGUI means?

Yes. Good luck clearing that up. The programming community as a whole couldn't even get Object Oriented Programming right. It originally meant little machines passing messages to each other (Smalltalk, Objective-C). What we got was inheritance, encapsulation, and polymorphism (Java).

Re:About the IMGUI Paradigm by igouy on Saturday August 24, 2024 @12:04PM (#41339162)
> It originally meant

"Smalltalk encourages well-factored designs through inheritance. Every class inherits behavior from its superclass … all forms of ordered collections in the system will instantly acquire this new capability through inheritance."

"Modularity: No component in a complex system should depend on the internal details of any other component."

"Polymorphism: A program should specify only the behavior of objects, not their representation."

1981 "Design Principles Behind Smalltalk" Daniel H. H. Ingalls

https://www.cs.virginia.edu/~evans/cs655/readings/smalltalk....

Re:About the IMGUI Paradigm by ogogmad on Friday August 23, 2024 @07:19PM (#41333955)
Are there GUI builders like for VB6, but for IMGUI libraries?
Re:About the IMGUI Paradigm by gyomu on Friday August 23, 2024 @07:41PM (#41334111)
Posted last week: ImRAD is a GUI builder for the ImGui library

https://news.ycombinator.com/item?id=41261426

Re:About the IMGUI Paradigm by malkia on Friday August 23, 2024 @07:41PM (#41334110)
On the other hand, flutter has plenty of state management options :) - https://docs.flutter.dev/data-and-backend/state-mgmt/options - it's like living in the US, you don't like how your state is managed - move to the next one!
Re:About the IMGUI Paradigm by jesse__ on Friday August 23, 2024 @08:24PM (#41334396)
Somewhat of a nitpick..

> The acronym is misleading because "immediate-mode" was initially coined as a reference to obsolete graphics API which made it very easy to render contents.

Is that actually true? From what I remember of hearing Casey (the person who coined the term) talk about it on Handmade Hero and various other streams, it's differentiating between 'immediate mode' and 'retained mode' GUI APIs (QT, GTK, Swing, MFC .. etc) which make you retain handles to UI elements. AFAIK it didn't have anything to do with the graphics API whatsoever ..? Right?

EDIT: Watched the video linked of Casey from 05, which I'd never seen before and was quite interesting. I'm not totally convinced that the small portion he talked about renderer APIs near the 10 minute mark substantiates the claim, but it might.

Re:About the IMGUI Paradigm by phire on Friday August 23, 2024 @08:32PM (#41334438)
Yes, it's true.

Direct3D had a retained mode up until version 3.0, but the only examples of it ever being used in a commercially successful game was LEGO Island and LEGO Rock Raiders.

Instead of supplying all the draw commands every frame, you would give it your 3D scene and it would draw it.

Re:About the IMGUI Paradigm by torlok on Friday August 23, 2024 @10:30PM (#41335065)
All modern graphics APIs are retained mode, because you push data to the GPU and the GPU maintains its own state. The closest you can get to immediate mode is OpenGL 1.0 with glBegin, etc.
Re:About the IMGUI Paradigm by badsectoracula on Friday August 23, 2024 @08:46PM (#41334522)
I tried to use it (for fun) at some point but the API design felt too verbose/cumbersome for what it did and by the time DrawPrimitive was added in D3D5 it was simpler to use that directly than use D3DRM.

It was also very clear that D3DRM was designed by a different team than D3DIM.

Re:About the IMGUI Paradigm by bob1029 on Friday August 23, 2024 @08:29PM (#41334417)
https://learn.microsoft.com/en-us/windows/win32/learnwin32/r...

I think you could also draw some analogies between server side and client side rendering. Where the authoritative view state lives is the most important bit I think.

Re:About the IMGUI Paradigm by badsectoracula on Friday August 23, 2024 @08:48PM (#41334533)
One of my perverse ideas for a project is to make a Dear ImGUI (the most common IMGUI library and basically what many people associate with "ImGUI") backend for Lazarus/LCL (the most non-IMGUI/Retained mode framework you can probably think with OOP -something that IMGUI aficionados seem to have a distaste for- layers thick enough to act as armor :-P).
Re:About the IMGUI Paradigm by akira2501 on Friday August 23, 2024 @09:17PM (#41334715)
> "Minimize state synchronization."

> void UpdateUI()

Minimize state synchronization by effectively synchronizing state on each screen refresh?

> "Minimize state storage on user side."

> Immediate mode is a style of API where important state is kept in user code

Then reduce state stored in user code by storing "important state" in user code?

> "Minimize setup and maintenance."

I don't find the example convincing. It seems like any more complexity beyond this toy example puts you right back where you started. Building components by hand is stone age ideology regardless of how you push state.

https://github.com/ocornut/imgui/blob/master/examples/exampl...

> "Easy to use to create dynamic UI which are the reflection of a dynamic data set."

Which is great for a video game.

Re:About the IMGUI Paradigm by tom_ on Friday August 23, 2024 @09:45PM (#41334853)
Try it! Worst thing that'll happen is that you'll still hate it.
Re:About the IMGUI Paradigm by d--b on Friday August 23, 2024 @10:01PM (#41334926)
> Nowadays I am starting to believe that the term has caused more harm than benefits, because it suggests there are two camps "IMGUI" vs "RMGUI". The reality is there is a continuum of possibilities over multiple unrelated axises.

> The fact that we are even trying to put an official definition to a label is hindering people's imagination about the many possible areas of researches to be done in UI space.

Well said, but then the author proceeds and lists what IMGUI is and what it’s not.

My opinion is that we may just think about IMGUI as “the stuff that dear-imgui does”, which people understand well. And yes there’s a loop, and things get redrawn all the time and so on.

Everything else that borrows concepts from that is IMGUI-ish. I for myself definitely use some IMGUI concept when I do js apps, but is it imgui? Definitely not. Is it imgui-ish, hell yeah.

Trying to make the term IMGUI mean “good way of doing UI” is not gonna work…

Re:About the IMGUI Paradigm by theamk on Saturday August 24, 2024 @12:20AM (#41335608)
There maybe a continium in games space, but in non-game apps it's all crystal clear and sharp boundaries:

Can the app stop generating wakeup interrupts and let CPU/GPU sleep?

Yes -> this means app events (like network transfer) need to be able to generate "update" events, which means those events need to be directed somewhere, which means retained mode.

No -> this means GUI is allowed to poll non-stop and thus can check every variable 60 times per second to support immediate mode.

Re:About the IMGUI Paradigm by modeless on Saturday August 24, 2024 @12:48AM (#41335735)
Immediate mode and polling are not the same thing. With Dear ImGui you own the event loop so you can draw as frequently or infrequently as you want. It is not necessary to draw 60 times per second when nothing is happening.

Dear ImGui's sample code currently does draw every frame even when nothing is happening. Omar has said that he would eventually like to change this and it's on his roadmap, but it's low priority because he is currently targeting game industry users and doesn't want to attract a lot more users in other areas that will add to his support load and dilute his focus. [1]

He also has said the same thing about accessibility and fancy theming. These features are good examples of why "the stuff that dear-imgui does" is not a good definition of immediate mode. People often assume that anything Dear Imgui doesn't do is hard or impossible for any immediate mode API, but that's far from the truth.

Omar is only one guy. He has a target audience in mind and is not trying to satisfy all use cases at once. You have to remember that when comparing Dear ImGui to a framework like Qt or SwiftUI or whatever that has hundreds if not thousands of developers contributing to it.

[1] https://github.com/ocornut/imgui/issues/7892

Re:About the IMGUI Paradigm by torlok on Friday August 23, 2024 @10:47PM (#41335129)
It sucks that this is what immediate mode got reduced to. If you listen to what Casey was advocating for, it was to avoid the need to synchronise state between local state and black box state. This can be applied to UI, but just as well to f.e. a physics engine, where a constraint can live as long as you keep calling doConstraint().

Unfortunately, all people seem to have gotten out of that was if(doButton(...)).

Re:About the IMGUI Paradigm by dsp_person on Friday August 23, 2024 @10:21PM (#41335022)
> IMGUI does not mean it needs to refresh all-or-nothing.

The author of microui described an interesting approach to this here https://rxi.github.io/cached_software_rendering.html

Re:About the IMGUI Paradigm by pjmlp on Friday August 23, 2024 @10:55PM (#41335167)
Basically, it is how we did graphics programming back in MS-DOS, UNIX framebuffers, and everywhere else where desktop OSes didn't had a GUI framework to start with.
Re:About the IMGUI Paradigm by sweeter on Friday August 23, 2024 @11:23PM (#41335303)
I hate writing GUI's, I cannot get them to "click" with me, but for some reason the immediate mode GUI paradigm makes a lot more sense to me. It doesn't help that UI code is usually really blocky and error prone either, but IMGUI and GIO are great
Re:About the IMGUI Paradigm by giovannibonetti on Saturday August 24, 2024 @01:54PM (#41339987)
Working with GUIs really "clicked" with me when I learned the Elm programming language and framework for building web applications (front-end) [1]. The Model-View-Update paradigm matches very well the UML state machine modelling taught in universities [2].

[1] https://guide.elm-lang.org/architecture/ [2] https://en.wikipedia.org/wiki/UML_state_machine

Re:About the IMGUI Paradigm by 0x1ceb00da on Friday August 23, 2024 @11:49PM (#41335433)
One thing I never figured out how to do in an immediate mode system is encapsulating functionality. In a retained mode system I can have, for example, a panning view widget, which wraps another widget and allows you to pan and zoom using the mouse. How would one encapsulate such functionality with an immediate mode ui toolkit?
Re:About the IMGUI Paradigm by dsp_person on Saturday August 24, 2024 @12:40AM (#41335698)
That sounds exactly like a scroll area. For example Dear ImGui has scrolling based on a draw list which will be clipped to the current visible area. Nothing stopping adding panning and zoom controls for this. In fact I saw mouse panning added in one of the ImColorTextEdit forks. Maybe Dear Imgui doesn't have a "zoom" feature built-in, but I don't imagine that being hard to implement. Just additional scaling and clipping to the draw list.
Re:About the IMGUI Paradigm by 0x1ceb00da on Saturday August 24, 2024 @08:48AM (#41337888)
Can it be done outside of the library in the user code?
Re:About the IMGUI Paradigm by dsp_person on Saturday August 24, 2024 @03:14PM (#41340663)
Click to drag yes since it's just using ImGui::SetScrollX, ImGui::SetScrollY based on mouse events. For zoom, it could be in user code if it's your own custom widgets or rendering with ImGui::GetWindowDrawList()->Add{Something}, but I don't think Dear ImGui has a super great api for zoom with the built in windows/widgets like we're talking about here. It's a limitation of this api, not the immediate mode paradigm in general (like the article argues).

For example, ImColorTextEdit renders an ImGui:Dummy() to create a dummy widget of a specified width and height which defines the scroll area, and then based on the current ImGui::GetScrollX() and ImGui::GetScrollY() it uses ImGui::GetWindowDrawList()->Add{Rectangle,Line,Text, etc} to custom render the contents inside the widget based on what should be visible at the scroll positions. Since it's custom code it would be easy to use a zoom param to adjust the scale of things and what is submitted to the draw list.