Consider the following Composable:
setContent {
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(fontSize = 30.sp, text = "Hello")
Box {
Canvas(
modifier = Modifier
.size(100.dp)
) {
drawRect(Color.Red)
}
}
}
}
If we add a rotation()
modifier on the Canvas
, the square is drawn on top of the other Text
element.
setContent {
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(fontSize = 30.sp, text = "Hello")
Box {
Canvas(
modifier = Modifier
.size(100.dp)
.rotate(45f)
) {
drawRect(Color.Red)
}
}
}
}
I understand this is because the transformation append in the drawing phase, after everything has been sized.
If we want the column to adjust to this, we have to add a padding to the box:
setContent {
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(fontSize = 30.sp, text = "Hello")
Box(
modifier = Modifier
.padding(21.dp)
) {
Canvas(
modifier = Modifier
.size(100.dp)
.rotate(45f)
) {
drawRect(Color.Red)
}
}
}
}
My problem is that this padding have to be calculated by taking into account the transformed foot print.
Is there something like Modifier.wrapContentSize()
(which is not working here) or another way of arranging things that could provide this result?