Effekte in Kategorien, App mit Kategorie-Spalte und 12 Plätzen

- Firmware: Kategorien Flash, Weihnachten, Silvester, Musik, Floating statt
  normal/Musik; Prüfung beim Kompilieren auf höchstens 12 Effekte je Kategorie
- API: neu GET /api/categories, /api/effects liefert "category" statt "music"
- App: links die Kategorien, rechts die 12 Plätze der gewählten Kategorie
  (freie Plätze gestrichelt), grüner Punkt an der Kategorie des laufenden Effekts
- Doku und App-Screenshot angepasst

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mikeandClaude Opus 5.5 committed 2026-11-16 12:02:49 +01:00
1 parent 5fbcc15680
commit fba1d3faa6
9 files changed
+237 -75

No files matched your search

+65 -20
View File
@@ -105,28 +105,20 @@ struct ContentView: View {
.disabled(!model.isConnected)
}
/// Links zwei Spalten normale Effekte, rechts eine Spalte Musik-Effekte.
/// Plätze pro Kategorie (2 Spalten × 6 Zeilen)
private static let slots = 12
/// Links die Kategorien, rechts die 12 Plätze der gewählten Kategorie.
/// Die Zeilen wachsen mit dem Platz (32 bis 56 Punkte hoch).
private var effectGrid: some View {
let normal = model.effects.filter { !$0.isMusic }
let music = model.effects.filter(\.isMusic)
let rowCount = max((normal.count + 1) / 2, music.count)
let shown = model.effects.filter { $0.category == model.shownCategory }
let rowCount = max(Self.slots / 2, model.categories.count)
return VStack(spacing: 8) {
HStack(spacing: 8) {
Color.clear.frame(maxWidth: .infinity)
Color.clear.frame(maxWidth: .infinity)
Label("Musik", systemImage: "music.note")
.frame(maxWidth: .infinity)
}
.fixedSize(horizontal: false, vertical: true)
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
.opacity(model.effects.isEmpty ? 0 : 1)
ForEach(0..<rowCount, id: \.self) { row in
HStack(spacing: 8) {
cell(normal, 2 * row)
cell(normal, 2 * row + 1)
cell(music, row)
categoryCell(row)
slot(shown, 2 * row)
slot(shown, 2 * row + 1)
}
.frame(minHeight: 32, maxHeight: 56)
}
@@ -136,9 +128,50 @@ struct ContentView: View {
}
@ViewBuilder
private func cell(_ effects: [CubeEffect], _ index: Int) -> some View {
if index < effects.count {
private func categoryCell(_ index: Int) -> some View {
if index < model.categories.count {
categoryTile(model.categories[index])
} else {
Color.clear.frame(maxWidth: .infinity)
}
}
/// Kategorie wählen zeigt nur ihre Effekte; der Würfel läuft weiter.
/// Der grüne Punkt markiert die Kategorie des laufenden Effekts.
private func categoryTile(_ category: CubeCategory) -> some View {
let shown = category.id == model.shownCategory
let color = Self.color(category.id)
return Button {
model.shownCategory = category.id
} label: {
HStack(spacing: 4) {
if category.id == model.runningCategory {
Circle().fill(.green).frame(width: 7, height: 7)
}
Text(category.name)
.font(.subheadline.weight(.semibold))
.lineLimit(1)
.minimumScaleFactor(0.6)
}
.padding(.horizontal, 4)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(color.opacity(shown ? 0.7 : 0.2), in: .rect(cornerRadius: 10))
.overlay {
if shown { RoundedRectangle(cornerRadius: 10).strokeBorder(color, lineWidth: 2) }
}
}
.buttonStyle(.plain)
}
@ViewBuilder
private func slot(_ effects: [CubeEffect], _ index: Int) -> some View {
if index < effects.count && index < Self.slots {
tile(effects[index])
} else if index < Self.slots && !model.effects.isEmpty {
// freier Platz für einen weiteren Effekt
RoundedRectangle(cornerRadius: 10)
.strokeBorder(.secondary.opacity(0.3), style: StrokeStyle(lineWidth: 1, dash: [4, 4]))
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
Color.clear.frame(maxWidth: .infinity)
}
@@ -146,7 +179,7 @@ struct ContentView: View {
private func tile(_ effect: CubeEffect) -> some View {
let active = effect.id == model.state?.effect
let idle = effect.isMusic ? Color.indigo.opacity(0.35) : Color(.secondarySystemBackground)
let idle = Self.color(effect.category).opacity(0.3)
return Button {
Task { await model.select(effect) }
} label: {
@@ -164,6 +197,18 @@ struct ContentView: View {
}
.buttonStyle(.plain)
}
/// Farbe je Kategorie; neue Kategorien aus der Firmware erscheinen grau.
private static func color(_ category: String) -> Color {
switch category {
case "flash": .yellow
case "weihnachten": .red
case "silvester": .orange
case "musik": .indigo
case "floating": .teal
default: .gray
}
}
}
struct SettingsView: View {