App/Sources/ModelListView.swift
34 lines · 1136 bytes
1 symbol in this file
1import FoldFormat
2import Models
3import SwiftUI
4
5/// The shipped models by title. Choosing one opens it at step 1.
6struct ModelListView: View {
7 private let models: [FoldFile]
8 @State private var path: [Int]
9
10 init() {
11 let models = (try? ModelLibrary.all()) ?? []
12 self.models = models
13 let cup = ScreenshotScene.requested?.pose == nil ? nil : models.firstIndex { $0.fileTitle == "Cup" }
14 _path = State(initialValue: cup.map { [$0] } ?? [])
15 }
16
17 var body: some View {
18 NavigationStack(path: $path) {
19 Group {
20 if models.isEmpty {
21 ContentUnavailableView("No Models", systemImage: "square.dashed")
22 } else {
23 List(models.indices, id: \.self) { i in
24 NavigationLink(models[i].fileTitle ?? "Untitled", value: i)
25 }
26 }
27 }
28 .navigationTitle("Models")
29 .navigationDestination(for: Int.self) { i in
30 StepView(model: models[i], step: ScreenshotScene.requested?.pose?.step ?? 1)
31 }
32 }
33 }
34}