Skip to content

Commit

Permalink
cleanup layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjlockwood committed Oct 20, 2024
1 parent 57665d3 commit f587531
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ private class AnimateGridTilePlacementNode(
override fun MeasureScope.measure(measurable: Measurable, constraints: Constraints): MeasureResult {
val placeable = measurable.measure(constraints)
return layout(placeable.width, placeable.height) {
placeable.placeWithLayer(
x = 0,
y = 0,
) {
placeable.placeWithLayer(x = 0, y = 0) {
scaleX = animatedScale.value
scaleY = animatedScale.value
translationX = animatedOffset.value.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,26 @@ fun GameLayout(
bestScoreText: @Composable (() -> Unit),
bestScoreLabel: @Composable (() -> Unit),
modifier: Modifier = Modifier,
padding: Dp = 16.dp,
) {
val gameGrid = remember(gameGrid) { movableContentOf(gameGrid) }
val currentScoreText = remember(currentScoreText) { movableContentOf(currentScoreText) }
val currentScoreLabel = remember(currentScoreLabel) { movableContentOf(currentScoreLabel) }
val bestScoreText = remember(bestScoreText) { movableContentOf(bestScoreText) }
val bestScoreLabel = remember(bestScoreLabel) { movableContentOf(bestScoreLabel) }

BoxWithConstraints(modifier = modifier) {
val isPortrait = maxWidth < maxHeight
val gridSize = min(maxWidth, maxHeight).coerceAtMost(600.dp) - padding * 2
val gridSize = min(maxWidth, maxHeight).coerceAtMost(GameGridMaxWidth) - GameGridPadding * 2

if (isPortrait) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(padding),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
Box(
modifier = Modifier
.padding(start = padding, top = padding, end = padding)
.padding(vertical = 16.dp)
.padding(start = 16.dp)
.fillMaxWidth(),
contentAlignment = Alignment.Center,
) {
Expand All @@ -57,7 +58,7 @@ fun GameLayout(

Row(
modifier = Modifier
.padding(start = padding, end = padding)
.padding(horizontal = 16.dp)
.width(gridSize)
.align(Alignment.CenterHorizontally),
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -66,6 +67,7 @@ fun GameLayout(
currentScoreText()
currentScoreLabel()
}

Column(horizontalAlignment = Alignment.End) {
bestScoreText()
bestScoreLabel()
Expand All @@ -74,23 +76,25 @@ fun GameLayout(
}
} else {
Row(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize(),
horizontalArrangement = Arrangement.Center,
) {
Box(
modifier = Modifier
.padding(start = padding, top = padding, bottom = padding)
.fillMaxHeight(),
.fillMaxHeight()
.padding(vertical = 16.dp)
.padding(start = 16.dp),
contentAlignment = Alignment.Center,
) {
gameGrid(gridSize)
}

Spacer(Modifier.width(padding))
Spacer(Modifier.width(16.dp))

Column(
modifier = Modifier
.padding(top = padding, bottom = padding)
.padding(vertical = 16.dp)
.height(gridSize)
.align(Alignment.CenterVertically),
verticalArrangement = Arrangement.Bottom,
Expand All @@ -105,3 +109,6 @@ fun GameLayout(
}
}
}

private val GameGridMaxWidth = 600.dp
private val GameGridPadding = 16.dp
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ private val KeyEvent.direction: Direction?
else -> null
}

/**
* Returns true if the platform should support moves via touch gestures.
*/
internal expect fun shouldDetectSwipes(): Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import net.harawata.appdirs.AppDirsFactory
import okio.FileSystem
import okio.Path.Companion.toPath

private const val PACKAGE_NAME = "com.alexjlockwood.twentyfortyeightcompose"
private const val PACKAGE_NAME = "com.alexjlockwood.twentyfortyeight"
private const val VERSION = "1.0.0"
private const val AUTHOR = "alexjlockwood"

Expand All @@ -23,8 +23,6 @@ fun main() = application {
onCloseRequest = ::exitApplication,
title = "2048",
) {
App(
repository = GameRepository(store),
)
App(repository = GameRepository(store))
}
}
Binary file not shown.

0 comments on commit f587531

Please sign in to comment.