https://kotlinlang.org logo
g

galex

07/26/2020, 3:31 PM
What’s the best way to have a button or anything just centered inside its parent (which is the
bodyContent
of Scaffold in my case) ?
I think I need to use fillMaxSize!
a

Adam Powell

07/26/2020, 3:33 PM
Super generally, if you don't care if that thing consumes all available space in the parent?
Copy code
Modifier.fillMaxSize()
  .wrapContentSize()
g

galex

07/26/2020, 3:36 PM
Nice! Thank you as always 🙂
👍 1
Honestly if it centers the content, why not call it
centerContent
? I read the doc and I still don’t understand its naming
a

Adam Powell

07/26/2020, 5:15 PM
Alignment is an argument for wrapContentSize, the default happens to be center.
We started with names closer to what you suggest, but the way it affects measure and layout behavior was unexpected.
Mechanically speaking wrapContentSize drops the min size constraints to 0 during measurement, permitting the element to be smaller than the required minimum, but the modifier still fills the difference in space. The alignment parameter specifies how the content should be positioned within a potentially larger space that was expanded to meet the parent's minimum size requirement.
g

galex

07/27/2020, 3:50 AM
Then it makes sense. I guess we need to learn to think differently about our layouts! Alignement argument is cool, aligning center top, center bottom is now super easy. Thanks for the explanation!
👍 1