upvote
Both approaches have their downsides and, in my view, retained mode and immediate mode tend to converge as the UI complexity increases. So far, no problems with implementing any UI I want in my experience with egui on a somewhat complicated application (Desktop word processor). Immediate mode is a breath of fresh air from React.

[Edit: although the standard accessibility criticisms apply to my application; although that's more of an issue with my implementation than an indictment of immediate mode generally.]

reply
Accessibility problems are something both retained-mode and immediate-mode UIs have generally. I've found that you can kind-of hack it together but the best route is to incorporate the actual accessibility frameworks of the operating system(s) your targeting. Egui was doing this at one point I think but I'm pretty sure it's either broken now or just doesn't work all that well.
reply
The problem with immediate mode is that most a11y frameworks expect all UI elements to have a stable identity.

Imagine you have a to-do list of 100 items. What happens when a remote user drags and drops item 100 to lie between items 1 and 2? In retained mode, that's clearly communicated to the UI toolkit; the widget representing that todo is told to change its position in the list. In immediate mode, you can't just destroy and re-create the a11y tree on each render. You need some kind of tree diffing algorithm to figure out that it's one op (move item) instead of ~200 ops (change the name and checkbox state for all items between 2 and 100).

reply
> In immediate mode, you can't just destroy and re-create the a11y tree on each render

You don't need to do it each render, just when something structural changes, right?

reply
There are libs that function as a messenger between your "hack" and the OS on this.

You don't lose anything.

This is but my opinion, but toolkits tend to be opinionated piles of **. Talking directly with the GPU to paint stuff is often just saner to me.

reply
From what I've seen immediate mode seems suitable for less fancy UI requirements. If you want to start having a framework solve things like animations and such then you'll probably end up with some form of retained mode.

Over my years making UIs I've found most of the bugs you get is due to incorrect state handling in applications. Having a framework you use which is opinionated and helps you solve that is pretty nice. (If your UI requirements are such that you need it.)

reply
I'm curious too. I currently have both a plasmid editor, and protein/molecule viewer using EGUI. Both have complex UIs, and I haven't hit roadblocks. I think the protein viewer might be more of a canonical immediate-mode case, because most of the window is a 3D render, but it still has a GUI above it.
reply
Kind of off topic, but a protein viewer in Rust sounds really interesting! Is the source code available? I'd love to poke through it (understandable if not though).
reply
I'm also thinking of building a word processor so I'd be interested to see what you're working on if you fancy sharing?
reply
If your UI is fast enough, why not in complex UI’s either? I’d say it gives you good motivation to keep your UI handling code as fast as possible.
reply
Doesn't egui always re-render? I like my idle apps to be doing nothing, I don't want them running their render loop in the background
reply
I think the default behavior is to only re-render if the window is active/focused. You can trigger a render at specific points, including in the main loop, which will result in the behavior you mention.

This can be problematic, e.g. some of the sensor interfaces I have, I want to always display correct data, even if not focused. So, I have to decide if I want to have old data shown in the background misleading users, or have a per penalty from constant renders. Or try something else to be clever. (Maybe have it update at a low rate if not focused? I think that's the move...)

reply
> You can trigger a render at specific points, including in the main loop, which will result in the behavior you mention.

sounds analogous to manual memory management

reply
Which is completely fine. There are bugs but unlike with memory management, render bugs are more in your face.
reply
which is why, I think, it is better to not have to do that manual rendering gymnastics when retained mode does it for you.
reply
Let's not pretend that retained mode is somehow easy. Procedurally changing the system's state in response to events gets pretty complex. A philosophy which approximates the II as a function of state is tempting, in a lot of ways. As someone with a fair amount of experience of both retained mode and immediate mode UIs, I can't confidently say that retained mode requires less "mental gymnastics" than immediate mode.
reply
Breaking: software development require developers to understand what the system does, more at 11
reply
Any quarter decent imgui implementation will idle when there's no input or active animations, and the renderer can generate dirty tiles or rects to unnecessary redrawing -- if it matters, gpus are ridiculously overpowered for drawing a bunch of rectangles. Ui logic is usually firmly in the microseconds realm.
reply
I agree that this is not a necessary downside to immediate mode GUIs, but we're talking about egui specifically here. AFAIK, egui always redraws at some relatively high rate even when nothing is happening. (I'm having trouble finding documentation about what that rate is though.)
reply
That's not true, it only re-renders if there's an input event or an animation running. This is very easy to see if you just put a `println!` in your UI logic.

This is also mentioned in the gui docs here https://github.com/emilk/egui#why-immediate-mode:

> egui only repaints when there is interaction (e.g. mouse movement) or an animation, so if your app is idle, no CPU is wasted.

reply
Iiuc, a tiny clock in the top right corner of the screen will trigger O(n) work where n is the number of elements on the entire screen. On every change of the clock, e.g. every second. This may be more if there are smooth animations, e.g. 25 times per second if that is the animation frame rate.
reply
Sure, but it will consume less CPU than an idle instance of Electron. Or the effort it takes to redraw a React app even once.
reply
There are two modes, reactive and continuous. You can switch between them here in the backend tab:

https://www.egui.rs/

Reactive mode is the one you are looking for.

reply
I really wish this were built into imgui as a first-class use case instead of requiring a hodgepodge mix of unofficial hacks.

I recall the author posting an imgui update saying this will be an officially supported mode, but AFAIK it's still not the case. Otherwise I would be building all my applications with imgui going forward.

Re-rendering the screen, even if it's fast, incurs a lot of memory bandwidth to draw everything and swap framebuffers etc. Not something you'd like to happen on mobile, in particular. Just because the waste is "small", doesn't mean it's acceptable.

reply
Does ImGui work on mobile? I’ve seen it run in web assembly on mobile but typically none of the keyboard inputs work (the mobile keyboard doesn’t pop up, so effectively it’s not usable, at least in that approach).
reply
You typically set it up so that it does not re-render when it's idle. Or at least not at 60fps.

By the way once upon a time, visual studio code I think it was, was using like 20% cpu when idle just because of the blinking cursor, fun.

reply
By default it re-renders on each event. This isn't often on mobile apps, but moving a mouse across a desktop app triggers multiple vents. There is a function call to request a re-render if you want not to wait for an event.
reply
So if it's just an idle visible application, does it not render at all because there are no events? Or am I right that there's some idle redrawing going on
reply
With eframe, it does not re-render when idle, no. You need to have another thread that forces it to redraw on your own schedule. It will also redraw when an event occurs (mouse movement, keyboard presses, interacting with the application in general.)
reply
I suspect (and hope) you can block the main loop if no events are received. This avoids re-rendering if the UI is not visible and no interaction has happened.
reply
do you run without a compositor? I get where you're coming from, but 'idle' can mean a lot of different things and redrawing the whole UI at 60hz is not necessarily 'not idle' nowadays.
reply
I run with a compositor, which is exactly why it's so great for the application to just draw its window once and then the compositor has the window's contents as a texture. The compositor can do whatever it wants with that texture without involvement from the application.
reply
Appreciate the thoughts about both Flutter and egui.

It's not perfect, but I don't know if there's much on the market that addresses robust UI and single code base as well as Flutter.

Very open to other things that are not more complex than Flutter to accomplish the single codebase to multi platform solution it does provide.

reply

  > egui is great for projects where the application runtime is short lived
What is good for a long-lived application, such as an email client? I'm looking for something that fits the same place that Qt fits in the Python world.

Accessibility and keyboard shortcuts are of extreme importance.

reply
Some of the QT people have forked off and started working on slint[1], iced[2] is the most mature gui in the rust ecosystem right now (in my opinion), but still lacking in some ways, including portability to mobile and component libraries are sort of against the design principle so it's allergic to network effects. Iced is built on some pretty orthodox elm architecture principles by some very talented and devs - but they leave very little room for impurity.

[2] https://iced.rs/ [1] https://slint.dev/demos

reply