slint icon indicating copy to clipboard operation
slint copied to clipboard

Add support for `for` and `if` in `GridLayout`

Open tronical opened this issue 4 years ago • 11 comments
trafficstars

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.

tronical avatar Jul 28 '21 15:07 tronical

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?).

ogoffart avatar Oct 19 '21 08:10 ogoffart

I can think of four different ways of writing a "dynamic" grid layout:

  1. Create a variable number of rows:
GridLayout {
    for item in model: Row {
        // ...
    }
}
  1. Create a variable number of columns:
GridLayout {
    Row {
        for item in model: Column {
            // ...
        }
    }
}
  1. Create a variable number of columns:
GridLayout {
    for item in model: Rectangle {
        // ...
    }
}
  1. 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?

tronical avatar Oct 19 '21 08:10 tronical

Would it be possible to have a StaticGridLayout with a fixed num_rows and num_cols which accepts for loops?

FlorentBecker avatar Apr 12 '22 15:04 FlorentBecker

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.

ogoffart avatar Apr 13 '22 08:04 ogoffart

Another solution would be to add a support for wrapping to HorizontalLayout and VerticalLayout (à la flex-wrap in css).

FlorentBecker avatar May 05 '22 12:05 FlorentBecker

Has there been any progress on this one? What is a possible workaround?

Tastaturtaste avatar Jun 23 '23 09:06 Tastaturtaste

Right now, the workaround is to use HorizontalLayout in VerticalLayout. Or to do the layouting "manually" using x, y bindings

ogoffart avatar Jun 23 '23 12:06 ogoffart

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?

coufxr avatar Jan 29 '24 15:01 coufxr

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?

Would love that too, thanks!

petrostrak avatar Feb 27 '24 15:02 petrostrak