Hard to believe that UI code in C can look this nice.
This new UI() macro creates ui elements and uses varargs for properties:
UI(.textColor = Color.cyan, .text = s8("Hello"));
Supports nesting:
UI(.backgroundColor = Color.white, .padding=5) {
UI(.text = s8("One"));
UI(.text = s8("Two"));
}
Any item can get input:
UI(.text = s8("Click me")) {
if (ui_input().clicked) doSomething();
}
And you make reusable elements using functions:
void my_row_header(s8 title) {
UI() {
UI(.text = title);
// more stuff
}
}
Everything is laid out with a flexbox-like algorithm (Thanks @nicbarkeragain ). All elements get automatic IDs based on their source location (Thanks @antovsky). And the elements are built in one of two alternating frame arenas (Thanks @rfleury).
This is all just standard C11, no prepass. UI() could be a function instead of a macro, but then I'd lose the auto-id and the default arguments.
I'll be talking more about my ui library when my build profiler launches next week.
No, s8() is just the macro I use to initialize my length-based string type with a c string literal.
No copy is needed for memory lifetime purposes because it’s a static string.
Dynamic strings are created like
.text = ui_fmt(“%i images”, img_count)
The memory for those strings comes from the frame arena which is cleared at the end of each frame.
@Kilada_ManaFold If you’re saying this because you share my enthusiasm for C, then yes, I agree.
If you’re saying this because you think I’m dumb but you actually just misread “UI code” as “UI”…
@TaylorDrif64778 This post was just about the api design, but since you asked about rendering: metal on macOS, DirectX11 on windows, and OpenGL on Linux. I’ll talk more about the ui system in the coming days.
Whether it’s a fat struct or a discriminated union (or whatever) is pretty inconsequential. Under the UI() api interface the underlying system could store the data in any format it wants.
And it’s not purely declarative. You can cache nodes if you want, though I’ve not really found a use for that.
But the user is pressing enter because they want the (now previously) selected thing. Changing the selection and preventing enter still breaks that. Short of never changing the thing that is selected, the only other idea I’ve had is to remember the last selected thing and if it changed in the last 300ms when enter is pressed then open that instead of whatever is currently selected
@annimvs I'm shipping to private users that I manually onboard. This reduces cloner's visibility into what I'm doing, and gets me good feedback in the early stages where every new user has a lot to teach me.
It was with great sadness that I discovered a vibecoded clone of a project I’ve been working on for a year.
HOWEVER…
Has web based UI (mine’s native)
Linux only (mine’s macOS/win/linux)
Less performant
Maybe already abandoned?
Maybe I'll be ok?
@theleastsirius That's nice to hear, but clones aren't entirely a non-issue.
The game "Threes" is a good example: It was released in Feb 2014, one month later it was cloned by "2048". 2048 became substantially more popular.
@RLeRoux64 I am developing in private. I blogged about it to gauge interest (which went viral) but haven't talked about details since. Ironically the cloner based his on what I said in that post, but I've since moved on to better ideas/approaches.