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.

Give the + and - under a Settings list the same height

Țugui Dragoșffd9021ea2f9
diff --git a/Peel/Views/Settings/SettingsListEditing.swift b/Peel/Views/Settings/SettingsListEditing.swift
index 5e878ad4..5bce362c 100644
--- a/Peel/Views/Settings/SettingsListEditing.swift
+++ b/Peel/Views/Settings/SettingsListEditing.swift
@@ -26,7 +26,17 @@ struct ListEditingButtons<Buttons: View>: View {
buttons
Spacer(minLength: 0)
}
- .labelStyle(.iconOnly)
+ .labelStyle(EditingSymbolLabelStyle())
.editingControls()
}
}
+
+/// A symbol alone, named by its title for VoiceOver, and as tall as a line of text: a small bordered button is its
+/// label's height and six points, so a minus alone would make it 9 points high.
+private struct EditingSymbolLabelStyle: LabelStyle {
+ func makeBody(configuration: Configuration) -> some View {
+ Label(configuration)
+ .labelStyle(.iconOnly)
+ .frame(minHeight: 14)
+ }
+}
diff --git a/PeelTests/ListEditingButtonsTests.swift b/PeelTests/ListEditingButtonsTests.swift
new file mode 100644
index 00000000..8b4e228b
--- /dev/null
+++ b/PeelTests/ListEditingButtonsTests.swift
@@ -0,0 +1,42 @@
+import AppKit
+@testable import Peel
+import SwiftUI
+import Testing
+
+@MainActor
+struct ListEditingButtonsTests {
+ private final class Heights {
+ var add: CGFloat = 0
+ var remove: CGFloat = 0
+ }
+
+ @Test func theButtonsAtTheFootOfASettingsListAreAsHighAsTheHIGsSmallestControl() async {
+ let heights = Heights()
+ let form = Form {
+ Section {
+ Text(verbatim: "org.example.folder")
+ ListEditingButtons {
+ Button("Add Folder…", systemImage: "plus") {}
+ .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { heights.add = $0 }
+ Button("Remove", systemImage: "minus") {}
+ .disabled(true)
+ .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { heights.remove = $0 }
+ }
+ }
+ }
+ .formStyle(.grouped)
+ let window = NSWindow(
+ contentRect: NSRect(x: 0, y: 0, width: 600, height: 300), styleMask: [.titled],
+ backing: .buffered, defer: true
+ )
+ window.contentView = NSHostingView(rootView: form)
+
+ for _ in 0..<200 where heights.add == 0 || heights.remove == 0 {
+ window.layoutIfNeeded()
+ try? await Task.sleep(for: .milliseconds(5))
+ }
+
+ #expect(heights.add >= 20)
+ #expect(heights.remove >= 20)
+ }
+}