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.

Keep a list row's separator under its title beside a status label

Țugui Dragoș079ed1761fff
diff --git a/Peel/Views/LeavesRowSeparatorAlone.swift b/Peel/Views/LeavesRowSeparatorAlone.swift
new file mode 100644
index 00000000..ec864234
--- /dev/null
+++ b/Peel/Views/LeavesRowSeparatorAlone.swift
@@ -0,0 +1,24 @@
+import SwiftUI
+
+/// Lays out one view as it is, but never lets it decide where a list row's separator starts. A `Label` marks its
+/// title as that start, so a status or a tag beside a row's title would pull the separator under itself.
+struct LeavesRowSeparatorAlone: Layout {
+ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
+ subviews.first?.sizeThatFits(proposal) ?? .zero
+ }
+
+ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
+ subviews.first?.place(at: bounds.origin, proposal: ProposedViewSize(bounds.size))
+ }
+
+ func explicitAlignment(
+ of guide: HorizontalAlignment,
+ in bounds: CGRect,
+ proposal: ProposedViewSize,
+ subviews: Subviews,
+ cache: inout ()
+ ) -> CGFloat? {
+ guard guide != .listRowSeparatorLeading, let view = subviews.first else { return nil }
+ return view.dimensions(in: ProposedViewSize(bounds.size))[explicit: guide].map { bounds.minX + $0 }
+ }
+}
diff --git a/Peel/Views/StatusLabel.swift b/Peel/Views/StatusLabel.swift
index fd76fe85..0d455c89 100644
--- a/Peel/Views/StatusLabel.swift
+++ b/Peel/Views/StatusLabel.swift
@@ -8,11 +8,13 @@ struct StatusLabel: View {
var tint: Color = .orange
var body: some View {
- Label {
- title
- } icon: {
- Image(systemName: systemImage)
- .rowTint(tint)
+ LeavesRowSeparatorAlone {
+ Label {
+ title
+ } icon: {
+ Image(systemName: systemImage)
+ .rowTint(tint)
+ }
}
}
}