loloof64
11/25/2020, 7:50 PM@Composable
fun GameScreen(topLevelNavController: NavController) {
GameScreenTheme {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
stringResource(id = R.string.game_page),
)
},
navigationIcon = {
IconButton(onClick = {
topLevelNavController.popBackStack()
}) {
Icon(Icons.Filled.ArrowBack)
}
}
)
},
) {
// Is there a way to get available width and height ?
}
}
}
Bradleycorn
11/25/2020, 7:53 PMAdam Powell
11/25/2020, 7:57 PMWithConstraints
composable defers composition of its contents until layout time when the sizing constraints are available, and you can compose different UI depending on the size. This is a bit expensive, but it's often the right way to do certain kinds of responsive UIs.loloof64
11/25/2020, 8:05 PMAdam Powell
11/25/2020, 8:07 PMModifier.aspectRatio(1f)
thenWithConstraints
is way overkill for that 🙂loloof64
11/25/2020, 8:09 PMAdam Powell
11/25/2020, 8:10 PMloloof64
11/25/2020, 8:10 PM{
Column(
modifier = Modifier.fillMaxSize().aspectRatio(1f)
) {
StaticChessBoard(size = 300.dp)
}
}
Column(
modifier = Modifier.fillMaxSize().aspectRatio(1f)
) {
WithConstraints {
val availableWidth = with(DensityAmbient.current) {constraints.maxWidth.toDp()}
val availableHeight = with(DensityAmbient.current) {constraints.maxHeight.toDp()}
val minSize = if (availableWidth < availableHeight) availableWidth else availableHeight
StaticChessBoard(size = minSize)
}
}
Andrey Kulikov
11/25/2020, 8:29 PMAdam Powell
11/25/2020, 8:30 PMWithConstraints
down into the part of your code where you need to do font sizing rather than forcing StaticChessBoard
to accept a size as a parameterModifier.aspectRatio
for calling StaticChessBoard
loloof64
11/25/2020, 8:37 PMAdam Powell
11/25/2020, 8:39 PMloloof64
11/25/2020, 8:41 PM