Skip to content

Commit 67494d2

Browse files
committed
Fix contentSize calculation
1 parent 59fdc0e commit 67494d2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Sources/GateEngine/UI/StackView.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,26 @@ public final class StackView: View {
5050
}
5151

5252
public override func contentSize() -> Size2 {
53+
for subview in self.subviews {
54+
subview.layoutIfNeeded()
55+
}
56+
let spacingSize: Float = spacing * Float(subviews.count - 1)
5357
switch axis {
5458
case .horizontal:
5559
return Size2(
56-
width: subviews.last?.frame.maxX ?? 0,
57-
height: (subviews.sorted(by: {$0.bounds.height > $1.bounds.height}).first?.bounds.height ?? 0) + (spacing * Float(subviews.count - 1))
60+
width: subviews.sorted(by: {$0.frame.maxX < $1.frame.maxX}).last?.frame.maxX ?? 0,
61+
height: (subviews.sorted(by: {$0.frame.height < $1.frame.height}).last?.frame.height ?? 0) + spacingSize
5862
)
5963
case .vertical:
6064
return Size2(
61-
width: (subviews.sorted(by: {$0.bounds.width > $1.bounds.width}).first?.bounds.width ?? 0) + (spacing * Float(subviews.count - 1)),
62-
height: subviews.last?.frame.maxY ?? 0
65+
width: (subviews.sorted(by: {$0.frame.width < $1.frame.width}).last?.frame.width ?? 0) + spacingSize,
66+
height: subviews.sorted(by: {$0.frame.maxY < $1.frame.maxY}).last?.frame.maxY ?? 0
6367
)
6468
}
6569
}
6670

6771
public override func updateLayoutConstraints() {
68-
if subviews.isEmpty {
69-
self.widthAnchor.constrain(to: 0)
70-
self.heightAnchor.constrain(to: 0)
71-
return
72-
}
72+
if subviews.isEmpty {return}
7373
switch axis {
7474
case .horizontal:
7575
switch distribution {

0 commit comments

Comments
 (0)