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