cheonjaeung / gridlayout-compose

Missing non lazy grid layout for Compose Multiplatform.
https://cheonjaeung.github.io/gridlayout-compose
Apache License 2.0
46 stars 4 forks source link

Getting actual cell count for SimpleGridCells.Adaptive #26

Open zakgof opened 1 month ago

zakgof commented 1 month ago

When SimpleGridCells.Adaptive is used, is there any API to get the actual number of cells?

cheonjaeung commented 1 month ago

Hi, @zakgof!

Currently there is no official API to get actual number of cells when using Adaptive. But I think SimpleGridCells's Density.calculateCrossAxisCellSizes method will be helpful. This method is for internal but it is public interface method. So, you can use it as long as the interface is changed.

The method API looks like below,

fun Density.calculateCrossAxisCellSizes(availableSize: Int, spacing: Int): List<Int>

The availableSize is the actual usable size of grid layout. And the spacing is spacing size between cells. You can get spacing from Arrangement.spacing property. calculateCrossAxisCellSizes returns list of size of each cells. The length of the list is the cell count.

For finding real usage, you can find rememberColumnCellWidthConstraints or rememberRowCellHeightConstraints from source.