top | item 28166663

Egui: An easy-to-use immediate mode GUI

366 points| ducktective | 4 years ago |github.com | reply

141 comments

order
[+] paulshen|4 years ago|reply
I investigated egui early this year. It's a very good library! For me, getting used to immediate mode UI was a change from being used to DOM / React-style UI. imgui works well for a lot but it struggles with complex layouts, eg flexbox. This is acknowledged in egui's README

Couple things I built with egui: https://artifacts.bypaulshen.com/rust-gui/code-render/ https://artifacts.bypaulshen.com/rust-gui/tictactoe/

[+] capableweb|4 years ago|reply
Could you possible share the source to your two examples? I'd love to see how much is accidental complexity vs actual complexity, compared to how web UIs (and other similar paradigms) can be built almost in an almost fully declarative way.
[+] fluidcruft|4 years ago|reply
Tic-tac-toe is frustrating me because I can't seem to force it into a draw.
[+] soheil|4 years ago|reply
The tic tac toe is easily defeated
[+] ducktective|4 years ago|reply
Be sure to checkout the web demo, quite impressive IMO:

https://emilk.github.io/egui/index.html

[+] elpocko|4 years ago|reply
Why does every IM UI library have a dropdown widget that they call "Combo box"? Dear IMGUI, Nuklear, this one does it too.

A dropdown list is not a combo box - a combo box is a text input box combined with a dropdown list. This "combo" aspect is missing in all these frameworks, but they still call their simple dropdowns "Combo box".

[+] athorax|4 years ago|reply
The font rendering is almost unreadable on my machine, but the functionality seems to be there
[+] mastax|4 years ago|reply
> NOTE: The WebGL backend does NOT pass the color test.

> This is because WebGL does not support linear framebuffer blending (not even WebGL 2!).

> Maybe when WebGL3 becomes mainstream in 2030 the web can finally get colors right?

Yes, I had to transcribe this manually because I couldn't copy and paste it.

[+] micheljansen|4 years ago|reply
This is way snappier on iOS than I would have expected. Feels faster than most web apps.
[+] Rd6n6|4 years ago|reply
That official egui demo is phenomenal.
[+] dleslie|4 years ago|reply
I can't seem to select any text on my phone.
[+] theiasson|4 years ago|reply
As a user of a keyboard driven browser, I hate it. I hope this trend of rendering the whole page on html canvas never catches on.
[+] sodality2|4 years ago|reply
I use this in a few of my projects. Simple, no complaints. Compile time is faster than it takes for me to yawn most of the time (using mold linker and sccache, which improves compile time a lot with a far superior linker and caching compiled dependencies, respectively).

(Edit to add: below complaint is entirely within rust and irrelevant to this library)

Only problem (not the fault of egui) is sometimes the elements disallow me using the templateapp object mutably as a whole: sometimes I have to mut borrow a part of `self` before the ui part (instead of mutating `self.whatever` within the UI element, I have to do `let borrow = self.whatever.borrow_mut()` before the UI element then call that borrow) which seemed odd to me as a beginner. I think this is mostly a rust "problem" but also maybe because of how UI element creation was designed.

If you understand the borrow rules then you'll probably understand it fine. I might be able to just lock an Arc Mutex instead and avoid the problem but I just learned how to use them so :p

[+] soheil|4 years ago|reply
Reminds of highly interactive older Windows programs, like Photoshop. Every slight mouse movement gives you some sort of feedback, every click makes a change, everything is snappy... I like those things and I'm sad the web took them away. On the web everything is dull and dead, you can tell it very much was designed for reading.
[+] dleslie|4 years ago|reply
How is it for accessibility?

Looking at the custom widget example didn't leave me with the impression that it has that in mind, but I could be mistaken.

[+] ndarilek|4 years ago|reply
Blind screen reader user and game developer here.

As of a recent release, egui pushes out some events that I'm able to consume and provide TTS feedback for. You can find a simple Bevy example with a bit of event coverage here:

https://github.com/ndarilek/bevy_egui_a11y

In my game, I'm able to use this for buttons, checkboxes, and single-line text edit fields. Sliders are a bit wonky but I'm hoping to eventually get those working better as well. Much of this development is needs-driven for me, and as of now I only need these few widgets. I certainly wouldn't complain if coverage improved, though. :)

Before anyone jumps on me about screen readers not being the accessibility end game, I do know that. But as a totally blind developer myself, I can't easily work on solutions for low vision, high contrast, etc. And for my needs (simple keyboard navigable game UIs for games targeted at blind players) it works well enough, and should hopefully get better soon.

For true cross-platform accessibility with integrations into native APIs, we'll need something like https://accesskit.dev.

[+] mastax|4 years ago|reply
The WebGL demo has a checkbox for (Experimental) screen reader support but I don't have any speakers on this computer to test.
[+] 4fips|4 years ago|reply
Yeah, I believe accessibility is not addressed at all. Similarly when compiler for web, it would be great if the UI would actually behave as text (actual web page) and could be copied into the clipboard etc.
[+] da_big_ghey|4 years ago|reply
Why is everyone concern with accessability on small gui tool? Someone make a cool project and always hackernews with the question on how it serve this very small demographic.
[+] no_time|4 years ago|reply
Looks pretty nice apart from the font rendering, which is terrible. It looks half decent with the default color scheme but when you switch to the dark mode it really shows.

I'm using a regular 1920x1080 27" display for reference

EDIT: the unhinted editor font looks good.

