Skip to content

Instantly share code, notes, and snippets.

@landarskiy
Created December 17, 2022 10:29
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/36baab8bb3d4e260fde1e249c8a065c7 to your computer and use it in GitHub Desktop.
Save landarskiy/36baab8bb3d4e260fde1e249c8a065c7 to your computer and use it in GitHub Desktop.
internal class GridPadScopeImpl(private val cells: GridPadCells) : GridPadScope {
// list of composables to future measurement and placement
internal val data: MutableList<GridPadContent> = mutableListOf()
override fun item(
row: Int?, column: Int?, rowSpan: Int, columnSpan: Int,
itemContent: @Composable GridPadItemScope.() -> Unit
) {
findPlaceForContent(
row = row, column = column, rowSpan = rowSpan, columnSpan = columnSpan
) { cellRow, cellColumn ->
this.data.add(
GridPadContent(
row = cellRow,
column = cellColumn,
rowSpan = rowSpan,
columnSpan = columnSpan,
item = { itemContent() }
)
)
}
}
private fun findPlaceForContent(
row: Int?, column: Int?, rowSpan: Int, columnSpan: Int,
callback: (row: Int, column: Int) -> Unit
): Boolean {
// some logic for locating in the grid in cases where no row or column is specified
}
}
internal class GridPadContent(
val row: Int, val column: Int, val rowSpan: Int, val columnSpan: Int,
val item: @Composable GridPadItemScope.() -> Unit
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment