r/cpp • u/germandiago • Mar 19 '26
Modern declarative EDSL for graphic user interface in C++? Not QML or XAML.
Hello everyone,
I have been investigating lately (after using NiceGUI for a real project) and learning Jetpack Compose (not writing any real code with it, would do it with Jetpack Multiplatform if ever).
I am really impressed by Jetpack Compose approach, especially UDF.
I thought there could possibly not be a better way than MVVM tbh, after using it for years.
But after seeing how declarative composition inside the language, not with XAML or QML can be done, I am sold in the amount of boilerplate that can be saved, plus the better integration when the dsl is in the host language.
So I wanted to mention I found this, which I think could be a good start for some experiments, on top of wxWidgets: https://github.com/rmpowell77/wxUI
I think it has a talk in CppCon2025 here: https://www.youtube.com/watch?v=xu4pI72zlO4
Kudos to the author for bringing something like this to C++! Definitely useful.
I would like to hear your opinions on this style of EDSL GUI embedding and pros/cons you find for those of you who do GUI programming all the time.
Also, wild idea: with the power of compile-time C++ programming and C++26 reflection, it would be possible to get existing xaml interfaces and convert it into regular C++ at compile-time via #embed or #include and not even changing the EDSL itself and making it directly embedded and reusable in C++? That would be plenty useful.
View all comments
Show parent comment
0
u/germandiago Mar 20 '26
As a person that has tried everything (but I do not do GUIs for a living, so take it with a grain of salt) from MVC to MVVM, MVP, etc. I would say that what Jepack Compose does is quite neat.
Basically an EDSL will generate those widgets (through it is kind of an "expression template" in C++. It is not the widget directly, but I do not see why you could not have some function to unfold and inspect or generate code directly from the declarative part. I would say it is as if you used a RAD editor, but embedded in the code (and without drag and drop, of course) but without the headache of having to identify every widget for which you want to make it do things 90% of the time: you just add the callbacks/bindings directly in the declarative DSL, which reduces boilterplate a lot.
I am not completely sure of this. I mean, in some way, yes, but you can abstract it to some extent and in my experience that abstraction (for example using a callback at the function factory level) lets you decouple, for example a binding with a name. The key is that you can have "pieces of UI" in functions with callbacks and configuration at the top and refresh (just like Jetpack Compose does). I find this to be easier to follow than other alternatives. I would say second easiest is MVVM. Even MVVM is good for not so complex cases where you have a form or something that is just bind variables to widgets. When sources come from network and other places then things start to get more complex though.
This is not a challenge, but something to understand better since I do not do GUIs all day long: where do you need to find other widgets directly with no alternative designs? I try to avoid that and so far I cannot think of UIs where you need to reach another widget directly. What I would reach is state or a callback to inform of a change, without mentioning the widget itself and propagation of some kind should do the rest.
wxFormBuilder also generates C++ code for you and you can refer to it directly. It works pretty well, but I am not sure it is the way it should be done bc it promotes this coupling I was talking about.
Interesting. If you could talk more about it (and you are allowed to do so) it would be great to hear of it, to let my imagination fly and see how I would do it or if it is just that the better or only way is the way you say.