So I am trying to create a Chess Board using JetPack compose & have managed to draw the layout a bit. But, Now I have issue that I want the board square to have a equal height as width. I want it to be perfect square.
Note: I don't want to give any fix width or height. I want to fit squares in the screens width & then each squares' height should be as much as the width.
What I have tried:
@ExperimentalFoundationApi
class PlayGameActivity : BaseActivity() {
val darkSquare = Color(0xFF779556)
val lightSquare = Color(0xFFEBECD0)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Column {
Board()
}
}
}
@Composable
fun Board() {
Column {
for (i in 0 until 8) {
Row {
for (j in 0 until 8) {
val isLightSquare = i % 2 == j % 2
val squareColor = if (isLightSquare) lightSquare else darkSquare
Box(
modifier = Modifier
.weight(1f)
.background(squareColor)
) {
Text(text = "${i + j}")
}
}
}
}
}
}
}
It gives me following result.
What I expect it to look like:
Any Idea how I can calculate width & set it same as width of the square?