slint icon indicating copy to clipboard operation
slint copied to clipboard

Support for conditional children wrappers

Open lmaxyz opened this issue 1 year ago • 3 comments

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

component MyComponent {
    if condition : some_id := CustomWrapper {
        @children
    } else : VerticalLayout {
        @children
    }
}

lmaxyz avatar Sep 27 '24 13:09 lmaxyz

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.

Enyium avatar Sep 27 '24 16:09 Enyium

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

ogoffart avatar Oct 01 '24 06:10 ogoffart

I've just gotten the error:

The @children placeholder cannot appear in a conditional element

(SlintPad reproduction)

This was in the context of the implementation of a modal that fades out when being closed using opacity, and that shouldn't keep its subtree including @children alive while the modal isn't needed, which would be most of the time. Every modal instance's outermost element would always exist, though.

So, this changing is basically part of the request of this issue.

Enyium avatar Oct 05 '24 17:10 Enyium