Travis Griggs
02/01/2024, 7:45 PMTravis Griggs
02/01/2024, 7:50 PM.constrainAs(textRef) {
absoluteLeft.linkTo(labelRef.absoluteRight)
absoluteRight.linkTo(buttonRef.absoluteLeft)
centerTo(parent)
}
it doesn't seem to center, just centers between the uneven width edge widgetsbrandonmcansh
02/01/2024, 8:34 PMshikasd
02/01/2024, 9:20 PMRow {
Icon()
Box(Modifier.weight(1f)) {
Text(...)
}
Icon()
}
shikasd
02/01/2024, 9:28 PMbrandonmcansh
02/01/2024, 9:43 PMTravis Griggs
02/01/2024, 10:25 PMBen Trengrove [G]
02/01/2024, 10:36 PMTravis Griggs
02/01/2024, 11:03 PMTravis Griggs
02/01/2024, 11:28 PMLayout(content = {
SettingsLabel(
text_id = R.string.mcHostSettingsCard_name
)
Text(
text = mc.name ?: "", ..., textAlign = TextAlign.Center
)
CircleButton(icon_id = R.drawable.screwdriver_in_circle_mask, onClick = { isEditing = NOT(isEditing) })
}, modifier = modifier) { measurables, constraints ->
val (labelPlaceable, textPlaceable, buttonPlaceable) = measurables.map { measurable -> measurable.measure(constraints) }
val maxInset = maxOf(labelPlaceable.width, buttonPlaceable.width)
layout(constraints.maxWidth, constraints.maxHeight) {
val width = constraints.maxWidth
val height = constraints.maxHeight
labelPlaceable.place(0, (height - labelPlaceable.height) / 2)
textPlaceable.place(maxInset, (height - textPlaceable.height) / 2)
buttonPlaceable.place(width - buttonPlaceable.width, (height - buttonPlaceable.height) / 2)
}
}
would get me in the ballpark at least. But logging some of the points, my maxInset ends up being the screen width. I'm interested in the intrinsic widths (I think?) of the first and last placeables. But getting something very different. It's not clear to me how one sets the width of the middle placeable either, seems I can place it, but not adjust its width 😕Travis Griggs
02/01/2024, 11:56 PMTravis Griggs
02/02/2024, 12:04 AM{ (labelMeasure, textMeasure, buttonMeasure), constraints ->
val labelPlacer = labelMeasure.measure(constraints.copy(minWidth = 0))
val buttonPlacer = buttonMeasure.measure(constraints.copy(minWidth = 0))
val maxInset = maxOf(labelPlacer.measuredWidth, buttonPlacer.measuredWidth)
val textWidth = constraints.maxWidth - maxInset - maxInset
val textPlacer = textMeasure.measure(constraints.copy(minWidth = textWidth))
val maxHeight = listOf(labelPlacer, textPlacer, buttonPlacer).maxOf { p -> p.height }
layout(constraints.maxWidth, maxHeight) {
val width = constraints.maxWidth
labelPlacer.place(0, (maxHeight - labelPlacer.height) / 2)
textPlacer.place(maxInset, (maxHeight - textPlacer.height) / 2)
buttonPlacer.place(width - buttonPlacer.width, (maxHeight - buttonPlacer.height) / 2)
}