slint-ui / slint

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

Syntax for repeated elements and conditional elements #1873

Closed ogoffart closed 1 year ago

ogoffart commented 1 year ago

Currently

for tile[i] in memory-tiles: MemoryTile {
   // ...      
}

if foo.some-conditoin : SomeElement {
}

It was suggested in https://github.com/slint-ui/slint/discussions/1818#discussioncomment-4182871 to add brace to extand for more elements:

for tile[i] in memory-tiles {
        MemoryTile {
            // ...
        }
        // potentially more elements
    }
}

if foo.some-condition {
    SomeElement {
    }
    SomeOtherElement {
    }
}

It is assumed that this new scope is not in iteself an element, and when used in layout or other components that do something with their direct children the sub-element are considered direct children.

Unresolved questions:

ogoffart commented 1 year ago

Example of code which would benefit of condition with several elements: https://github.com/slint-ui/slint/blob/85df47966e0e1a36c7a0de83b0c0bbd1d582391a/examples/printerdemo/ui/printer_queue.slint#L184

tronical commented 1 year ago

Whether or not to allow multiple elements is another decision in itself that we could take. We could also say that only one child is allowed, in the event that we can't come up with clear semantics yet for multiple.