-
-
Save mukeshsolanki/68583765ce6aa757025ebc569c0ac3b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Controller(onDirectionChange: (Int) -> Unit) { | |
val buttonSize = Modifier.size(size64dp) | |
val currentDirection = remember { mutableStateOf(SnakeDirection.Right) } | |
Column( | |
horizontalAlignment = Alignment.CenterHorizontally, | |
modifier = Modifier.padding(padding24dp) | |
) { | |
AppIconButton(icon = Icons.Default.KeyboardArrowUp) { | |
if (currentDirection.value != SnakeDirection.Down) { | |
onDirectionChange.invoke(SnakeDirection.Up) | |
currentDirection.value = SnakeDirection.Up | |
} | |
} | |
Row { | |
AppIconButton(icon = Icons.Default.KeyboardArrowLeft) { | |
if (currentDirection.value != SnakeDirection.Right) { | |
onDirectionChange.invoke(SnakeDirection.Left) | |
currentDirection.value = SnakeDirection.Left | |
} | |
} | |
Spacer(modifier = buttonSize) | |
AppIconButton(icon = Icons.Default.KeyboardArrowRight) { | |
if (currentDirection.value != SnakeDirection.Left) { | |
onDirectionChange.invoke(SnakeDirection.Right) | |
currentDirection.value = SnakeDirection.Right | |
} | |
} | |
} | |
AppIconButton(icon = Icons.Default.KeyboardArrowDown) { | |
if (currentDirection.value != SnakeDirection.Up) { | |
onDirectionChange.invoke(SnakeDirection.Down) | |
currentDirection.value = SnakeDirection.Down | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment