@Composable
fun MyColumn(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
) {
Layout(
content = content,
modifier = modifier,
) { measurables, constraints ->
val looseConstraints = constraints.copy(
minWidth = 0,
minHeight = 0,
)
val placeables = measurables.map { measurable ->
measurable.measure(looseConstraints)
}
val maxChildWidth = placeables.maxByOrNull { it.width }?.width ?: 0
val height = placeables.sumOf { it.height }
layout(
constraints.maxWidth,
height.coerceAtMost(constraints.maxHeight),
) {
var yPosition = 0
val maxWidth = constraints.maxWidth
placeables.forEach { placeable ->
val deltaX = maxWidth - maxChildWidth + (maxChildWidth - placeable.width) / 2
placeable.place(deltaX, yPosition)
yPosition += placeable.height
}
}
}
}