Skip to content

Instantly share code, notes, and snippets.

View material-design-colors-for-compose.kt
import androidx.compose.ui.graphics.Color
// reds
val md_red_50 = Color(0xFFFFEBEE)
val md_red_100 = Color(0xFFFFCDD2)
val md_red_200 = Color(0xFFEF9A9A)
val md_red_300 = Color(0xFFE57373)
val md_red_400 = Color(0xFFEF5350)
val md_red_500 = Color(0xFFF44336)
val md_red_600 = Color(0xFFE53935)
View chess-game-simplified.kt
@Composable
fun Game() {
Column {
Moves()
CapturedPieces(WHITE)
Board()
CapturedPieces(BLACK)
Controls()
}
}
View chess-datapoint-remember.kt
val datapoint = remember(viz, properties) {
viz.dataPointAt(
properties.position,
properties.boardProperties.toState
)
}
View chess-datapoint.kt
@Composable
override fun render(properties: SquareRenderProperties) {
ActiveDatasetVisualisation.current.let { viz ->
val datapoint = viz.dataPointAt(
properties.position,
properties.boardProperties.toState
)
//...
}
View chess-board-with-decorations.kt
@Composable
fun Board(
fromState: GameSnapshotState,
toState: GameSnapshotState,
uiState: UiState,
isFlipped: Boolean = false,
onClick: (Position) -> Unit,
) {
BoxWithConstraints(
modifier = Modifier
View chess-default-renderers.kt
object DefaultSquareRenderer : SquareRenderer {
override val decorations: List<SquareDecoration> =
listOf(
DefaultSquareBackground,
DefaultHighlightSquare,
DefaultSquarePositionLabel,
DatasetVisualiser,
TargetMarks
)
View chess-renderer.kt
interface SquareRenderer {
val decorations: List<SquareDecoration>
}
interface BoardRenderer {
val decorations: List<BoardDecoration>
}
View chess-decorations.kt
interface SquareDecoration {
@Composable
fun render(properties: SquareRenderProperties)
}
interface BoardDecoration {
@Composable
fun render(properties: BoardRenderProperties)
View chess-render-properties.kt
data class SquareRenderProperties(
val position: Position,
val isHighlighted: Boolean,
val clickable: Boolean,
val onClick: () -> Unit,
val isPossibleMoveWithoutCapture: Boolean,
val isPossibleCapture: Boolean,
val boardProperties: BoardRenderProperties
)
View chess-blocked-pieces.kt
override fun dataPointAt(position: Position, state: GameSnapshotState): Datapoint? =
valueAt(position, state)?.let { value ->
Datapoint(
value = value,
label = null,
colorScale = when (value) {
0 -> Color.Red.copy(alpha = 0.35f) to Color.Unspecified
else -> Color.Unspecified to Color.Unspecified
},
)