Your example would look like this:
export component Hello inherits Rectangle {
in property <string> text: "World";
width: 500px; height: 500px;
background: #505050;
border-width: 1px; border-color: blue;
drop-shadow-blur: 15px; drop-shadow-color: #0008;
VerticalLayout {
alignment: center; spacing: 12px;
Text { text: "Hello, \{root.text}!"; font-size: 20px; color: white; horizontal-alignment: center; }
HorizontalLayout {
alignment: center; spacing: 8px;
for c in [#f00, #0f0, #00f, #ff0, #000, #fff]: Rectangle { width: 32px; height: 32px; background: c; }
}
}
}
More on why we chose a DSL vs code in Rust: https://slint.dev/blog/domain-specific-language-vs-imperativ...[–] c-smile 2 days ago
[–] ivanmontillam 2 days ago
They have no shame in deploying a 300 MB hot mess bundle.
[–] thisismyanon2 2 days ago
Here's a more idiomatic version of the previous example. IME gpui (and iced) is a lot easier to extend than something with a DSL, and if you check out the gpui example you'll see that gpui provides convenient methods to get consistent styles vs the Slint example where you hardcode widths and sizes. Those hex color abbreviations give me a facial tic every single time.
use gpui::{black,red,green,blue,yellow,white};
let Self{text,..} = self;
v_flex()
.gap_3()
.bg(rgb(0x505050))
.size(px(500.0))
.justify_center()
.items_center()
.shadow_lg()
.border_1()
.border_color(black())
.text_xl()
.text_color(white())
.child(format!("Hello, {text}!"))
.child(
h_flex()
.gap_2()
.children(
[red(), green(), blue(), yellow(), black(), white()].map(|color|
div().size_8().bg(color)
)))[–] MisterMunchkin 2 days ago
[–] ogoffart 2 days ago
Btw, a rug pull can happen under even the most permissive licenses. As we've seen in the past with some project changing license or direction. That's more or less already happened with GPUI when Zed refocused development on its own needs rather than other GPUI users resulting in several forks.
[–] IshKebab 2 days ago
It even added ANSI colour support... which I am still on the fence about but it did make the very good point that it means the logging is exactly the same in GUI and CLI mode.
That's is not about just Rust ... Any domain has its own optimal or sub-optimal language describing it. Criteria of optimality is a bit subjective of course. Like: INI, TOML, YAML, etc. are better (YMMV, again) for user facing configs than JSON or XML and so on.
I think that HTML is better for defining hierarchical UI structures and CSS and CSS selectors are (arguably again) better to define UI styling.
My Sciter[1] was initially using .FRM alike inputs (VisualBasic forms, good for IDE but bad for a human) but I quickly discovered that having styles, structure and code-behind-UI in single PL makes non-manageable mess. So Sciter uses HTML, CSS and JS we all familiar with. Not 100% match of course but good enough.
[1] https://sciter.com