Adaptive Layout

This commit is contained in:
Christian Basler
2025-07-11 16:59:26 +02:00
parent 00c783ffd7
commit 145abfe1ca

View File

@@ -145,7 +145,7 @@ private fun Placeable.PlacementScope.portrait(
divider1Placeable.place(0, gridSize + spacingPx) divider1Placeable.place(0, gridSize + spacingPx)
// Position the horizontal clues // Position the horizontal clues
val offsetY = placeClues( var offsetY = placeClues(
placeables = horizontalCluesPlaceables, placeables = horizontalCluesPlaceables,
offsetX = 0, offsetX = 0,
offsetY = gridSize + 2 * spacingPx, offsetY = gridSize + 2 * spacingPx,
@@ -156,7 +156,7 @@ private fun Placeable.PlacementScope.portrait(
divider2Placeable.place(0, offsetY + spacingPx) divider2Placeable.place(0, offsetY + spacingPx)
// Position the vertical clues // Position the vertical clues
placeClues( offsetY = placeClues(
placeables = verticalCluesPlaceables, placeables = verticalCluesPlaceables,
offsetX = 0, offsetX = 0,
offsetY = offsetY + spacingPx + divider2Placeable.height, offsetY = offsetY + spacingPx + divider2Placeable.height,
@@ -164,10 +164,26 @@ private fun Placeable.PlacementScope.portrait(
) )
// Position the time // Position the time
timePlaceable.place( val remainingSpace = constraints.maxHeight - offsetY
x = constraints.maxWidth - timePlaceable.width - spacingPx, if (remainingSpace < timePlaceable.height) {
y = constraints.maxHeight - 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( private fun Placeable.PlacementScope.squarish(
@@ -297,8 +313,7 @@ private fun Placeable.PlacementScope.placeClues(
placeables: List<Placeable>, placeables: List<Placeable>,
offsetX: Int, offsetX: Int,
offsetY: Int, offsetY: Int,
maxWidth: Int, maxWidth: Int
minSpacing: Int = 0
): Int { ): Int {
if (placeables.isEmpty()) return offsetY if (placeables.isEmpty()) return offsetY