Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Space an empty state's buttons as the empty state does

Țugui Dragoș0eb132fd272b
diff --git a/Peel/Views/EmptyStateActions.swift b/Peel/Views/EmptyStateActions.swift
index 0284079c..816e322e 100644
--- a/Peel/Views/EmptyStateActions.swift
+++ b/Peel/Views/EmptyStateActions.swift
@@ -6,10 +6,13 @@ import SwiftUI
struct EmptyStateActions<Content: View>: View {
@ViewBuilder let content: Content
+ /// The gap an empty state leaves between the buttons of its own row.
+ static var spacing: CGFloat { 6 }
+
var body: some View {
ViewThatFits(in: .horizontal) {
- HStack { content }
- VStack { Group { content }.fixedSize() }
+ HStack(spacing: Self.spacing) { content }
+ VStack(spacing: Self.spacing) { Group { content }.fixedSize() }
}
}
}
diff --git a/PeelTests/EmptyStateActionsTests.swift b/PeelTests/EmptyStateActionsTests.swift
new file mode 100644
index 00000000..0d0a0aa3
--- /dev/null
+++ b/PeelTests/EmptyStateActionsTests.swift
@@ -0,0 +1,61 @@
+import AppKit
+@testable import Peel
+import SwiftUI
+import Testing
+
+@MainActor
+struct EmptyStateActionsTests {
+ private final class Frames {
+ var all: [String: CGRect] = [:]
+ }
+
+ private struct Buttons: View {
+ let frames: Frames
+ let tag: String
+
+ var body: some View {
+ ForEach(["Open Home", "Copy Details", "Help"], id: \.self) { title in
+ Button(title) {}
+ .onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: {
+ frames.all["\(tag) \(title)"] = $0
+ }
+ }
+ }
+ }
+
+ @Test func buttonsThatFitStandAsAnEmptyStateSpacesItsOwn() async {
+ let frames = Frames()
+ let page = VStack {
+ ContentUnavailableView {
+ Label(String("Own"), systemImage: "folder")
+ } actions: {
+ Buttons(frames: frames, tag: "own")
+ }
+ ContentUnavailableView {
+ Label(String("Wrapped"), systemImage: "folder")
+ } actions: {
+ EmptyStateActions { Buttons(frames: frames, tag: "wrapped") }
+ }
+ }
+ let window = NSWindow(
+ contentRect: NSRect(x: 0, y: 0, width: 700, height: 600), styleMask: [.titled],
+ backing: .buffered, defer: true
+ )
+ window.contentView = NSHostingView(rootView: page)
+
+ for _ in 0..<200 where frames.all.count < 6 {
+ window.layoutIfNeeded()
+ try? await Task.sleep(for: .milliseconds(5))
+ }
+
+ func gap(_ tag: String) -> CGFloat? {
+ guard let first = frames.all["\(tag) Open Home"], let second = frames.all["\(tag) Copy Details"] else {
+ return nil
+ }
+ return second.minX - first.maxX
+ }
+ #expect(gap("own") != nil)
+ #expect(gap("wrapped") == gap("own"))
+ #expect(frames.all["wrapped Open Home"]?.minY == frames.all["wrapped Help"]?.minY)
+ }
+}