How to use `alignmentGuide` properly to avoid extra space under items?
Asked Answered
N

0

1

Following this solution: https://mcmap.net/q/259752/-hstack-with-wrap

My Code is fairly similar:

GeometryReader { g in
    var width = CGFloat.zero
    var height = CGFloat.zero
    ZStack(alignment: .topLeading) {
        let platforms = walkExpression(mapRule.objectrule)
        ForEach(platforms) { platform in
            Text(platform.text).padding([.horizontal, .vertical], 4)
                .alignmentGuide(.leading, computeValue: { d in
                    if (abs(width - d.width) > g.size.width)
                    {
                        width = 0
                        height -= d.height
                    }
                    let result = width
                    if platform == platforms.last! {
                        width = 0 //last item
                    } else {
                        width -= d.width
                    }
                    return result
                }).alignmentGuide(.top, computeValue: {d in
                    let result = height
                    if platform == platforms.last! {
                        height = 0 // last item
                    }
                    return result
                })
            
        }
    }
}

But there is a hug gap, empty space under the list, why?

enter image description here

Nopar answered 5/6, 2023 at 10:46 Comment(3)
Can you post a picture what it should look like?Expansionism
At the very bottom you see the top of to button, those buttons should be right on the bottom of text.Blessed
extra spece is between ZStack and GeometryReaderBlessed

© 2022 - 2024 — McMap. All rights reserved.