galex

    galex

    2 years ago
    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!
    Adam Powell

    Adam Powell

    2 years ago
    Super generally, if you don't care if that thing consumes all available space in the parent?
    Modifier.fillMaxSize()
      .wrapContentSize()
    galex

    galex

    2 years ago
    Nice! Thank you as always 🙂
    Honestly if it centers the content, why not call it
    centerContent
    ? I read the doc and I still don’t understand its naming
    Adam Powell

    Adam Powell

    2 years ago
    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.
    galex

    galex

    2 years ago
    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!