News for hackers. Stuff that matters.
Re:Immediate Mode GUI Programming by goodpaul6 on Monday January 15, 2024 @06:21PM (#39007399)
I'm not sure the perf/battery life tradeoff is a necessary aspect of immediate mode UI.

  while (running) {
    event := get_next_event()
    process_event(event)
    repaint()
  }
You could just have get_next_event block until there is a meaningful event that occurs (e.g. mouse click). You could even have your UI report "interactive" rectangles to the event layer to prevent it from producing e.g. mouse move events that are irrelevant.

IMGUI is just a different API design IMO.

Re:Immediate Mode GUI Programming by epcoa on Monday January 15, 2024 @06:36PM (#39007528)
> You could even have your UI report "interactive" rectangles to the event layer to prevent it from producing e.g. mouse move events that are irrelevant.

And then what?

With this one innocuous seeming sentence you are hand waving a way a ton of complexity. If you try to implement it you will at least have some respect for toolkit authors.

> IMGUI is just a different API design IMO.

Yes one that is lower level and therefore is fundamentally harder to deal with to get all the things people take for granted in a full blown mature state based GUI toolkit.

You can implement a retained GUI toolkit with IMGUI. Or you can use something already done.

IMGUI eschews this complexity as part of its purpose but it comes with trade offs that limit its use cases.

Re:Immediate Mode GUI Programming by goodpaul6 on Monday January 15, 2024 @07:59PM (#39008106)
I decided to implement it (IMGUI that only repaints when relevant interactions occur) so that my point comes across more clearly:

https://github.com/goodpaul6/imgui-power-saving-example

Of course this is a greatly simplified example, but I can see this extending to any GUI widget that can be represented with a (hierarchy) of rectangles.

Re:Immediate Mode GUI Programming by epcoa on Monday January 15, 2024 @08:12PM (#39008191)
All major GUI toolkits are ultimately implemented on some immediate mode drawing system. So I don’t see the point.

When you unsimplify your example then you are reinventing a wheel. A big wheel. It can be done, but it’s a lot of work. It’s actually easier than ever to implement accessibility for instance (assuming you’re ok pulling in a large dependency), but show me an actual example of this done on top of imgui.

Re:Immediate Mode GUI Programming by goodpaul6 on Monday January 15, 2024 @08:45PM (#39008381)
Here's an IMGUI library that's also accessible (via AccessKit): https://github.com/emilk/egui
Re:Immediate Mode GUI Programming by epcoa on Monday January 15, 2024 @08:55PM (#39008452)
https://github.com/emilk/egui#cpu-usage

Fantastic - “only” 1 to 2 ms (and that’s for simple stuff). Depending on what you’re doing that’s a big chunk. Also time you could be sleeping. Also something you don’t usually have to worry about.

Re:Immediate Mode GUI Programming by goodpaul6 on Monday January 15, 2024 @09:04PM (#39008527)
It looks like they only repaint when there is interaction as well (so it does sleep while nothing is happening).

However, my point with linking this library was just to demonstrate that accessibility and IMGUI are not inherently incompatible.

My point with the example I created above was that you don't have to trade away battery life in order to take advantage of the IMGUI paradigm. My secondary point was also to implement the "interactive rectangles" optimization I mentioned above (which only took a few lines of code).

While I agree with you that there are definitely tradeoffs, I don't think the aforementioned ones are necessary.

Re:Immediate Mode GUI Programming by epcoa on Monday January 15, 2024 @09:56PM (#39008878)
> my point with linking this library was just to demonstrate that accessibility and IMGUI are not inherently incompatible.

Once again, all major GUI toolkits and browser are implemented on top of immediate mode graphics APIs, so you continue to beat this straw man argument. Obviously everything is ultimately immediate mode. No one was refuting those points and sorry they’re not particularly informative.

The point is you’re just rearranging where that state lives and who manages it. You’re retaining it somewhere. But your app is not the best place to manage a lot of this state (as even egui itself admits), it belongs in a well tested library.

Once you start using dirty rectangles, someone has to keep track of them. What benefit is it to me to drive when to call the apis for those details?

IMGUI has a certain elegance where your answer to that is to just say fuck it, and that works well for like a game editor. (The point about accessibility was not that it can’t be done but IMGUI rarely gets actually used where this is ever done). Because if your answer isn’t fuck it to all those things than just go get a library to it for you, which will be managing that state.

I think a lot of people pining for IMGUI really just want sane data binding. Which is understandable, but IMGUI is often throwing the baby out with the bath water.

Like honestly read that egui advantages/disadvantages. That’s a lot of cons (that first one woo) for that one pro (which is not even inherent to all retained APIs).

Re:Immediate Mode GUI Programming by kvemkon on Monday January 15, 2024 @06:29PM (#39007482)
> IMGUI is just a different API design IMO.

There are so many issues about so called "power saving mode" and several open PRs like https://github.com/ocornut/imgui/pull/5116.

Re:Immediate Mode GUI Programming by all2 on Monday January 15, 2024 @06:44PM (#39007601)
There's also the paradigm where only new information is painted.
Re:Immediate Mode GUI Programming by n2d4 on Monday January 15, 2024 @06:29PM (#39007484)
If you do that, you have an event loop again (like in the OP), which your comment's grandparent was trying to get rid of (and your parent explained to them why they can't).
Re:Immediate Mode GUI Programming by whstl on Monday January 15, 2024 @06:46PM (#39007617)
In practice there is always a loop. I believe the point flohofwoe was making is that with an immediate UI you don't have to even touch events in your immediate UI code (they are abstracted away, if needed, in a pretty clean manner, IMO), so there's no need to do anything to get a "sane event loop". I might be wrong about what's his point though.
Re:Immediate Mode GUI Programming by n2d4 on Tuesday January 16, 2024 @02:30AM (#39010460)
There's a loop yes, but not an event loop - the other argument is that you can have a loop that runs every frame, and you just rerender the whole thing
Re:Immediate Mode GUI Programming by whstl on Tuesday January 16, 2024 @05:16AM (#39011602)
Not really. To expand on my response: In practice there is always the operating system's event loop, both in retained and immediate mode. This is true for all mainstream operating systems.
Re:Immediate Mode GUI Programming by n2d4 on Tuesday January 16, 2024 @02:21PM (#39017697)
I mean, that's just being overly pedantic. Surely you see a difference between these two pieces of code?

    while (true) {
        redraw();
    }
and

    while (true) {
        waitForAndProcessNextEvent();
        redraw();
    }
Re:Immediate Mode GUI Programming by whstl on Wednesday January 24, 2024 @08:33AM (#39117106)
Please don't call me pedantic.

What I am explaining is that in practice you have to use the second code, because of how operating systems work. This can be handled by a windowing library (SDL, GLFW, Sokol), and the adapters for libraries like Dear Imgui, Nuklear, etc. also expect the second code.

There are ways to skip processing events in some OSs, but this is not really advised by OS writers, and in some cases you will get subpar experience, apps that don't close correctly, etc.