Skip to content

Instantly share code, notes, and snippets.

@landarskiy
Created December 17, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save landarskiy/780cd8b4f1bc77c99e2c380aed834673 to your computer and use it in GitHub Desktop.
Save landarskiy/780cd8b4f1bc77c99e2c380aed834673 to your computer and use it in GitHub Desktop.
@Composable
public fun GridPad(
cells: GridPadCells, modifier: Modifier = Modifier, content: GridPadScope.() -> Unit
) {
val scopeContent: GridPadScopeImpl = GridPadScopeImpl(cells).apply(content)
Layout(modifier = modifier, content = {
scopeContent.data.forEach {
it.item(GridPadItemScopeImpl)
}
}) { measurables, constraints ->
// ...
val placeables = measurables.mapIndexed { index, measurable ->
// ...
}
//define component size
layout(layoutWidth, layoutHeight) {
placeables.forEachIndexed { index, placeable ->
val contentMetaInfo = scopeContent.data[index]
val cellPlaceInfo = cellPlaces[contentMetaInfo.row][contentMetaInfo.column]
// placement the item in the desired location
placeable.placeRelative(x = cellPlaceInfo.x, y = cellPlaceInfo.y)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment