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)
// 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<Placeable>,
offsetX: Int,
offsetY: Int,
maxWidth: Int,
minSpacing: Int = 0
maxWidth: Int
): Int {
if (placeables.isEmpty()) return offsetY