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.
7
u/Electronic_Tap_8052 Mar 19 '26
why do people like declarative guis? I find that they are much more boilerplate than simply creating widgets within c++. Anyone who's ever had to dig into a large QML or other type of declaration file probably knows what I'm talking about. It is also much harder to find out what any particular widget actually does. Once you start adding functionality, signals and slots and so forth, it becomes a real nightmare and your code is spread out over a lot of places, and you can't just ctrl+click to see what something does, like if you were using a real IDE. They promise a lot of benefits but they rarely deliver, and it seems to me that the target audience is former web devs who are used to CSS.
For all the but the simplest of guis, plain old c++ is almost always the more robust and maintainable solution. With a proper layout engine, you don't even need to (and should not) size widgets. I say this as someone who's job it is to maintain guis written by other people who have moved on.
6
u/willdieh Mar 19 '26 edited Mar 19 '26
When C++/WinRT first came out, I made a declarative UI by calling the WinRT XAML layout and control/widget object functions directly. This was because using WinRT in a pure Win32 app didn't (and still doesn't?) support the XAML editor so there wasn't any graphical way to do this.
It worked well but I eventually just gave up and went back to regular Win32 as it was too difficult to get it working properly once WinUI 3 came along without switching to their new packaged application format. Ugh.
3
u/ts826848 Mar 19 '26
I'm not familiar enough with C++26's reflection to say doing such a thing is outright impossible, but I think P3294 Code Injection with Token Sequences would make doing that easier. That paper proposes functionality allow you to inject arbitrary token sequences a la Lisp/Swift/Rust macros, which based on the examples in the paper seems like it'd be simpler on the generation side.
Unfortunately that paper didn't make it into C++26, but IIRC it was removed relatively late in the process for lack of time so I think there's a pretty good chance it'll make it into C++29.
1
u/d86leader Mar 19 '26
I'm not sure DSLs that translate into existing widgets or toolkits are a good idea. In theory there could be one that is safe and sound, but in practice they always miss corner cases, leak the underlying abstractions, and add magic that is hard to debug.
One modern EDSL that is used in a graphical toolkit created specifically around it is https://docs.slint.dev/latest/docs/cpp/ - I like the language itself a lot, but there is a slight problem of it being too young and lacking community libraries and styles
-1
u/VictoryMotel Mar 20 '26
I know you think you want this, but you don't. Adding a markup language that stands between you and your GUI parameters just to lay out company is only going to end in tears.
Laying out components is very easy and not the difficulty of a GUI. If anything getting it to compile and link is the hardest part.
Try fltk, super simple, small robust, great documentation and faster than anything else.
-2
u/Copronymus09 Mar 20 '26
C++ should stay as a backend language, all of this innovation would be a waste of time.
We don't even have the basics of package management done well, compilers are lagging behind the standard by 3-4 years.
Chances are when developing something like this you would fall to qt's approach of doing everything by yourself, and that is very counterproductive.