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
Put a notice's buttons beside its words wherever the notice comes out shorter
Țugui Dragoș7d0243818c17
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7f0512c0..c7400c57 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -436,8 +436,9 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.no room. What concerns one row sits at that row's right end, and a section heading with nothing under it keeps itsbutton beside it.- Show in Finder is Finder's own symbol at the end of the row that says where the item is.-- A notice's buttons stand beside its words only while each line of the words fits there, and otherwise under them at- the right, the main action last.+- A notice's buttons stand at its right, centered on its words, wherever the notice comes out shorter so and its title+ keeps its line, and otherwise under the words at the right, the main action last; the notice's symbol stands as far+ in from its edge as its buttons.- Where macOS keeps Peel out until it has Full Disk Access, the notice says to turn it on from Home, with Open Home,and a folder whose own permissions keep your account out says that Full Disk Access takes Peel past macOS's privacyprotections, not past a folder's own permissions.diff --git a/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swift b/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swiftindex 24f77b22..5b881953 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/ActionRowPlan.swift@@ -10,11 +10,9 @@ public struct ActionRowPlan: Equatable, Sendable {/// - Parameters:/// - sizes: Each button's own size. What has no width, a group with nothing to show, takes no room.- /// - top: The space above the buttons, left out with them when none shows./// - leading: Which buttons lead, by their place in `sizes`.public init(- sizes: [CGSize], width: CGFloat?, spacing: CGFloat = 8, lineSpacing: CGFloat = 6, top: CGFloat = 0,- leading: [Bool] = []+ sizes: [CGSize], width: CGFloat?, spacing: CGFloat = 8, lineSpacing: CGFloat = 6, leading: [Bool] = []) {let shown = sizes.indices.filter { sizes[$0].width > 0 }let leads = shown.filter { leading.indices.contains($0) && leading[$0] }@@ -30,7 +28,7 @@ public struct ActionRowPlan: Equatable, Sendable {lines += oneLine ? [Line(leading: leads, trailing: follows)] : trailingvar frames = [CGRect](repeating: .zero, count: sizes.count)- var y = top+ var y: CGFloat = 0for line in lines {let height = (line.leading + line.trailing).reduce(0) { max($0, sizes[$1].height) }func place(_ index: Int, at x: CGFloat) {diff --git a/Packages/PeelCore/Sources/PeelCore/Support/NoticePlan.swift b/Packages/PeelCore/Sources/PeelCore/Support/NoticePlan.swiftnew file mode 100644index 00000000..d8b7b9a8--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Support/NoticePlan.swift@@ -0,0 +1,101 @@+public import CoreGraphics++/// Where a notice's mark, words, detail and buttons go. The buttons stand beside the words while the notice is shorter+/// so, the words keep their lines, every word fits and the words stand no taller than three buttons: a detail wraps+/// beside a long button instead of leaving a line of its own to it, while a title never breaks for one and a long+/// notice reads as text with its buttons under it. Without buttons the words stand beside the mark while each fits on+/// one line. Otherwise the words and the detail take the whole width, and the buttons stand under them. The mark is+/// centered on the row while every line stays whole, else at the words' first line.+public struct NoticePlan: Equatable, Sendable {+ public let isBeside: Bool+ public let mark: CGRect+ public let words: CGRect+ public let detail: CGRect+ public let actions: CGRect+ public let size: CGSize++ /// - Parameters:+ /// - mark: A mark with no width takes no room, nor the gap after it.+ /// - actions: The buttons on one line. With no width there are none.+ /// - actionsUnder: The buttons under the words, laid out across the whole width.+ /// - words: The words' size at a width, or on one line for nil: a title, or a block that keeps its lines.+ /// - detail: The detail's size likewise, under the words.+ public init(+ width: CGFloat?, mark: CGSize, actions: CGSize, actionsUnder: CGSize, markGap: CGFloat, detailGap: CGFloat,+ actionsGap: CGFloat, actionsTop: CGFloat, words: (CGFloat?) -> CGSize, detail: ((CGFloat?) -> CGSize)?+ ) {+ let markRoom = mark.width > 0 ? mark.width + markGap : 0+ let hasActions = actions.width > 0+ let actionsRoom = hasActions ? actionsGap + actions.width : 0+ let oneLine = Parts(words: words(nil), detail: detail?(nil))+ guard let width, width.isFinite else {+ let room = max(oneLine.words.width, oneLine.detail?.width ?? 0)+ self.init(+ arranged: oneLine, beside: true, room: room, width: markRoom + room + actionsRoom, mark: mark,+ markRoom: markRoom, actions: hasActions ? actions : .zero, gaps: (detailGap, actionsTop),+ linesKept: true+ )+ return+ }+ let room = max(width - markRoom - actionsRoom, 0)+ let wholeRoom = max(width - markRoom, 0)+ let beside = Parts(words: words(room), detail: detail?(room))+ let under = Parts(words: words(wholeRoom), detail: detail?(wholeRoom))+ let isBeside = hasActions+ ? beside.fit(in: room) && beside.words.height <= under.words.height+ && beside.height(detailGap) <= 3 * actions.height+ && max(mark.height, beside.height(detailGap), actions.height)+ < max(mark.height, under.height(detailGap)) + actionsTop + actionsUnder.height+ : oneLine.fit(in: wholeRoom)+ let parts = isBeside ? beside : under+ self.init(+ arranged: parts, beside: isBeside, room: isBeside ? room : wholeRoom, width: width, mark: mark,+ markRoom: markRoom, actions: !hasActions ? .zero : isBeside ? actions : actionsUnder,+ gaps: (detailGap, actionsTop),+ linesKept: parts.words.height <= oneLine.words.height+ && (parts.detail?.height ?? 0) <= (oneLine.detail?.height ?? 0)+ )+ }++ private struct Parts {+ let words: CGSize+ let detail: CGSize?++ func fit(in room: CGFloat) -> Bool {+ words.width <= room && (detail?.width ?? 0) <= room+ }++ func height(_ detailGap: CGFloat) -> CGFloat {+ words.height + (detail.map { detailGap + $0.height } ?? 0)+ }+ }++ private init(+ arranged parts: Parts, beside: Bool, room: CGFloat, width: CGFloat, mark: CGSize, markRoom: CGFloat,+ actions: CGSize, gaps: (detail: CGFloat, actionsTop: CGFloat), linesKept: Bool+ ) {+ let block = parts.height(gaps.detail)+ let height = beside ? max(mark.height, block, actions.height) : max(mark.height, block)+ let blockY = beside ? (height - block) / 2 : 0+ isBeside = beside+ self.mark = CGRect(+ origin: CGPoint(x: 0, y: beside && linesKept ? (height - mark.height) / 2 : blockY), size: mark+ )+ words = CGRect(x: markRoom, y: blockY, width: room, height: parts.words.height)+ detail = parts.detail.map {+ CGRect(x: markRoom, y: blockY + parts.words.height + gaps.detail, width: room, height: $0.height)+ } ?? .zero+ if actions.width <= 0 {+ self.actions = .zero+ size = CGSize(width: width, height: height)+ } else if beside {+ self.actions = CGRect(+ origin: CGPoint(x: width - actions.width, y: (height - actions.height) / 2), size: actions+ )+ size = CGSize(width: width, height: height)+ } else {+ self.actions = CGRect(x: 0, y: height + gaps.actionsTop, width: width, height: actions.height)+ size = CGSize(width: width, height: height + gaps.actionsTop + actions.height)+ }+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swiftindex c7a7536f..e3d0a196 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ActionRowPlanTests.swift@@ -44,13 +44,6 @@ struct ActionRowPlanTests {#expect(ActionRowPlan(sizes: [], width: 400).size.height == 0)}- @Test func theSpaceAboveTheActionsIsThereOnlyWhileOneShows() {- let plan = ActionRowPlan(sizes: [small], width: 400, top: 8)- #expect(plan.frames == [CGRect(x: 300, y: 8, width: 100, height: 28)])- #expect(plan.size.height == 36)- #expect(ActionRowPlan(sizes: [.zero], width: 400, top: 8).size.height == 0)- }-@Test func leadingActionsStandAtTheLeftEdgeOnTheLineOfTheOthers() {let plan = ActionRowPlan(sizes: [small, small, small], width: 400, spacing: 8, leading: [true, true, false])#expect(plan.frames.map(\.minX) == [0, 108, 300])diff --git a/Packages/PeelCore/Tests/PeelCoreTests/NoticePlanTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/NoticePlanTests.swiftnew file mode 100644index 00000000..c4f383f9--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/NoticePlanTests.swift@@ -0,0 +1,115 @@+import CoreGraphics+@testable import PeelCore+import Testing++struct NoticePlanTests {+ private let mark = CGSize(width: 26, height: 26)++ /// Words that wrap as a paragraph does: `length` points of text, in lines of 15 points.+ private func text(_ length: CGFloat) -> (CGFloat?) -> CGSize {+ { width in+ guard let width, width < length else { return CGSize(width: length, height: 15) }+ return CGSize(width: width, height: (length / width).rounded(.up) * 15)+ }+ }++ private func plan(+ width: CGFloat?, mark: CGSize? = nil, actions: CGSize, markGap: CGFloat = 10,+ title: @escaping (CGFloat?) -> CGSize, detail: ((CGFloat?) -> CGSize)? = nil+ ) -> NoticePlan {+ let under = actions.width > 0 ? CGSize(width: width ?? actions.width, height: actions.height) : .zero+ return NoticePlan(+ width: width, mark: mark ?? self.mark, actions: actions, actionsUnder: under, markGap: markGap,+ detailGap: 1, actionsGap: 10, actionsTop: 8, words: title, detail: detail+ )+ }++ @Test func aDetailThatWrapsBesideALongButtonStaysBesideItWhileThatIsShorter() {+ let plan = plan(width: 520, actions: CGSize(width: 190, height: 28), title: text(250), detail: text(400))+ #expect(plan.isBeside)+ #expect(plan.words == CGRect(x: 36, y: 0, width: 284, height: 15))+ #expect(plan.detail == CGRect(x: 36, y: 16, width: 284, height: 30))+ #expect(plan.mark == CGRect(x: 0, y: 0, width: 26, height: 26))+ #expect(plan.actions == CGRect(x: 330, y: 9, width: 190, height: 28))+ #expect(plan.size == CGSize(width: 520, height: 46))+ }++ @Test func whileEveryLineStaysWholeTheMarkTheWordsAndTheButtonsShareOneAxis() {+ let plan = plan(width: 520, actions: CGSize(width: 150, height: 28), title: text(200), detail: text(200))+ #expect(plan.isBeside)+ #expect(plan.size.height == 31)+ #expect(plan.mark.minY == 2.5)+ #expect(plan.words.minY == 0)+ #expect(plan.actions.minY == 1.5)+ }++ @Test func aTitleThatWouldWrapBesideTheButtonsSendsThemUnder() {+ let plan = plan(+ width: 480, mark: CGSize(width: 24, height: 17), actions: CGSize(width: 100, height: 24), markGap: 8,+ title: text(400), detail: text(300)+ )+ #expect(!plan.isBeside)+ #expect(plan.words == CGRect(x: 32, y: 0, width: 448, height: 15))+ #expect(plan.detail == CGRect(x: 32, y: 16, width: 448, height: 15))+ #expect(plan.actions == CGRect(x: 0, y: 39, width: 480, height: 24))+ #expect(plan.size == CGSize(width: 480, height: 63))+ }++ @Test func theButtonsStandBesideOnlyWhereTheNoticeComesOutShorter() {+ let saving = plan(width: 520, actions: CGSize(width: 190, height: 28), title: text(250), detail: text(900))+ #expect(saving.isBeside)+ #expect(saving.detail.height == 60)+ let even = plan(width: 520, actions: CGSize(width: 190, height: 22), title: text(250), detail: text(900))+ #expect(!even.isBeside)+ }++ @Test func wordsTallerThanThreeButtonsKeepTheButtonsUnderThem() {+ let plan = plan(width: 900, actions: CGSize(width: 300, height: 22), title: text(200), detail: text(3500))+ #expect(!plan.isBeside)+ #expect(plan.detail.width == 864)+ }++ @Test func aNarrowColumnKeepsTheWholeWidthForTheDetail() {+ let plan = plan(+ width: 330, actions: CGSize(width: 100, height: 22), markGap: 8, title: text(120), detail: text(1200)+ )+ #expect(!plan.isBeside)+ #expect(plan.mark == CGRect(x: 0, y: 0, width: 26, height: 26))+ #expect(plan.detail == CGRect(x: 34, y: 16, width: 296, height: 75))+ #expect(plan.actions == CGRect(x: 0, y: 99, width: 330, height: 22))+ }++ @Test func withoutButtonsTheWordsStandBesideTheMarkOnlyOnOneLine() {+ let short = plan(width: 400, actions: .zero, title: text(300))+ #expect(short.isBeside)+ #expect(short.words == CGRect(x: 36, y: 5.5, width: 364, height: 15))+ #expect(short.size == CGSize(width: 400, height: 26))++ let long = plan(width: 400, actions: .zero, title: text(200), detail: text(500))+ #expect(!long.isBeside)+ #expect(long.mark == CGRect(x: 0, y: 0, width: 26, height: 26))+ #expect(long.detail == CGRect(x: 36, y: 16, width: 364, height: 30))+ #expect(long.size == CGSize(width: 400, height: 46))+ }++ @Test func aWordWiderThanTheRoomBesideTheButtonsSendsThemUnder() {+ let unbreakable: (CGFloat?) -> CGSize = { _ in CGSize(width: 300, height: 15) }+ let plan = plan(width: 400, actions: CGSize(width: 150, height: 28), title: text(100), detail: unbreakable)+ #expect(!plan.isBeside)+ }++ @Test func withoutAWidthEverythingStandsOnOneLine() {+ let plan = plan(width: nil, actions: CGSize(width: 190, height: 28), title: text(250), detail: text(400))+ #expect(plan.isBeside)+ #expect(plan.size == CGSize(width: 636, height: 31))+ #expect(plan.actions.minX == 446)+ }++ @Test func aMarkWithNoWidthTakesNoRoom() {+ let plan = plan(width: 520, mark: .zero, actions: CGSize(width: 190, height: 28), title: text(250))+ #expect(plan.isBeside)+ #expect(plan.words.minX == 0)+ #expect(plan.words.width == 320)+ #expect(plan.detail == .zero)+ }+}diff --git a/Peel/Views/ActionRow.swift b/Peel/Views/ActionRow.swiftindex 79ca5600..be63705b 100644--- a/Peel/Views/ActionRow.swift+++ b/Peel/Views/ActionRow.swift@@ -3,9 +3,6 @@ import SwiftUI/// Buttons together at the right edge, the last, the page's main action, at the edge itself, as `ActionRowPlan` says.struct ActionRow: Layout {- /// The space above the buttons, which a row with none to show leaves out too.- var top: CGFloat = 0-func makeCache(subviews: Subviews) -> [CGSize] {subviews.map { $0.sizeThatFits(.unspecified) }}@@ -30,7 +27,7 @@ struct ActionRow: Layout {return subview.sizeThatFits(ProposedViewSize(width: width, height: nil))}let leading = subviews.map { $0[LeadsActionRow.self] }- return ActionRowPlan(sizes: fitted, width: width, top: top, leading: leading)+ return ActionRowPlan(sizes: fitted, width: width, leading: leading)}}diff --git a/Peel/Views/Notice.swift b/Peel/Views/Notice.swiftindex e64d0692..55e3a70a 100644--- a/Peel/Views/Notice.swift+++ b/Peel/Views/Notice.swift@@ -26,39 +26,25 @@ struct Notice<Actions: View>: View {@ViewBuilder let actions: Actionsvar body: some View {- // The buttons go beside the words only while each line of them fits there whole, else under them at the right.- ViewThatFits(in: .horizontal) {- HStack(spacing: 10) {- mark- words- Spacer(minLength: 10)- buttons- }- VStack(alignment: .leading, spacing: 0) {- HStack(alignment: .top, spacing: 10) {- mark- words- .frame(maxWidth: .infinity, alignment: .leading)- }- ActionRow(top: 8) { buttons }- }- }- .padding(.horizontal, 12)- .padding(.vertical, 8)- .modifier(NoticeBackground(isAlbum: isAlbum))- }-- private var words: some View {- VStack(alignment: .leading, spacing: 1) {+ NoticeLayout(markGap: isAlbum ? 10 : 8) {+ mark+ .noticePart(.mark)title.font(isAlbum ? .system(size: 12.5, weight: .bold, design: .rounded) : .callout.weight(.semibold)).foregroundStyle(titleColor)+ .noticePart(.words)if let detail {detail.font(isAlbum ? .system(size: 11) : .caption).foregroundStyle(.secondary)+ .noticePart(.detail)}+ ActionRow { buttons }+ .noticePart(.actions)}+ .padding(.horizontal, 12)+ .padding(.vertical, 8)+ .modifier(NoticeBackground(isAlbum: isAlbum))}/// Bordered buttons outside the album, so a page's one prominent button stays its main action.@@ -105,7 +91,8 @@ struct Notice<Actions: View>: View {Image(systemName: systemImage ?? kindSymbol).font(.system(size: 16)).foregroundStyle(tint)- .frame(width: 26)+ // At the panel's inset, as the buttons are on the other side; 24 holds the widest symbol, hammer.+ .frame(width: 24, alignment: .leading)// VoiceOver hears the kind's own symbol, Info or Warning, whichever symbol is drawn..accessibilityRepresentation { Image(systemName: kindSymbol) }}diff --git a/Peel/Views/NoticeLayout.swift b/Peel/Views/NoticeLayout.swiftnew file mode 100644index 00000000..686e17c5--- /dev/null+++ b/Peel/Views/NoticeLayout.swift@@ -0,0 +1,58 @@+import PeelCore+import SwiftUI++/// A notice's mark, words, detail and buttons, each named with `noticePart(_:)`, placed as `NoticePlan` says.+struct NoticeLayout: Layout {+ enum Part: Sendable { case mark, words, detail, actions }++ var markGap: CGFloat = 0+ var detailGap: CGFloat = 1+ var actionsGap: CGFloat = 10+ var actionsTop: CGFloat = 8++ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {+ plan(subviews, width: proposal.width).size+ }++ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {+ let plan = plan(subviews, width: bounds.width)+ for subview in subviews {+ let frame = switch subview[NoticePart.self] {+ case .mark: plan.mark+ case .words: plan.words+ case .detail: plan.detail+ case .actions: plan.actions+ }+ subview.place(+ at: CGPoint(x: bounds.minX + frame.minX, y: bounds.minY + frame.minY),+ proposal: ProposedViewSize(frame.size)+ )+ }+ }++ private func plan(_ subviews: Subviews, width: 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)) }+ }+ let actions = part(.actions)+ let oneLine = actions?.sizeThatFits(.unspecified) ?? .zero+ return NoticePlan(+ width: width, mark: part(.mark)?.sizeThatFits(.unspecified) ?? .zero, actions: oneLine,+ actionsUnder: width.flatMap { width in actions.map { size(of: $0)(width) } } ?? oneLine,+ markGap: markGap, detailGap: detailGap, actionsGap: actionsGap, actionsTop: actionsTop,+ words: part(.words).map(size(of:)) ?? { _ in .zero }, detail: part(.detail).map(size(of:))+ )+ }+}++nonisolated private struct NoticePart: LayoutValueKey {+ static let defaultValue = NoticeLayout.Part.words+}++extension View {+ /// What this view is to its `NoticeLayout`.+ func noticePart(_ part: NoticeLayout.Part) -> some View {+ layoutValue(key: NoticePart.self, value: part)+ }+}diff --git a/Peel/Views/UpdatePanel.swift b/Peel/Views/UpdatePanel.swiftindex cf5c9afe..5dbb2725 100644--- a/Peel/Views/UpdatePanel.swift+++ b/Peel/Views/UpdatePanel.swift@@ -14,17 +14,10 @@ struct UpdatePanel<Detail: View, Action: View>: View {HStack(alignment: .words, spacing: 12) {markVStack(alignment: .leading, spacing: 12) {- ViewThatFits(in: .horizontal) {- HStack(spacing: 12) {- words- Spacer(minLength: 12)- action- }- VStack(alignment: .leading, spacing: 0) {- words- ActionRow(top: 10) { action }- }- .frame(maxWidth: .infinity, alignment: .leading)+ NoticeLayout(actionsGap: 12, actionsTop: 10) {+ words+ ActionRow { action }+ .noticePart(.actions)}if let notes {Divider()diff --git a/PeelTests/NoticeLayoutTests.swift b/PeelTests/NoticeLayoutTests.swiftindex c5634919..c6151882 100644--- a/PeelTests/NoticeLayoutTests.swift+++ b/PeelTests/NoticeLayoutTests.swift@@ -81,6 +81,21 @@ struct NoticeLayoutTests {#expect(reopen.height > frames.panel.height / 2)#expect(abs(reopen.maxX - (frames.panel.maxX - 12)) < 1)}++ @Test func aDetailWrapsBesideALongButtonRatherThanLeaveItALine() async throws {+ let frames = Frames()+ let view = Notice(+ title: Text(verbatim: "Peel couldn’t read your exclusions"),+ detail: Text(verbatim: "Peel removes nothing and puts nothing back until you start the list over in Settings.")+ ) {+ button("Open Peel Settings", into: frames)+ }+ .measured(into: frames)+ let open = try #require(await laidOut(view, width: 560, frames: frames, buttons: 1).buttons["Open Peel Settings"])++ #expect(abs(open.midY - frames.panel.midY) < 1)+ #expect(abs(open.maxX - (frames.panel.maxX - 12)) < 1)+ }}@MainActor@@ -120,7 +135,7 @@ struct UpdatePanelLayoutTests {}@Test func underALongTextTheButtonStandsBelowIt() async throws {- let frames = await panel(paragraph, width: 900)+ let frames = await panel([paragraph, paragraph, paragraph].joined(separator: "\n\n"), width: 900)let open = try #require(frames.buttons["Open Tidewater"])#expect(abs(open.maxY - (frames.panel.maxY - 12)) < 1)