Minimum Viable Declarative GUI in C++
ossia.io
ossia.io
But also they got harder to implement as UI's got more complex.
This at least is still the case for iOS.
> The objects could be manipulated with InterfaceBuilder and live tested.
Is this anything like the new live previews with Canvas? I've only ever done iOS development but if this is the case that is amazing.
Q1: is it mostly iterating to get precise visuals to get specific behaviours?
Q2: is the toolchain/compiler/webpack turnaround speed a major factor?
If I put any of the example code into a file and run g++ test.cpp -o test -std=c++2a, I get the very expected error, undefined reference to 'main'. Adding main isn't going to magically make a struct turn into a UI. There are no #include statements. It's clear a library is needed as well as some familiarization.
Midway through, a link to Nuklear is provided. At the very bottom, the reader learns this can be tested with the avendish library... a bit after the sentence stating, "Glory to the post-library era."
I still don't know whether the code uses Nuklear or avendish or both, and because there will be more than a few steps to install and this solves a problem I don't have, I lost interest in the examples and will continue to ncurses my way through GUI MVPs.
> By user code, I mean that all the “nice” UI work can be done in, say, foo.hpp: <...> without requiring any custom header. Some yet-unknown .cpp file will include foo.hpp, and, no matter what the content of my_ui is, will execute a nice user interface from it. Anyone will be able to create independent libraries which will render UIs according to whatever platform-specific intricacies there are, but the actual UI code will be entirely independent from anything: peak separation of concerns is achieved.
Regarding:
> the reader learns this can be tested with the avendish library... a bit after the sentence stating, "Glory to the post-library era."
I say that because the UI code itself does not depend on any library: any organization can fairly easily make their own library which will parse these classes however they want. For instance, the code that wraps some of these things to python is in itself ~130 lines: https://github.com/celtera/avendish/blob/main/include/avnd/b... + helpers types for introspection ; the day C++ finally gets reflection most of these helper types can disappear and your actual business code won't have to change at all, unlike if you had written it against $TODAY's gui toolkit and wanted to make it work in $TOMORROW's
Like a DSL but without the “domain specific” part?
I mean, umm… dunno?
Each user can then choose what they want to do with it. For instance, the same code can be put on some embedded chip without any UI processing and will be able to be plugged to hardware pretty easily by writing a few lines of simple glue code.
…which, honestly, horrifies me.
I remember for a time I was adding drag and drop to various parts of blender (Ton went on his yearly vacation and this is what he brought back) and every little change required a rebuild to test which wasn’t the quickest on my little netbook. Mind you there was zero documentation and I was pretty deep in the innerds so there was a lot of trial and error involved. I literally spent most of the time waiting on the compiler because, well, I’m not the best coder out there.
Working on the UI code was a dream in comparison — edit code, reload python module, see changes, rinse and repeat.
yes :-)
> I literally spent most of the time waiting on the compiler
well, it being a tree of plain structs without 200kloc of header files to parse also means that it's possible to implement very fast live-recompilation, like this: https://youtu.be/fMQvsqTDm3k?t=87
Hmm specifying my UI in code is tedious, and porting it to a different framework is impossible! I wonder if I could encode this somehow...
Eureka! I can just specify my code as a data structure! Now it's implementation agnostic!
How can I actually use it though?
I know! All I have to do is write some functions which recursively descend through the UI data structure and make the corresponding calls to the UI framework!
[Writes an interpreter(s) for their data structure]
Congratulations, now you understand the value prop of lisp, and have a poor supplement in C++.
Saying that parsing an AST is on its own a justification for using LISP, is very much like saying that one should use smalltalk or erlang instead of $LANGUAGE every time they implement a message-passing system: at best worth of a shrug. There's a reason why all the projects listed here: https://github.com/celtera/avendish#future-directions are C++ :)
https://forums.4fips.com/viewtopic.php?f=3&t=6896
I ported the code to Lua for a game I'm working on. Could still use some improvements and some live update functionality (should be easy enough to add), but useful for my purposes.
Anonymous:
struct Foo {
struct { int x, y; };
};
Foo foo; do_stuff_with(foo.x);
Unnamed: struct Foo {
struct { int x, y; } child;
};
Foo foo; do_stuff_with(foo.child.x);