r/cpp • • 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.

43 Upvotes

25 comments sorted by

View all comments

Show parent comment

0

u/germandiago Mar 20 '26

Yes and it looks like a nightmare for anything other than 'textbox with button' guis. I couldn't even comprehend what their basic example was trying to tell me, and I maintain guis for a living.

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.

Because its standardized and the compiler and any IDE under the sun is going to understand it and be able to traverse it very easily, give you hints and summarize functions and so forth for you, and autocomplete will work well out of the box

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.

GUIs are inherently coupled, though, so you almost always have to end up searching for a field.

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.

Then how do you search for them dynamically?

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.

At least Qt lets you compile your ui files into headers that the IDE can understand

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.

At least Qt lets you compile your ui files into headers that the IDE can understand

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.

3

u/UnicycleBloke Mar 20 '26

> As a person that has tried everything (but I do not do GUIs for a living

I did so for over ten years. Widgets are easier to understand and maintain.

I haven't done a ton of Android development, but found it simple enough when I worked on a project some years ago. I was impressed by Android Studio. More recently, I had occasion to look into Jetpack Compose after a long absence from Android. It was baffling. I completely understand a hierarchy of objects which I have explicitly created. This composable function malarkey feels like I'm hapless flotsam trapped in a morass of what some CS theorist thinks code should look like. No. Just no.