slint
slint copied to clipboard
Add support for `for` and `if` in `GridLayout`
After #349 outlined that there were build errors - and those are fixed now - it would still be desirable to use if and for in grid layouts.
Some implementation instructions are in https://github.com/sixtyfpsui/sixtyfps/discussions/574#discussioncomment-1475441
We need to find a behavior of what happens to column and row detection when there is a if or a for.
for a if it could simply be like for a normal item which would just be hidden when false.
for a for we could force them to be a single row (or a single column?).
I can think of four different ways of writing a "dynamic" grid layout:
- Create a variable number of rows:
GridLayout {
for item in model: Row {
// ...
}
}
- Create a variable number of columns:
GridLayout {
Row {
for item in model: Column {
// ...
}
}
}
- Create a variable number of columns:
GridLayout {
for item in model: Rectangle {
// ...
}
}
- Mad-max:
GridLayout {
for item[i] in model: Rectangle {
row: i / 4;
col: mod(i, 4);
}
}
I guess (1)-(3) are special cases of (4), but is it even possible to implement that?
Would it be possible to have a StaticGridLayout with a fixed num_rows and num_cols which accepts for loops?
Would it be possible to have a StaticGridLayout with a fixed num_rows and num_cols which accepts for loops?
Yeah, i think this would make sense to have these properties in the GridLayout. we would also need a flow-direction property then.
Another solution would be to add a support for wrapping to HorizontalLayout and VerticalLayout (à la flex-wrap in css).
Has there been any progress on this one? What is a possible workaround?
Right now, the workaround is to use HorizontalLayout in VerticalLayout. Or to do the layouting "manually" using x, y bindings
I'm sorry, I would like to know if there are other dynamic methods with better performance than using for in Rectangle? Or, could you tell me what the current best method is for dynamically drawing grids?
I'm sorry, I would like to know if there are other dynamic methods with better performance than using
forinRectangle? Or, could you tell me what the current best method is for dynamically drawing grids?
Would love that too, thanks!