logoalt Hacker News

iTokiotoday at 7:24 AM3 repliesview on HN

I almost never use inheritance beside using some kind of interfaces/traits to declare a contract.

However, the only time where I’m missing code/data reuse through inheritance is with GUI. Some mostly flat hierarchies of widgets are really powerful ways to declare and compose UI components with shared behaviors.

In rust, the DX for GUI components is always lacking compared to web, C#. With maybe the exception of Slint which is really not Rust anymore.

Is there a way to have good DX for GUI components in Rust?


Replies

aabhaytoday at 8:21 AM

If you want to get inspired by good component DX, try looking at Bevy, the game engine.

But essentially it comes down to traits, newtypes/enum variants, and macros.

show 1 reply
ameliustoday at 11:31 AM

Rust is great for acyclic data structures, but ... in a GUI you always have closures that point back to the widgets they were created for. That's one reason you should probably not use Rust for GUIs and similar problem areas.

show 1 reply
h4x0rrtoday at 9:47 AM

Isn't composition (react style) better for GUIs anyways?

show 1 reply