-
-
Save landarskiy/863c620989fa14639ca37e69e31eeba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 cellPlaces = calculateCellPlaces(cells, width = constraints.maxWidth, height = constraints.maxHeight) | |
// list of measured children | |
val placeables = measurables.mapIndexed { index, measurable -> | |
val contentMetaInfo = scopeContent.data[index] | |
// calculate the actual maximum cell width in pixels based on the span size | |
val maxWidth = (0 until contentMetaInfo.columnSpan).sumOf { | |
cellPlaces[contentMetaInfo.row][contentMetaInfo.column + it].width | |
} | |
// calculate the actual maximum cell height in pixels based on the span size | |
val maxHeight = (0 until contentMetaInfo.rowSpan).sumOf { | |
cellPlaces[contentMetaInfo.row + it][contentMetaInfo.column].height | |
} | |
// measurement of children with cell boundary constraints, not the parent | |
measurable.measure( | |
constraints.copy( | |
minWidth = min(constraints.minWidth, maxWidth), | |
maxWidth = maxWidth, | |
minHeight = min(constraints.minHeight, maxHeight), | |
maxHeight = maxHeight | |
) | |
) | |
} | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment