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?