I'm using a LazyVerticalGrid to show a bunch of ca...
# compose
m
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
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
How would I get the screen width in Compose for Web?
a
There must be some native delegate, otherwise use
BoxWithConstraints
a
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