Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Keep the window its height when a notice is asked for its least size
Țugui Dragoș23342001ac1f
diff --git a/Peel/Views/FlowLayout.swift b/Peel/Views/FlowLayout.swiftindex dd6e4f78..7889c9d8 100644--- a/Peel/Views/FlowLayout.swift+++ b/Peel/Views/FlowLayout.swift@@ -8,11 +8,11 @@ struct FlowLayout: Layout {var lineSpacing: CGFloat = 6func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {- arrange(subviews, in: proposal.width ?? .infinity).size+ arrange(subviews, in: proposal.width ?? .infinity, height: proposal.height).size}func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {- let arrangement = arrange(subviews, in: bounds.width)+ let arrangement = arrange(subviews, in: bounds.width, height: proposal.height)for (subview, frame) in zip(subviews, arrangement.frames) {subview.place(at: CGPoint(x: bounds.minX + frame.minX, y: bounds.minY + frame.minY),@@ -21,9 +21,11 @@ struct FlowLayout: Layout {}}- /// Each view at its own width, or the whole width when it is wider than that, and each line's views centered- /// on the line.- private func arrange(_ subviews: Subviews, in width: CGFloat) -> (frames: [CGRect], size: CGSize) {+ /// Each view at its own width, or the whole width when it is wider than that, within the height proposed as+ /// `NoticeLayout` measures, and each line's views centered on the line.+ private func arrange(+ _ subviews: Subviews, in width: CGFloat, height: CGFloat?+ ) -> (frames: [CGRect], size: CGSize) {var frames: [CGRect] = []var lineStart = 0var x: CGFloat = 0, y: CGFloat = 0, lineHeight: CGFloat = 0, widest: CGFloat = 0@@ -38,7 +40,7 @@ struct FlowLayout: Layout {for subview in subviews {var size = subview.sizeThatFits(.unspecified)if size.width > width {- size = subview.sizeThatFits(ProposedViewSize(width: width, height: nil))+ size = subview.sizeThatFits(ProposedViewSize(width: width, height: height))}if x > 0, x + size.width > width {closeLine()diff --git a/Peel/Views/NoticeLayout.swift b/Peel/Views/NoticeLayout.swiftindex 686e17c5..04718f8f 100644--- a/Peel/Views/NoticeLayout.swift+++ b/Peel/Views/NoticeLayout.swift@@ -11,11 +11,11 @@ struct NoticeLayout: Layout {var actionsTop: CGFloat = 8func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {- plan(subviews, width: proposal.width).size+ plan(subviews, width: proposal.width, height: proposal.height).size}func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {- let plan = plan(subviews, width: bounds.width)+ let plan = plan(subviews, width: bounds.width, height: proposal.height)for subview in subviews {let frame = switch subview[NoticePart.self] {case .mark: plan.mark@@ -30,10 +30,12 @@ struct NoticeLayout: Layout {}}- private func plan(_ subviews: Subviews, width: CGFloat?) -> NoticePlan {+ /// Each part is measured within the height proposed: asked for its least size, zero by zero, a notice measured+ /// with no height would lay its words out a letter to a line, and a window holding it would grow to fit.+ private func plan(_ subviews: Subviews, width: CGFloat?, height: CGFloat?) -> NoticePlan {func part(_ part: Part) -> LayoutSubview? { subviews.first { $0[NoticePart.self] == part } }func size(of subview: LayoutSubview) -> (CGFloat?) -> CGSize {- { subview.sizeThatFits(ProposedViewSize(width: $0, height: nil)) }+ { subview.sizeThatFits(ProposedViewSize(width: $0, height: height)) }}let actions = part(.actions)let oneLine = actions?.sizeThatFits(.unspecified) ?? .zerodiff --git a/PeelTests/LayoutLeastSizeTests.swift b/PeelTests/LayoutLeastSizeTests.swiftnew file mode 100644index 00000000..5b872e9f--- /dev/null+++ b/PeelTests/LayoutLeastSizeTests.swift@@ -0,0 +1,32 @@+import AppKit+@testable import Peel+import SwiftUI+import Testing++@MainActor+struct LayoutLeastSizeTests {+ private func leastAndIdealHeight(of view: some View) -> (least: CGFloat, ideal: CGFloat) {+ let host = NSHostingController(rootView: view)+ return (host.sizeThatFits(in: .zero).height, host.view.fittingSize.height)+ }++ @Test func aNoticeAskedForItsLeastSizeIsNoTallerThanItsIdealOne() {+ let heights = leastAndIdealHeight(of: Notice(+ title: Text(verbatim: "History no longer lists 1 older removal"),+ detail: Text(verbatim: "What was moved is still in the Trash unless you emptied it."),+ kind: .note+ ) { EmptyView() })++ #expect(heights.least <= heights.ideal)+ }++ @Test func aFlowAskedForItsLeastSizeIsNoTallerThanItsIdealOne() {+ let heights = leastAndIdealHeight(of: FlowLayout {+ Text(verbatim: "Needs approval, or was turned off")+ Button("Open System Settings") {}+ .buttonStyle(.link)+ })++ #expect(heights.least <= heights.ideal)+ }+}