Adaptive Layout (WIP)
This commit is contained in:
@@ -47,7 +47,7 @@ fun AdaptiveGameLayout(
|
||||
divider: @Composable () -> Unit = { HorizontalDivider() }
|
||||
) {
|
||||
Layout(
|
||||
contents = listOf(grid, horizontalClues, verticalClues, time, divider),
|
||||
contents = listOf(grid, horizontalClues, verticalClues, time, divider, divider),
|
||||
modifier = modifier
|
||||
) { measurables, constraints ->
|
||||
layout(width = constraints.maxWidth, height = constraints.maxHeight) {
|
||||
@@ -63,6 +63,7 @@ fun AdaptiveGameLayout(
|
||||
|
||||
when (aspectRatio) {
|
||||
PORTRAIT -> {
|
||||
val divider2Measurable = measurables[5][0]
|
||||
portrait(
|
||||
constraints,
|
||||
spacingPx,
|
||||
@@ -70,7 +71,8 @@ fun AdaptiveGameLayout(
|
||||
horizontalCluesMeasurables,
|
||||
verticalCluesMeasurables,
|
||||
timeMeasurable,
|
||||
dividerMeasurable
|
||||
dividerMeasurable,
|
||||
divider2Measurable
|
||||
)
|
||||
}
|
||||
|
||||
@@ -108,17 +110,22 @@ private fun Placeable.PlacementScope.portrait(
|
||||
horizontalCluesMeasurables: List<Measurable>,
|
||||
verticalCluesMeasurables: List<Measurable>,
|
||||
timeMeasurable: Measurable,
|
||||
dividerMeasurable: Measurable
|
||||
divider1Measurable: Measurable,
|
||||
divider2Measurable: Measurable
|
||||
) {
|
||||
val gridSize = constraints.maxWidth
|
||||
val bottomBarHeight = constraints.maxHeight - gridSize - spacingPx
|
||||
val timeWidth = constraints.maxWidth / 10
|
||||
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
||||
|
||||
val gridConstraints = fixed(gridSize, gridSize)
|
||||
val horizontalCluesConstraints = fixed(gridSize, bottomBarHeight / 2)
|
||||
val verticalCluesConstraints =
|
||||
fixed(gridSize - timeWidth - spacingPx, bottomBarHeight / 2)
|
||||
val timeConstraints = fixed(timeWidth, bottomBarHeight / 2)
|
||||
val horizontalCluesConstraints = fixed(
|
||||
width = 3 * gridItemSize + 2 * spacingPx,
|
||||
height = gridItemSize + 2 * spacingPx
|
||||
)
|
||||
val verticalCluesConstraints = fixed(
|
||||
width = gridItemSize + 2 * spacingPx,
|
||||
height = 3 * gridItemSize + 2 * spacingPx
|
||||
)
|
||||
val timeConstraints = Constraints()
|
||||
val dividerConstraints = fixedWidth(gridSize)
|
||||
|
||||
val gridPlaceable = gridMeasurable.measure(gridConstraints)
|
||||
@@ -129,11 +136,14 @@ private fun Placeable.PlacementScope.portrait(
|
||||
it.measure(verticalCluesConstraints)
|
||||
}
|
||||
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
||||
val dividerPlaceable = dividerMeasurable.measure(dividerConstraints)
|
||||
val divider1Placeable = divider1Measurable.measure(dividerConstraints)
|
||||
val divider2Placeable = divider2Measurable.measure(dividerConstraints)
|
||||
|
||||
// Position the grid
|
||||
gridPlaceable.place(0, 0)
|
||||
|
||||
divider1Placeable.place(0, gridSize + spacingPx)
|
||||
|
||||
// Position the horizontal clues
|
||||
val offsetY = placeClues(
|
||||
placeables = horizontalCluesPlaceables,
|
||||
@@ -143,13 +153,13 @@ private fun Placeable.PlacementScope.portrait(
|
||||
)
|
||||
|
||||
// Add divider in between
|
||||
dividerPlaceable.place(gridSize + 3 * spacingPx, offsetY + spacingPx)
|
||||
divider2Placeable.place(0, offsetY + spacingPx)
|
||||
|
||||
// Position the vertical clues
|
||||
placeClues(
|
||||
placeables = verticalCluesPlaceables,
|
||||
offsetX = 0,
|
||||
offsetY = offsetY + 2 * spacingPx + dividerPlaceable.height,
|
||||
offsetY = offsetY + spacingPx + divider2Placeable.height,
|
||||
maxWidth = gridSize
|
||||
)
|
||||
|
||||
@@ -272,7 +282,7 @@ private fun Placeable.PlacementScope.landscape(
|
||||
placeClues(
|
||||
placeables = verticalCluesPlaceables,
|
||||
offsetX = gridSize + 2 * spacingPx,
|
||||
offsetY = offsetY + 2 * spacingPx + dividerPlaceable.height,
|
||||
offsetY = offsetY + spacingPx + dividerPlaceable.height,
|
||||
maxWidth = rightBarWidth
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user