Skip to content

Commit 3eab2e3

Browse files
committed
Use a common style for disclosure group items.
1 parent f9d7691 commit 3eab2e3

File tree

1 file changed

+31
-44
lines changed

1 file changed

+31
-44
lines changed

Diffusion-macOS/ControlsView.swift

+31-44
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,32 @@ enum PipelineState {
1818
case failed(Error)
1919
}
2020

21-
//struct LabelToggleDisclosureGroupStyle: DisclosureGroupStyle {
22-
// func makeBody(configuration: Configuration) -> some View {
23-
// VStack {
24-
// HStack {
25-
// Button {
26-
// withAnimation {
27-
// configuration.isExpanded.toggle()
28-
// }
29-
// } label: {
30-
// Image(systemName: configuration.isExpanded ? "chevron.down.circle.fill" : "chevron.right.circle.fill")
31-
// }.buttonStyle(.plain).foregroundColor(.primary).colorInvert()
32-
// configuration.label.onTapGesture {
33-
// withAnimation {
34-
// configuration.isExpanded.toggle()
35-
// }
36-
// }
37-
// Spacer()
38-
// }
39-
// if configuration.isExpanded {
40-
// configuration.content
41-
// }
42-
// }
43-
// }
44-
//}
21+
/// Mimics the native appearance, but labels are clickable.
22+
/// To be removed (adding gestures to all labels) if we observe any UI shenanigans.
23+
struct LabelToggleDisclosureGroupStyle: DisclosureGroupStyle {
24+
func makeBody(configuration: Configuration) -> some View {
25+
VStack {
26+
HStack {
27+
Button {
28+
withAnimation {
29+
configuration.isExpanded.toggle()
30+
}
31+
} label: {
32+
Image(systemName: configuration.isExpanded ? "chevron.down" : "chevron.right").frame(width:8, height: 8)
33+
}.buttonStyle(.plain).font(.footnote).fontWeight(.semibold).foregroundColor(.gray)
34+
configuration.label.onTapGesture {
35+
withAnimation {
36+
configuration.isExpanded.toggle()
37+
}
38+
}
39+
Spacer()
40+
}
41+
if configuration.isExpanded {
42+
configuration.content
43+
}
44+
}
45+
}
46+
}
4547

4648
struct ControlsView: View {
4749
@EnvironmentObject var generation: GenerationContext
@@ -111,11 +113,7 @@ struct ControlsView: View {
111113
modelDidChange(model: model)
112114
}
113115
} label: {
114-
Label("Model from Hub", systemImage: "cpu").foregroundColor(.secondary).onTapGesture {
115-
withAnimation {
116-
disclosedModel.toggle()
117-
}
118-
}
116+
Label("Model from Hub", systemImage: "cpu").foregroundColor(.secondary)
119117
}
120118

121119
Divider()
@@ -131,11 +129,7 @@ struct ControlsView: View {
131129
.textFieldStyle(.squareBorder)
132130
}.padding(.leading, 10)
133131
} label: {
134-
Label("Prompts", systemImage: "text.quote").foregroundColor(.secondary).onTapGesture {
135-
withAnimation {
136-
disclosedPrompt.toggle()
137-
}
138-
}
132+
Label("Prompts", systemImage: "text.quote").foregroundColor(.secondary)
139133
}
140134

141135
Divider()
@@ -147,11 +141,7 @@ struct ControlsView: View {
147141
Text("\(Int(generation.steps))")
148142
}.padding(.leading, 10)
149143
} label: {
150-
Label("Step count", systemImage: "square.3.layers.3d.down.left").foregroundColor(.secondary).onTapGesture {
151-
withAnimation {
152-
disclosedSteps.toggle()
153-
}
154-
}
144+
Label("Step count", systemImage: "square.3.layers.3d.down.left").foregroundColor(.secondary)
155145
}
156146
Divider()
157147

@@ -174,14 +164,11 @@ struct ControlsView: View {
174164
Text("\(Int(generation.seed))")
175165
}.padding(.leading, 10)
176166
} label: {
177-
Label("Seed", systemImage: "leaf").foregroundColor(.secondary).onTapGesture {
178-
withAnimation {
179-
disclosedSeed.toggle()
180-
}
181-
}
167+
Label("Seed", systemImage: "leaf").foregroundColor(.secondary)
182168
}
183169
}
184170
}
171+
.disclosureGroupStyle(LabelToggleDisclosureGroupStyle())
185172

186173
StatusView(pipelineState: $pipelineState)
187174
}

0 commit comments

Comments
 (0)