slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.1k stars 576 forks source link

Support for conditional children wrappers #6354

Open lmaxyz opened 1 week ago

lmaxyz commented 1 week ago

It would be nice to have possibility to make conditional containers for children.

component MyComponent {
    if condition : some_id := CustomWrapper {
        @children
    } else : VerticalLayout {
        @children
    }
}
Enyium commented 1 week ago

else isn't currently supported in the context of conditional rendering. But - aside from its convenience and redundancy reduction potential - it would be a natural way in a limited local context to guarantee that only one @children is rendered. It's far from the sophistication of Rust's compile-time proofs, but it's a start.

ogoffart commented 3 days ago

Related: https://github.com/slint-ui/slint/issues/6258