Skip to content

Commit

Permalink
cleanup multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjlockwood committed Oct 20, 2024
1 parent a884d5d commit 15ec697
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 107 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -21,7 +23,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.KeyEventType
Expand All @@ -40,6 +41,7 @@ import kotlin.math.atan2
/**
* Renders the 2048 game's home screen UI.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun GameUi(
gridTileMovements: List<GridTileMovement>,
Expand Down Expand Up @@ -79,16 +81,23 @@ fun GameUi(
.focusRequester(focusRequester)
.focusable(),
topBar = {
GameTopAppBar(
title = { Text("2048") },
contentColor = Color.White,
backgroundColor = MaterialTheme.colorScheme.secondary,
actions = {
IconButton(onClick = { shouldShowNewGameDialog = true }) {
Icon(Icons.Filled.Add, contentDescription = null)
}
},
)
val title = @Composable { Text("2048") }
val actions = @Composable {
IconButton(onClick = { shouldShowNewGameDialog = true }) {
Icon(Icons.Filled.Add, contentDescription = null)
}
}
if (shouldCenterAlignTopAppBar()) {
CenterAlignedTopAppBar(
title = title,
actions = { actions() },
)
} else {
TopAppBar(
title = title,
actions = { actions() },
)
}
},
) { innerPadding ->
GameLayout(
Expand Down Expand Up @@ -166,15 +175,20 @@ private fun TextLabel(
}

private val KeyEvent.direction: Direction?
get() = when {
key == Key.DirectionUp || key == Key.W -> Direction.NORTH
key == Key.DirectionLeft || key == Key.A -> Direction.WEST
key == Key.DirectionDown || key == Key.S -> Direction.SOUTH
key == Key.DirectionRight || key == Key.D -> Direction.EAST
get() = when (key) {
Key.DirectionUp, Key.W -> Direction.NORTH
Key.DirectionLeft, Key.A -> Direction.WEST
Key.DirectionDown, Key.S -> Direction.SOUTH
Key.DirectionRight, Key.D -> Direction.EAST
else -> null
}

/**
* Returns true if the platform should support moves via touch gestures.
*/
internal expect fun shouldDetectSwipes(): Boolean

/**
* Returns true if the top app bar should be center aligned.
*/
internal expect fun shouldCenterAlignTopAppBar(): Boolean

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ package com.alexjlockwood.twentyfortyeight.ui
internal actual fun shouldDetectSwipes(): Boolean {
return true
}

internal actual fun shouldCenterAlignTopAppBar(): Boolean {
return true
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.alexjlockwood.twentyfortyeight.ui

internal actual fun shouldCenterAlignTopAppBar(): Boolean {
return false
}

0 comments on commit 15ec697

Please sign in to comment.