I'm using a LazyVerticalGrid to show a bunch of cards, but I want to fill the "empty" slots in the last row (if any) to have a dummy element. How would I set this up?
a
ascii
09/08/2023, 4:39 PM
It's just a bit of math really.
N = number of items
C = number of columns (you'd know this if you use
GridCells.Fixed
, otherwise can be calculated via screen width)
F = fraction;
(N / C) % 1
R = remaining;
C - floor(F * C)
e.g. N = 5, C = 3
F = 0.67
R = 3 - 2 => you need to draw 1 empty item
m
martmists
09/08/2023, 5:50 PM
How would I get the screen width in Compose for Web?
a
ascii
09/08/2023, 5:59 PM
There must be some native delegate, otherwise use
BoxWithConstraints
a
Andrey Kulikov
09/12/2023, 11:28 AM
you can implement GridCells interface directly instead of using GridCells.Fixed. In this interface you get the available size and returning the sizes for the cells