[+] sodality2|4 years ago|reply
Oddly enough it's the inverse for me: I can hardly read the light theme one.
[+] syrusakbary|4 years ago|reply
I was playing last week with this framework.

One of the best things that Egui does is updating the layout using a reactive rendering strategy by default. So rather than doing a paint per frame (each 15ms), it does it lazily only when the state changes.

For example: if you have a plot that updates each 10ms... a UI paint will be triggered each 16ms (up to 60fps I believe). If not, the UI will be updated lazily (when you move the mouse or other event happens).

Note: you can choose a "continuous" rendering mode for the backend as well.

It also has great accessibility with a built-in screen reader. It's an impressive piece of work.

[+] andrewmcwatters|4 years ago|reply
This is an old UI redraw strategy. It’s been used since the dawn of GUIs and is referred to as invalidation.

Here’s an example of a standard GUI invalidation event: https://github.com/Planimeter/grid-sdk/blob/master/engine/cl...

As you mentioned, most GUI software invalidates primarily on mouseovers, and individual components handle things like invalidation on focus.

[+] jbritton|4 years ago|reply
I see many complaints about the font rendering and I also agree the fonts don’t look good. This is a general problem with OpenGL. OpenGL draws triangles. There is no support for antialiased text rendering. And if one can figure out how to render live text with OpenGL, it won’t be something a GPU is efficient at rendering. I think the normal approach is to pre-render all needed glyphs and then move them into position. Pathfinder, Slug, and the work from Raph Levien are the only projects I know working on GPU based font rendering.
[+] gavinray|4 years ago|reply
Something interesting to think about:

- This has a framework "eframe" which lets you write generic apps which can be rendered and run either natively on on the web with WASM:

  - https://github.com/emilk/egui/tree/master/eframe
This has me thinking -- there's an existing standard "Web Audio Modules (WAM)" which never really went anywhere:

https://www.webaudiomodules.org/

I'm imagining some way of bridging the VST3 API's and the WAM API's, so that you could write code using "eframe" that would run either as a natively compiled VST plugin, or in a browser and using the DOM audio API's as a Web Audio Module.

               native -- glium (OpenGL) --                              --- VST3/LV2 API "Adapters"
              /                           \                            /
    eframe ---                             Generic Audio/Synth/FX API's
              \                           /                            \                                                   
               web ----- WASM (WebGL)-----                              --- Web Audio Modules API "Adapter"
Wouldn't something like that just be really friggin cool?

I'm not big-brain enough to figure out the details or if it's even viable, but damn it would be revolutionary.

[+] gameswithgo|4 years ago|reply
Figuring this stuff out is mostly grunt work, see if you can get a minimally viable prototype going, then maybe you can attract some big brains to refactor and improve and make it into something.
[+] soheil|4 years ago|reply
I just couldn't resist posting this here from one of the files comment section:

iOS-style toggle switch:

    _____________
   /       /.....\
  |       |.......|
   \_______\_____/
[+] freemint|4 years ago|reply
Not sure if that would look better:

    _____________
   /       /.....\
  (       (.......)
   \_______\_____/
[+] 4fips|4 years ago|reply
I'm using it for some of my little tools, and it's pretty seamless going between native and web, which I appreciate a lot, and unlike other non-native UI frameworks, navigating through egui feels pretty natural (the way input are handled etc).
[+] Decabytes|4 years ago|reply
I've always enjoyed making little apps with Immediate mode GUIs. It's a shame that they aren't as effective as retained GUIs for more complex apps.

When I was still programming in Rust FLTK was the only GUI I used that both worked on my Raspberry Pi 4 and was something I felt like I could grasp. I'm not sure if that is retained or immediate or not. I wish the OS maintainers would all get their act together and create an api that made creating cross platform GUIs easier. You can't blame people for using Electron when you see the state of desktop GUIs

1. https://github.com/fltk/fltk

[+] beagle3|4 years ago|reply
FLTK is retained.

It’s, from my experience, the sanest of all toolkits - much easier and simpler to use than almost any other, for 98% of tasks, and usually faster. Back in 1998(!) when I started using it, it was also the only flicker free one for Windows and X (without very significant effort) although I believe that gap was finally closed circa 2008 or so.

[+] DennisP|4 years ago|reply
Why aren't they good for more complex apps?
[+] radarsat1|4 years ago|reply
The plot widget is pretty nice. Makes me wonder if it could be an interesting frontend for viewing data in Python, like a realtime-capable, GPU-driven, web-friendly matplotlib.
[+] innocenat|4 years ago|reply
One thing I wish every immediate mode GUI library would show is how it handles complex script like Thai, Arabic, etc. because it's quite hard to get it correct, but it's also the hard requirement if your application need to support those language.
[+] MrWiffles|4 years ago|reply
I took a look at the GitHub repo and I understand this is a GUI library for Rust, but I don't quite understand what they mean by "immediate mode" - could someone elaborate on that, please? Thank you!
[+] accountofme|4 years ago|reply
Immediate mode guis, afaik started in games. The GUI is written on every frame of the game, layout and state (i.e. button presses) are handled in code.
[+] prionassembly|4 years ago|reply
This looks like a good excuse / starting point to learn Rust, but available documentation is basically tutorials that are hard to follow without knowing Rust. (I did work through Rustlings but mostly forgot it).

Of course, it's unfair to ask of any library to provide an intro that also presents the surrounding language. But Rusteros are always so eager to gain converts so... hey, here's a tip.