Repository navigation
Expand file tree
/
Copy pathTaskRow.swift
More file actions
133 lines (119 loc) · 4.27 KB
/
Copy pathTaskRow.swift
File metadata and controls
133 lines (119 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import SwiftUI
import CoreData
/// ✨ TaskRow avec stroke de sélection
struct TaskRow: View {
@Environment(\.colorScheme) private var colorScheme
@ObservedObject var task: TaskItem
// ✅ Détecte si la row est sélectionnée
var isSelected: Bool = false
var body: some View {
HStack(spacing: 12) {
statusIcon
titleView
.lineLimit(2)
Spacer()
if let dueDate = task.dueDate {
dueDateBadge(dueDate)
}
if task.color != .none, let c = task.color.uiColor {
Circle()
.fill(Color(c))
.frame(width: 8, height: 8)
}
}
.padding(.vertical, 8)
.padding(.horizontal, 12)
// ✅ NOUVEAU: Stroke au lieu de background
.background(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Color.clear)
)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(selectionStrokeStyle, lineWidth: 2)
)
}
// ✅ Style de stroke unifié (évite erreur de type)
private var selectionStrokeStyle: some ShapeStyle {
if isSelected {
return AnyShapeStyle(selectionStrokeGradient)
} else {
return AnyShapeStyle(Color.clear)
}
}
// ✅ Stroke gradient selon light/dark mode
private var selectionStrokeGradient: LinearGradient {
if colorScheme == .dark {
// Dark mode: Violet-bleu (comme titre manuscrit tâche)
return LinearGradient.primaryGradient
} else {
// Light mode: Jaune-orangé (comme note manuscrit tâche)
return LinearGradient.doingGradient
}
}
private var statusIcon: some View {
Group {
switch task.status {
case .done:
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.green)
case .doing:
Image(systemName: "circle.dotted")
.foregroundStyle(.orange)
case .todo:
Image(systemName: "circle")
.foregroundStyle(.secondary)
}
}
.font(.title3)
}
@ViewBuilder
private var titleView: some View {
#if os(iOS)
if shouldShowHandwrittenTitle, let data = task.titleDrawingData, !data.isEmpty {
HandwrittenTitleRowView(drawingData: data, height: 28)
} else {
Text(task.effectiveTitle.isEmpty ? "—" : task.effectiveTitle)
.font(.body.weight(.medium))
.foregroundStyle(.primary)
}
#elseif os(macOS)
if shouldShowHandwrittenTitle, let png = task.titleDrawingPreviewPNG, let nsImage = NSImage(data: png) {
Image(nsImage: nsImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 28)
} else {
Text(task.effectiveTitle.isEmpty ? "—" : task.effectiveTitle)
.font(.body.weight(.medium))
.foregroundStyle(.primary)
}
#else
Text(task.effectiveTitle.isEmpty ? "—" : task.effectiveTitle)
.font(.body.weight(.medium))
.foregroundStyle(.primary)
#endif
}
private var shouldShowHandwrittenTitle: Bool {
let typed = (task.typedTitle ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
guard typed.isEmpty else { return false }
#if os(iOS)
return (task.titleDrawingData?.isEmpty == false)
#elseif os(macOS)
return (task.titleDrawingPreviewPNG?.isEmpty == false)
#else
return false
#endif
}
private func dueDateBadge(_ date: Date) -> some View {
Text(date.compactRelativeFormat())
.font(.caption2)
.foregroundStyle(task.isOverdue ? .red : .secondary)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(
Capsule()
.fill(task.isOverdue ? Color.red.opacity(0.15) : Color.secondary.opacity(0.1))
)
}
}