From 145abfe1cabfa50495fd739cbce0d190e49ab1c3 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 11 Jul 2025 16:59:26 +0200 Subject: [PATCH] Adaptive Layout --- .../yaep/ui/common/adaptive game layout.kt | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 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 e7b621c..456c678 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 @@ -145,7 +145,7 @@ private fun Placeable.PlacementScope.portrait( divider1Placeable.place(0, gridSize + spacingPx) // Position the horizontal clues - val offsetY = placeClues( + var offsetY = placeClues( placeables = horizontalCluesPlaceables, offsetX = 0, offsetY = gridSize + 2 * spacingPx, @@ -156,7 +156,7 @@ private fun Placeable.PlacementScope.portrait( divider2Placeable.place(0, offsetY + spacingPx) // Position the vertical clues - placeClues( + offsetY = placeClues( placeables = verticalCluesPlaceables, offsetX = 0, offsetY = offsetY + spacingPx + divider2Placeable.height, @@ -164,10 +164,26 @@ private fun Placeable.PlacementScope.portrait( ) // Position the time - timePlaceable.place( - x = constraints.maxWidth - timePlaceable.width - spacingPx, - y = constraints.maxHeight - timePlaceable.height - ) + val remainingSpace = constraints.maxHeight - offsetY + if (remainingSpace < timePlaceable.height) { + val scale = remainingSpace.toFloat() / timePlaceable.height.toFloat() + if (scale > 0.1f) { + timePlaceable.placeWithLayer( + x = constraints.maxWidth - timePlaceable.width - spacingPx, + y = constraints.maxHeight - timePlaceable.height + ) { + scaleX = scale + scaleY = scale + translationX = (timePlaceable.width * (1 - scale)) / 2f + translationY = (timePlaceable.height * (1 - scale)) / 2f + } + } + } else { + timePlaceable.place( + x = constraints.maxWidth - timePlaceable.width - spacingPx, + y = constraints.maxHeight - timePlaceable.height + ) + } } private fun Placeable.PlacementScope.squarish( @@ -297,8 +313,7 @@ private fun Placeable.PlacementScope.placeClues( placeables: List, offsetX: Int, offsetY: Int, - maxWidth: Int, - minSpacing: Int = 0 + maxWidth: Int ): Int { if (placeables.isEmpty()) return offsetY