nuhkoca
06/14/2022, 10:58 AMplaceables using custom layout? In my case, button overlaps other items but I would expect other components to get smaller as much as button gets wider. Code in the 🧵nuhkoca
06/14/2022, 10:59 AMlayout(constraints.maxWidth, height) {
titlePlaceable.placeRelative(x = 0, y = iconPlaceable.height / 2 - titlePlaceable.height / 2)
iconPlaceable.placeRelative(x = titlePlaceable.width, y = 0)
performancePlaceable.placeRelative(
x = 0,
y = iconPlaceable.height / 2 + titlePlaceable.height / 2 + titleBottomSpacing
)
followButtonPlaceable.placeRelative(
x = constraints.maxWidth - followButtonPlaceable.width,
y = (contentHeight - followButtonPlaceable.height) / 2
)
}Filip Wiesner
06/14/2022, 11:00 AMis it possible to limit width ofNot of placeables butplaceables
mearurable s. You have to constraint them in measure phasenuhkoca
06/14/2022, 11:02 AMButton(Modifier.weight(1f)) so button will take precedence
this is my code for `mearurable`s
val placeables = measurables.map {
it.measure(constraints)
}Filip Wiesner
06/14/2022, 11:04 AMnuhkoca
06/14/2022, 11:08 AMnuhkoca
06/14/2022, 11:10 AMFilip Wiesner
06/14/2022, 11:13 AMFilip Wiesner
06/14/2022, 11:20 AMval remainingWidth = constraints.maxWidth - spaceTakenByOtherComponents
buttonMeasurable.measure(
Constraints(maxWidth = remainingWidth)
)nuhkoca
06/14/2022, 11:53 AMmeasurables.first().measure(constraints.copy(maxWidth = 150))
so how to pass the correct constraints for those which need to be measured first? Sorry I am pretty dumb at this things 🙂Filip Wiesner
06/14/2022, 12:10 PMmeasurables is list of components that you are passing to the content lambda of your layout. They are in the same order as called in the content. In the first step you get those that are prioritized over others and measure them with all of the available space (e.g. Constraints(maxWidth = constraints.maxWidth, maxHeight = constraints.maxheight)). It's not the best practice to copy the constraints that are given to you in measure policy scope. You might copy min constraints as well and you rarely want that.
When you have the priority measurables measeured, you can determine how much space you have left and constraint the remaining measurables to this space.
In other words, you measure the measurables one by one, creating custom Constraints for each of them to match the actual remaining space.
I was looking for some good example in google compose samples but couldn't find any layout where one measurable would constraint some other.nuhkoca
06/14/2022, 1:28 PMConstraints(maxWidth = constraints.maxWidth, maxHeight = constraints.maxheight) and can slice the remaining space for the rest. So I have 3 components in a row, Text, Icon and Button. So Button would already have been laid out. Might be a stupid question but how could I determine the correct width for the rest. For instance, Text will more space from the remaining space than the Icon does. How can I figure out the best widthFilip Wiesner
06/14/2022, 1:33 PMnuhkoca
06/14/2022, 3:42 PMnuhkoca
06/14/2022, 4:23 PMFilip Wiesner
06/14/2022, 4:25 PM