Skip to content

Commit

Permalink
Refactor WrappingHStack
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Mar 2, 2025
1 parent a7ca048 commit 154aed8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions CotEditor/Sources/Views/SwiftUI/WrappingHStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ private struct WrappingHStackLayout: Layout {

let width = proposal.replacingUnspecifiedDimensions().width
let rowCount = Double(self.countRows(for: subviews, in: width))
let minHeight = subviews
.map { $0.sizeThatFits(proposal).height }
.reduce(0) { max($0, $1).rounded(.up) }
let minHeight = subviews.map { $0.sizeThatFits(proposal).height }.max()?.rounded(.up) ?? 0
let height = rowCount * minHeight + max(rowCount - 1, 0) * self.verticalSpacing

return CGSize(width: width, height: height)
Expand All @@ -62,9 +60,7 @@ private struct WrappingHStackLayout: Layout {

func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {

let minHeight = subviews
.map { $0.sizeThatFits(proposal).height }
.reduce(0) { max($0, $1).rounded(.up) }
let minHeight = subviews.map { $0.sizeThatFits(proposal).height }.max()?.rounded(.up) ?? 0
var point = bounds.origin

for subview in subviews {
Expand Down

0 comments on commit 154aed8

Please sign in to comment.