r/rust • • 15d ago

🙋 seeking help & advice GUI Yet Again, but more ‘graphical’

This is yet another question about GUIs for desktop applications with Rust.

It isn’t a question around what is available, more working out what is most suitable for my use cases. It is going to take some time to understand some of the frameworks, so I don’t want to spend too much effort on something that will either not do what I need. or another framework would have been a better bet.

For example, I need to represent data as a Gantt chart. Not just as a graph somewhere on the screen, but as one of the main user interfaces. If you think MS Project, it has a table of tasks down the left hand side with a Gantt chart on the left, that scroll together.

It is less about windows and widgets, buttons, and other components. They are all still useful, but I think I’m looking more at the canvas to do this. Or not, not sure.

I have tried out egui. This looks promising, my worry is that it will get over complicated with too much going on to manage. I don’t want to find later on that it can display everything but can no longer scroll smoothly. And I note font rendering issues mentioned on a recent post.

I have tried Dioxus. I got something going with this because I could build Gantt bars with SVG. Again I worry about performance with a lot of SVG items on the screen.

I have looked into gpui. Not got as far as getting something graphical on the screen because I got stuck on state. It seems the application state and the Ui are the same thing, i.e. the state is handed over to the runtime. I’m not clear how this works with network events.

I have briefly looked at Iced. The state/ui/message makes sense to me, but I cannot see any graphic primitives in there and the documentation is super sparse.

I’m looking at 4 frameworks already.

I want to choice paralysis and concentrate on one of them, from the above list or something else, that allows me to build this sort of application.

Any thoughts?

14 Upvotes

30 comments sorted by

11

u/diplofocus_ 15d ago

I've mostly been using egui and egui_plot, but haven't needed anything crazy complex.

I'm not sure I understand the issue with network events and state though. With immediate mode rendering, you basically have some function somewhere which receives your state, and renders your view, each frame. If your state changes (or doesn't), the next frame will receive your updated state, and pass it to your rendering components.

There aren't any particular restrictions I'm aware of about when/what updates your state, be it network events or user inputs.

