|
1 | 1 | import SwiftUI |
2 | 2 |
|
| 3 | +/// Describes a selected row's place within a consecutive selection run. |
| 4 | +enum RowSelectionPosition { |
| 5 | + case none |
| 6 | + case single |
| 7 | + case first |
| 8 | + case middle |
| 9 | + case last |
| 10 | + |
| 11 | + static func resolve( |
| 12 | + _ id: NoteStore.SelectableID, |
| 13 | + in visibleOrder: [NoteStore.SelectableID], |
| 14 | + selection: Set<NoteStore.SelectableID>, |
| 15 | + ) -> Self { |
| 16 | + guard selection.contains(id), let index = visibleOrder.firstIndex(of: id) else { |
| 17 | + return .none |
| 18 | + } |
| 19 | + |
| 20 | + let joinsPrevious = index > visibleOrder.startIndex |
| 21 | + && selection.contains(visibleOrder[index - 1]) |
| 22 | + let joinsNext = index < visibleOrder.index(before: visibleOrder.endIndex) |
| 23 | + && selection.contains(visibleOrder[index + 1]) |
| 24 | + |
| 25 | + switch (joinsPrevious, joinsNext) { |
| 26 | + case (false, false): return .single |
| 27 | + case (false, true): return .first |
| 28 | + case (true, true): return .middle |
| 29 | + case (true, false): return .last |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + var isSelected: Bool { |
| 34 | + self != .none |
| 35 | + } |
| 36 | + |
| 37 | + fileprivate var cornerRadii: RectangleCornerRadii { |
| 38 | + let radius = SurfaceMetrics.panelCornerRadius |
| 39 | + switch self { |
| 40 | + case .none, .single: |
| 41 | + return RectangleCornerRadii( |
| 42 | + topLeading: radius, |
| 43 | + bottomLeading: radius, |
| 44 | + bottomTrailing: radius, |
| 45 | + topTrailing: radius, |
| 46 | + ) |
| 47 | + case .first: |
| 48 | + return RectangleCornerRadii(topLeading: radius, topTrailing: radius) |
| 49 | + case .middle: |
| 50 | + return RectangleCornerRadii() |
| 51 | + case .last: |
| 52 | + return RectangleCornerRadii(bottomLeading: radius, bottomTrailing: radius) |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
3 | 57 | /// Shared selection and hover surface for note and folder rows. |
4 | 58 | /// Active row states adopt Liquid Glass when enabled; classic mode keeps the established fills. |
5 | 59 | struct PanelRowBackground: View { |
6 | 60 | @Environment(AppSettings.self) private var appSettings |
7 | 61 |
|
8 | 62 | let isHovered: Bool |
9 | | - var isSelected = false |
| 63 | + var selectionPosition: RowSelectionPosition = .none |
10 | 64 |
|
11 | | - private var shape: RoundedRectangle { |
12 | | - RoundedRectangle( |
13 | | - cornerRadius: SurfaceMetrics.panelCornerRadius, |
| 65 | + private var shape: UnevenRoundedRectangle { |
| 66 | + UnevenRoundedRectangle( |
| 67 | + cornerRadii: selectionPosition.cornerRadii, |
14 | 68 | style: .continuous, |
15 | 69 | ) |
16 | 70 | } |
17 | 71 |
|
18 | 72 | var body: some View { |
19 | | - if #available(macOS 26.0, *), appSettings.usesLiquidGlass, isHovered || isSelected { |
| 73 | + if #available(macOS 26.0, *), appSettings.usesLiquidGlass, isHovered || selectionPosition.isSelected { |
20 | 74 | shape |
21 | | - .fill(isSelected ? Color.accentColor.opacity(0.14) : .clear) |
| 75 | + .fill(selectionPosition.isSelected ? Color.accentColor.opacity(0.14) : .clear) |
22 | 76 | .glassEffect(.regular.interactive(), in: shape) |
23 | 77 | } else { |
24 | 78 | shape.fill(classicFill) |
25 | 79 | } |
26 | 80 | } |
27 | 81 |
|
28 | 82 | private var classicFill: Color { |
29 | | - if isSelected { |
| 83 | + if selectionPosition.isSelected { |
30 | 84 | return Color.accentColor.opacity(isHovered ? 0.28 : 0.20) |
31 | 85 | } |
32 | 86 | return Color.primary.opacity(isHovered ? 0.06 : 0) |
|
0 commit comments