Commit 326c18adf5
Verified · cmc
Layout: unified · split
Sources/OrgstarWidgets/HabitsWidget.swift +51 −10
| @@ -104,32 +104,73 @@ struct HabitsView: View { | |||
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | /// org-habit's graph: a bar per day in the due-state color, lighter for days to come, a dot | 106 | /// org-habit's graph: a bar per day in the due-state color, lighter for days to come, a dot |
| 107 | /// where it was done, today outlined. | 107 | /// where it was done, today outlined. With Differentiate Without Colour, the state is also |
| 108 | /// how solid the bar is, from clear (faintest) to overdue (solid), and days to come are | ||
| 109 | /// outlined. | ||
| 108 | struct HabitCells: View { | 110 | struct HabitCells: View { |
| 109 | let cells: [Habit.Cell] | 111 | let cells: [Habit.Cell] |
| 110 | let colors: [String: AgendaSnapshot.Hex] | 112 | let colors: [String: AgendaSnapshot.Hex] |
| 111 | let width: CGFloat | 113 | let width: CGFloat |
| 112 | let height: CGFloat | 114 | let height: CGFloat |
| 113 | @Environment(\.colorScheme) private var scheme | 115 | @Environment(\.colorScheme) private var scheme |
| 116 | @Environment(\.accessibilityDifferentiateWithoutColor) private var differentiateWithoutColor | ||
| 117 | |||
| 118 | private var stepped: Bool { differentiateWithoutColor } | ||
| 114 | 119 | ||
| 115 | var body: some View { | 120 | var body: some View { |
| 116 | HStack(spacing: 1) { | 121 | HStack(spacing: 1) { |
| 117 | ForEach(cells, id: \.day) { cell in | 122 | ForEach(cells, id: \.day) { cell in |
| 118 | RoundedRectangle(cornerRadius: 1.5) | 123 | if stepped { |
| 119 | .fill(color(cell.face)) | 124 | steppedCell(cell) |
| 120 | .frame(width: width, height: height) | 125 | } else { |
| 121 | .overlay { | 126 | RoundedRectangle(cornerRadius: 1.5) |
| 122 | if cell.glyph == "*" { Circle().fill(.white.opacity(0.9)).frame(width: min(width, height) * 0.6) } | 127 | .fill(color(cell.face)) |
| 123 | } | 128 | .frame(width: width, height: height) |
| 124 | .overlay { | 129 | .overlay { |
| 125 | if cell.glyph == "!" { RoundedRectangle(cornerRadius: 1.5).strokeBorder(Color.primary, lineWidth: 1) } | 130 | if cell.glyph == "*" { Circle().fill(.white.opacity(0.9)).frame(width: min(width, height) * 0.6) } |
| 126 | } | 131 | } |
| 132 | .overlay { | ||
| 133 | if cell.glyph == "!" { RoundedRectangle(cornerRadius: 1.5).strokeBorder(Color.primary, lineWidth: 1) } | ||
| 134 | } | ||
| 135 | } | ||
| 127 | } | 136 | } |
| 128 | } | 137 | } |
| 129 | .accessibilityElement(children: .ignore) | 138 | .accessibilityElement(children: .ignore) |
| 130 | .accessibilityLabel("Done \(cells.filter { $0.glyph == "*" }.count) of \(cells.count) days") | 139 | .accessibilityLabel("Done \(cells.filter { $0.glyph == "*" }.count) of \(cells.count) days") |
| 131 | } | 140 | } |
| 132 | 141 | ||
| 142 | /// A filled bar for past days and an outline for days to come, at the state's step; a | ||
| 143 | /// done day has a dot, cut out of the darker steps. | ||
| 144 | private func steppedCell(_ cell: Habit.Cell) -> some View { | ||
| 145 | let (key, fallback, step, future) = Self.state(cell.face) | ||
| 146 | let color = (colors[key]?.color(scheme) ?? fallback).opacity(step) | ||
| 147 | let shape = RoundedRectangle(cornerRadius: 1.5) | ||
| 148 | let dot = Circle().frame(width: min(width, height) * 0.6) | ||
| 149 | return ZStack { | ||
| 150 | if future { shape.strokeBorder(color, lineWidth: 1) } else { shape.fill(color) } | ||
| 151 | if cell.glyph == "*" { | ||
| 152 | if step >= 0.75 { dot.blendMode(.destinationOut) } else { dot.foregroundStyle(Color.primary) } | ||
| 153 | } | ||
| 154 | if cell.glyph == "!" { shape.strokeBorder(Color.primary, lineWidth: 1) } | ||
| 155 | } | ||
| 156 | .compositingGroup() | ||
| 157 | .frame(width: width, height: height) | ||
| 158 | } | ||
| 159 | |||
| 160 | /// The theme key, its fallback, the opacity step and whether the day is to come. | ||
| 161 | private static func state(_ face: Habit.Face) -> (String, Color, Double, Bool) { | ||
| 162 | switch face { | ||
| 163 | case .clear: ("habit-clear", .blue, 0.25, false) | ||
| 164 | case .clearFuture: ("habit-clear", .blue, 0.25, true) | ||
| 165 | case .ready: ("habit-ready", .green, 0.5, false) | ||
| 166 | case .readyFuture: ("habit-ready", .green, 0.5, true) | ||
| 167 | case .alert: ("habit-alert", .yellow, 0.75, false) | ||
| 168 | case .alertFuture: ("habit-alert", .yellow, 0.75, true) | ||
| 169 | case .overdue: ("habit-overdue", .red, 1, false) | ||
| 170 | case .overdueFuture: ("habit-overdue", .red, 1, true) | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 133 | private func color(_ face: Habit.Face) -> Color { | 174 | private func color(_ face: Habit.Face) -> Color { |
| 134 | func themed(_ key: String, _ fallback: Color) -> Color { colors[key]?.color(scheme) ?? fallback } | 175 | func themed(_ key: String, _ fallback: Color) -> Color { colors[key]?.color(scheme) ?? fallback } |
| 135 | switch face { | 176 | switch face { |
docs/manual/guide/14-ios.org +2
| @@ -225,6 +225,8 @@ Tapping a row in the medium or large Today widget opens that entry; tapping else | |||
| 225 | 225 | ||
| 226 | Widgets can't read your folders, so the app writes the next seven days of the agenda (today included) for them to read: while it is open, when files, edits or settings change, when you return to the app, and every hour. Between those times the widgets move on by themselves as timed entries end and at midnight, but they show nothing new until you open orgstar. Until the app has written the agenda once, they say =Open orgstar to show your agenda here.= The widgets ignore the agenda's filter and show no days without entries. The Habits widget's graphs move on at midnight by themselves. | 226 | Widgets can't read your folders, so the app writes the next seven days of the agenda (today included) for them to read: while it is open, when files, edits or settings change, when you return to the app, and every hour. Between those times the widgets move on by themselves as timed entries end and at midnight, but they show nothing new until you open orgstar. Until the app has written the agenda once, they say =Open orgstar to show your agenda here.= The widgets ignore the agenda's filter and show no days without entries. The Habits widget's graphs move on at midnight by themselves. |
| 227 | 227 | ||
| 228 | In the Habits graph a day's bar has the colour of its state: not yet due, due, due today for the last time, or overdue; days to come are lighter. With Differentiate Without Colour on (Settings ▸ Accessibility ▸ Display & Text Size), the states are also told apart by how solid the bar is, from not yet due (faintest) to overdue (solid), and days to come are outlined. | ||
| 229 | |||
| 228 | ** Controls | 230 | ** Controls |
| 229 | 231 | ||
| 230 | orgstar has two controls for Control Center, the Lock Screen and the Action button. Add them as any control: in Control Center, touch and hold an empty space and tap Add a Control, then choose orgstar. | 232 | orgstar has two controls for Control Center, the Lock Screen and the Action button. Add them as any control: in Control Center, touch and hold an empty space and tap Add a Control, then choose orgstar. |