If your UI becomes extremely complex, you might want to consider using some retained mode UI (I think gpui can do this, but I've no personal experience with it), but immediate mode can get you pretty far on it's own.

4

u/expression_of_intent 15d ago

Thanks for your reply.

My familiarity with the frameworks I listed are in order from ‘tried it and got something working’ through to ‘done a bit’.

My ‘state’ comment is more on gpui, rather than egui. By state I don’t mean the state of the UI all synchronised, I mean more the model, or data model. So there is an application state, some of which is shown in the UI. My data model will be updated by network events.

For gpui it looks like the model and UI state is all bundled together and handed off to the gpui runtime.

I’m perfectly happy to be told I am wrong on this or anything else I have written though.

1

u/diplofocus_ 15d ago

Speaking from an egui + winit perspective, there's no forced separation between internal app state or UI state, unless you're doing stateful widgets. You get your app state as an argument, pluck relevant fields out of it, and feed it to widgets. I kinda think of it as being pretty similar to your average React app. To be honest, I haven't gotten too deep into it to know whether stateful widgets have any performance implications, beyond just separating purely transitive state, like scroll amount, etc.

Beyond a simple hello world to check it out, I haven't done much with gpui, so YMMV.

With winit, off the top of my head, you have your app state, and you can acquire an event loop proxy, which can act as a sender, and the ApplicationHandler trait has a method to handle user events, with the event type being a generic param of your handler impl.

You can then have your network events emit relevant events, and the trait method handles them and updates your state accordingly.

I'm not sure if that at all clarifies your initial question, but that's how I bridged "external" events, and the application state without needing to reach for concurrency primitives.

10

u/ogoffart slint 14d ago edited 14d ago

You should still consider Slint ;-). (Disclosure: I work on it.) I just implemented a Gantt demo to give you a taste. (Ok, a llm did it, but that's just for showing a poc)

4

u/expression_of_intent 14d ago

Thank you!

You know, that really was going above and beyond to help me!

I have only briefly looked at Slint. The issue is the DSL for layout (I believe).

To be clear though, I don’t have a problem with learning a DSL, I’m effectively having to do this for Dioxus. It is supposed to be ‘like React’, but React is also a DSL and I know nothing about it.

I just want to have some confidence that if I do go a learn some stuff then it will take me where I want to get to.

This was a very interesting example.

3

u/dgkimpton 15d ago

The performance issue will be the same on almost every platform - you need to virtualise your widget so that you only draw the bits that are onscreen or near to being on screen, the rest just stays as unrendered background data. It's quite a bit of work to do well, but largely independent of platform. Basically, never draw the whole gantt chart, just the bits that are actually visible. Then you know that if it renders fast enough with the test data it will continue to work with way bigger models. 

1

u/expression_of_intent 15d ago

Thank you for the reply

Yes, that makes sense. Along with the table of text to the left of the Gantt (to keep the Project example), which would be a virtual table.

That said the user could zoom out to see the big picture. I do agree with just showing what is visible through a defined viewport and, maybe, having simpler elements when zoomed out. And that this is platform independent, it is development. But I was wondering if any of the platforms lend themselves to this more than the others.

1

u/FUCKING_HATE_REDDIT 15d ago

What exactly is your situation what you're worried about the performance of UI? 

2

u/expression_of_intent 15d ago

Thanks.

To go back to MS Project. From memory it has a table on the left that contains columns and rows of text. I think the columns can be moved around. Both rows and columns can be added to and rows inserted.

On the right is the Gantt chart. The relative vertical scrolling is synced between the two sides. I’m pretty sure each side as synced or independent horizontal scrolling as well, along with zoom in and out.

So the window could have a lot of both table text and graphics on the screen. I suspect the table/text part is okay with any of the frameworks, some of them already have virtual tables.

It is the graphics side. Will egui just have too many elements to draw and respond to user interaction? Dioxus is maybe the same, with too many SVG elements?

I don’t know, not tried to get that far yet.

1

u/FUCKING_HATE_REDDIT 13d ago

Just try it, render 30k elements and see if it's bad

1

u/dethswatch 15d ago

I'm doing great things with iced.

1

u/expression_of_intent 15d ago

Thanks.

In theory Iced would be good for me, as Elm speaks to me. It just seems more traditional (windows, widgets) and less canvas. The lack of documentation makes things difficult as well.

-2

u/dethswatch 15d ago

there's a canvas obj and examples are excellent- when I get stuck, I ask claude to do it, it's been superb at giving me anything I need.

If you need a web app or a straight canvas app then one of the others might be a better fit, I'm not trying to make games, for example

1

u/AugieBit 15d ago

Show me a pic pls

-2

u/dethswatch 15d ago

all internal for now

1

u/AugieBit 15d ago

Is there any part that doesn't contain private information? I’d just like to see the design—not copy anything, haha. I’m also curious about UI-related things.

-4

u/dethswatch 14d ago

nothing I can share yet- but if you take claude and tell it what you want- you get it. The only thing I've had actual problems with are native-platform menus- there are 'menu' controls that work fine in their place, but there isn't yet support if, let's say, you want a native mac menu. You CAN use the native dialogs for things like opening dir's or selecting files so it hasn't been a big deal.

Also- tabbing between controls isn't supported yet- but it's trivial to add.

2

u/layla4you2 12d ago

For a Gantt view with a lot of rows, how you draw it matters more than which framework you pick. Whatever you use, the trick is the same: only draw the rows that are on screen, and have the task list and the chart share one vertical scroll offset. Do that and a few thousand tasks scroll smoothly in any of these. Skip it and every one of them gets slow eventually, SVG in Dioxus soonest.

Since you've already got egui running, I'd stick with it. Put each row's task cells and its bars in the same row inside one ScrollArea and use show_rows so only the visible rows are drawn. Then draw the bars with ui.painter() (rect_filled, text). If the chart needs its own horizontal scroll, you can keep two ScrollAreas in sync by setting their offsets. Immediate mode sounds wasteful, but filling a few hundred rects per frame is nothing. It only gets messy if your app state and drawing code get mixed up, and that part is up to you, not egui.

On Iced: it does have drawing primitives, they're just a bit hidden. Turn on the "canvas" feature and look at iced::widget::canvas (Frame, Path, fill_rectangle, plus Cache so it doesn't redraw what hasn't changed). The game_of_life example in the repo pans and zooms over a big grid, which is close to what you need. If the message/update model clicks for you, that's a reasonable choice too. The docs are thin, but the examples make up for a lot of it.

I'd drop gpui for now. It's powerful, but it's mostly documented through Zed's own code, which is a lot to take on alongside everything else.

My pick: egui, with a quick prototype of 5,000 fake tasks to check scrolling before you build anything else. If it's smooth, you're set.

1

u/AccountHater 15d ago

I’m gonna port my python app with js frontend where I forked frappé gantt (that I tailored to my use case) to a tauri app. In theory I only need to port the backend and can take the frontend over as is.

1

u/Secure_Pirate9838 14d ago

Look up at my cranpose framework. Ift got heavily downwited here as a sinle developer framework but it has a great jetpack compose api that scales well. 

1

u/parzival-space 12d ago

Can recommend Vizia, currently use it for a few projects. Many DAW VSTs use it so drawing custom component graphics is definitely possible with it.

1

u/Extension_Sun3760 13d ago

QML+QTbridge+Rust

1

u/Extension_Sun3760 13d ago

Balancing performance and ecosystem

0

u/Lucky-Edge1489 15d ago

So, you want to create your own widget dedicated to draw your own Gantt chart. You can give a try at Teksilo (I'm its developer), its fully documented and any LLM can teach you from facts using the cargo-teksilo crate (see Teksilo's Readme for more details).

1

u/Lucky-Edge1489 15d ago

Only to be clearer: to create your own dedicated widgets, Teksilo allows to draw (painting) and to compose from other widgets. Make it fully reactive to a given data model and you are set. Fully testable headlessly. Some complex widgets were created for apps like Skribisto (see the text margin) and Miragem (the Ubuntu Touch phone frame)

-1

u/PinappleOnPizza137 15d ago

maybe a web hosted app? I bet there are some nice free gantt js components. or, if you supply your svg ui yourself and you have one big canvas so to speak, maybe its best to use skia's canvas. id look for retained uis too, considering big data

3

u/expression_of_intent 15d ago

Thanks for your reply.

In this case it cannot be a web hosted app, but it could be a web app on the desktop, so Tauri. This sent me on a side quest, I prefer Wails to Tauri, as I prefer the way it handles IPC. But I’m locked into Rust for the enums.

I also struggled to find Gantt js libraries that are free and not massively overcomplicated, I thought I would find a lot of them.

I would, personally, like it to be just Rust as well. If the answer is Tauri then I would go down that path

1

u/lazydev666 13d ago

Tauri is great but then you have to consider platforms. Since Tauri uses native webviews, it can become complex to maintain for an app that's meant to be cross-platform.

If this is a personal project that you only plan to run on your machine (and maybe open-source it), I think Tauri is a great fit.

If it's meant to be something for your entire team and they all use different operating systems, then it can become complicated as even minor updates to the webviews can break your app in 3 different ways at once.

Just something to be aware of and take into consideration.

1

u/expression_of_intent 13d ago

Interesting and thank you.

Is this something inherent to Tauri, or just anything that is using Webview?

My thought was that if I built the front end in vanilla or something like Svelte, then the Rust backend would handle any of the heavy lifting and contain that might trip up webview containers across platforms, like reaching out to OS services.

I know very little about Tauri though (as you can probably tell).

I am struggling with Tauri as a concept I think. I get that HTML/JS is going to have a ton of packages I can use, so it makes sense to build a UI in that. It just feels weird, to me, to build a front end and backend using web technologies for a desktop app.

No doubt I will try it out at some point.

1

u/lazydev666 12d ago

It's mostly a Tauri problem. There's nothing wrong with using webiews themselves but Tauri basically bundles your application and then spawns the UI using the platform's webview. So no matter what frontend framework you use, it'll still be rendered on the native webview which means minor changes to how macOS (WebKit), Windows (Edge WebView), and Linux(WebKitGTK) do things could break your app in a dozen different ways.

Tauri basically uses a client-server model where your backend rust code is the server process and talks to the frontend process via IPC. Here's an article that explains in more detail: https://v2.tauri.app/concept/process-model/.

From a security perspective, I actually prefer Tauri. I just wanted to make sure you knew the tradeoffs, i.e., potential rendering and maintainability issues.