This repository was archived by the owner on Nov 7, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathInspectorPanelViews.swift
More file actions
228 lines (216 loc) · 10.4 KB
/
Copy pathInspectorPanelViews.swift
File metadata and controls
228 lines (216 loc) · 10.4 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import SwiftUI
import VisuStructCore
/// Kontext für „Fall hinzufügen“ / „Fall entfernen“ im Inspector (Fallauswahl).
struct InspectorFallauswahlToolbarContext {
let caseCount: Int
let removeCaseIndex: Int?
let onAdd: () -> Void
let onRemove: () -> Void
}
/// Hauptteil des Inspektors unter dem Canvas (GroupBox-Inhalt).
struct InspectorPanelBody<ForLoopColumn: View>: View {
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(\.appLanguage) private var lang
/// Muss `FocusState`-Projektion sein (nicht `Binding`), damit `.focused(_:equals:)` kompiliert.
var focusedField: FocusState<DiagramEditorFocusTarget?>.Binding
let selectedPath: [Int]?
let captionFont: Font
let inspectorHintFont: Font
let editorFont: Font
let editorMonoPt: CGFloat
let editorMinHeight: CGFloat
let editorMaxHeight: CGFloat
let ioModeBinding: Binding<StatementIOMode>?
let caseLabelBinding: Binding<String>?
let inspectorShowsForLoopThreeFields: Bool
@ViewBuilder let forLoopColumn: (Int, Font, Font) -> ForLoopColumn
let lineEditorVisibleTextBinding: Binding<String>
let editorFocusToken: UUID
let lineEditorFixedPrefixLabel: String?
let inspectorConditionEditorHintLine: String?
let inspectorLineEditorPlaceholder: String?
let fallauswahl: InspectorFallauswahlToolbarContext?
let onApplyLineEditor: () -> Void
let onApplyRespectingFocus: () -> Void
let groupBoxTitle: String
var body: some View {
GroupBox {
VStack(alignment: .leading, spacing: 12) {
if selectedPath == nil {
Text(lang.tr("inspector_no_selection"))
.foregroundStyle(.secondary)
.font(captionFont)
.lineSpacing(3)
}
if let ioModeBinding {
VStack(alignment: .leading, spacing: 6) {
Picker("", selection: ioModeBinding) {
Text(lang.tr("inspector_io_mode_statement")).tag(StatementIOMode.statement)
Text(lang.tr("inspector_io_mode_input")).tag(StatementIOMode.input)
Text(lang.tr("inspector_io_mode_output")).tag(StatementIOMode.output)
}
#if canImport(AppKit)
.pickerStyle(.radioGroup)
#else
.pickerStyle(.segmented)
#endif
.labelsHidden()
if ioModeBinding.wrappedValue == .statement {
Text(verbatim: "int number = 5 | double x = 1.5 | String text = \"Your text\" | boolean ok = true | char letter = 'A' | const double PI = 3.14")
.font(inspectorHintFont)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
} else if ioModeBinding.wrappedValue == .input {
Text(verbatim: "input: int age \"Enter age\" | input: double price \"Enter price\" | input: String name \"Enter name\"")
.font(inspectorHintFont)
.foregroundStyle(.secondary)
} else if ioModeBinding.wrappedValue == .output {
Text(verbatim: "output: number | output: \"Your text\" | output: \"Your age: \" + age")
.font(inspectorHintFont)
.foregroundStyle(.secondary)
}
}
.padding(.bottom, 2)
}
if let labelBind = caseLabelBinding {
TextField("z. B. 1, ok, default", text: labelBind)
.font(editorFont)
.textFieldStyle(.roundedBorder)
.textInputAutocapitalization(.never)
.autocorrectionDisabled(true)
.focused(focusedField, equals: DiagramEditorFocusTarget.caseLabel)
}
if inspectorShowsForLoopThreeFields {
if horizontalSizeClass == .regular {
HStack(alignment: .top, spacing: 12) {
ForEach(0 ..< 3, id: \.self) { i in
forLoopColumn(i, captionFont, editorFont)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
} else {
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: 12) {
ForEach(0 ..< 3, id: \.self) { i in
forLoopColumn(i, captionFont, editorFont)
.frame(minWidth: 128, alignment: .leading)
}
}
}
}
} else {
VStack(alignment: .leading, spacing: 6) {
if let condHint = inspectorConditionEditorHintLine {
Text(verbatim: condHint)
.font(inspectorHintFont)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
HStack(alignment: .top, spacing: 8) {
if let prefixLabel = lineEditorFixedPrefixLabel {
Text(verbatim: prefixLabel)
.font(.system(size: editorMonoPt, weight: .regular, design: .monospaced))
.foregroundStyle(.secondary)
.padding(.top, 10)
.allowsHitTesting(false)
}
ZStack(alignment: .topLeading) {
CodeLineEditor(
text: lineEditorVisibleTextBinding,
minHeight: editorMinHeight,
maxHeight: editorMaxHeight,
focusToken: editorFocusToken,
onCommit: onApplyLineEditor,
monospacedFontSize: editorMonoPt
)
.scrollContentBackground(.hidden)
.textInputAutocapitalization(.never)
.autocorrectionDisabled(true)
.overlay(RoundedRectangle(cornerRadius: 6).stroke(.quaternary))
.focused(focusedField, equals: DiagramEditorFocusTarget.textEditor)
if selectedPath != nil,
lineEditorVisibleTextBinding.wrappedValue.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty,
let placeholder = inspectorLineEditorPlaceholder {
Text(placeholder)
.font(inspectorHintFont)
.foregroundStyle(.secondary)
.padding(.horizontal, 12)
.padding(.vertical, 10)
.allowsHitTesting(false)
}
}
.frame(maxWidth: .infinity)
}
}
Button(lang.tr("inspector_apply_text")) {
onApplyRespectingFocus()
}
.disabled(selectedPath == nil)
}
if let fa = fallauswahl {
HStack(spacing: 16) {
Button {
fa.onAdd()
} label: {
Label(lang.tr("inspector_add_case"), systemImage: "plus.rectangle.on.rectangle")
}
.buttonStyle(.bordered)
Button(role: .destructive) {
fa.onRemove()
} label: {
Label(lang.tr("inspector_remove_case"), systemImage: "minus.rectangle")
}
.buttonStyle(.bordered)
.disabled(fa.caseCount <= 2 || fa.removeCaseIndex == nil)
}
}
}
} label: {
Text(groupBoxTitle)
.font(.headline)
}
}
}
/// iPhone: Inspector nur bei Bedarf; Abbruch Einfügemarke / „Texteditor einblenden“.
struct InspectorPhoneChrome<Inspector: View>: View {
@Environment(\.appLanguage) private var lang
let isPhone: Bool
let insertTargetActive: Bool
let hideInspectorOnPhone: Bool
let onCancelInsert: () -> Void
let onShowInspector: () -> Void
let onHideInspector: () -> Void
@ViewBuilder let inspector: () -> Inspector
var body: some View {
if !isPhone {
inspector()
} else {
if insertTargetActive {
Button {
onCancelInsert()
} label: {
Label(lang.tr("phone_insert_cancel"), systemImage: "xmark.circle")
}
.buttonStyle(.bordered)
} else if hideInspectorOnPhone {
Button {
onShowInspector()
} label: {
Label(lang.tr("phone_show_text_editor"), systemImage: "chevron.up")
}
.buttonStyle(.bordered)
} else {
VStack(alignment: .trailing, spacing: 4) {
Button {
onHideInspector()
} label: {
Label(lang.tr("phone_hide_text_editor"), systemImage: "chevron.down")
.font(.subheadline)
}
.buttonStyle(.borderless)
inspector()
}
}
}
}
}