From 00c783ffd701053b5bcbbdfaded0fe39857004af Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 9 Jul 2025 22:50:44 +0200 Subject: [PATCH] Adaptive Layout (WIP) --- .../yaep/ui/common/adaptive game layout.kt | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt index 66ef3e0..e7b621c 100644 --- a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt +++ b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt @@ -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, verticalCluesMeasurables: List, 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 )