Skip to content

Commit 0be765a

Browse files
committed
Improved UI
1 parent 2749fc5 commit 0be765a

File tree

3 files changed

+138
-72
lines changed

3 files changed

+138
-72
lines changed

Sources/LightControls/DirectionalLightControl.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public struct DirectionalLightControl: View {
7171
}
7272
}
7373

74+
#Preview {
75+
DirectionalLightControl(light: .init())
76+
}
77+
7478
//MARK: - Light Component
7579

7680
extension DirectionalLightControl {
@@ -95,7 +99,7 @@ extension DirectionalLightControl {
9599
}
96100
}
97101
.pickerStyle(MenuPickerStyle())
98-
.accessibilityHint("List of common lux presets to use as Luminance value.")
102+
.accessibilityHint("Sets the intensity of light from a list of common lux settings.")
99103

100104
Toggle("Real World Proxy", isOn: $store.isRealWorldProxy)
101105
.accessibilityHint("Set it to true to cast shadows without illuminating the scene.")
@@ -217,7 +221,7 @@ extension DirectionalLightControl {
217221
}
218222
)
219223
.accessibilityHint(
220-
"Avoid shadow acne and self-shadowing changing this value. It ensures the shadow is properly presented and does not intersect with the surface."
224+
"Adjusts it to avoid shadow acne and self-shadowing. It ensures the shadow is properly rendered and does not intersect with the surface."
221225
)
222226

223227
let maximumDistanceRange: ClosedRange<Float> = 0...20
@@ -260,13 +264,9 @@ extension DirectionalLightControl {
260264
}
261265
)
262266
.accessibilityHint(
263-
"Sets shadow split distance. It lets you customize shadow rendering to only show at particular distances. This can enhance performance and adjust scene shadows visual appearance."
267+
"Sets shadow split distance. It lets customize shadow display to only show at particular distances. This can enhance performance and improve visual appearance."
264268
)
265269
}
266270
}
267271
}
268272
}
269-
270-
#Preview {
271-
DirectionalLightControl(light: .init())
272-
}

Sources/LightControls/PointLightControl.swift

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,53 @@ public struct PointLightControl: View {
1919
isEnabled: pointLight.isEnabled,
2020
orientation: pointLight.orientation
2121
)
22-
) { PointLight() }
22+
) {
23+
PointLight()
24+
}
2325
}
2426

2527
public var body: some View {
2628
Form {
27-
//MARK: - Light Component
29+
LightComponent(store: store)
30+
.onChange(of: store.attenuationRadius) { _, newValue in
31+
pointLight.light.attenuationRadius = newValue
32+
}
33+
.onChange(of: store.color) { _, newValue in
34+
pointLight.light.color = UIColor(newValue)
35+
}
36+
.onChange(of: store.intensity) { _, newValue in
37+
pointLight.light.intensity = Float(newValue.lux)
38+
}
39+
}
40+
.toolbar {
41+
ToolbarItem {
42+
Toggle(
43+
"Enabled",
44+
systemImage: "power.circle",
45+
isOn: $store.isEnabled
46+
)
47+
}
48+
}
49+
.onChange(of: store.isEnabled) { _, newValue in
50+
pointLight.isEnabled = newValue
51+
}
52+
}
53+
}
54+
55+
#Preview {
56+
PointLightControl(light: .init())
57+
}
58+
59+
//MARK: - Light Component
60+
61+
extension PointLightControl {
62+
struct LightComponent: View {
63+
@Bindable var store: StoreOf<PointLight>
2864

65+
var body: some View {
2966
Section("Light Component") {
3067
ColorPicker("Color", selection: $store.color)
68+
.accessibilityHint("Sets the LightComponent color attribute.")
3169

3270
Picker(
3371
"Lux Preset",
@@ -42,8 +80,11 @@ public struct PointLightControl: View {
4280
}
4381
}
4482
.pickerStyle(MenuPickerStyle())
83+
.accessibilityHint("Sets the intensity of light from a list of common lux settings.")
4584

4685
Text("Attenuation Radius: \(store.attenuationRadius, format: .number)")
86+
.accessibilityHidden(true)
87+
4788
Slider(
4889
value: $store.attenuationRadius,
4990
in: 0...10,
@@ -53,39 +94,19 @@ public struct PointLightControl: View {
5394
Text("0 m")
5495
.font(.caption)
5596
.foregroundColor(.secondary)
97+
.accessibilityHidden(true)
5698
},
5799
maximumValueLabel: {
58100
Text("10 m")
59101
.font(.caption)
60102
.foregroundColor(.secondary)
103+
.accessibilityHidden(true)
61104
}
62105
)
63-
}
64-
.onChange(of: store.attenuationRadius) { _, newValue in
65-
pointLight.light.attenuationRadius = newValue
66-
}
67-
.onChange(of: store.color) { _, newValue in
68-
pointLight.light.color = UIColor(newValue)
69-
}
70-
.onChange(of: store.intensity) { _, newValue in
71-
pointLight.light.intensity = Float(newValue.lux)
72-
}
73-
}
74-
.toolbar {
75-
ToolbarItem {
76-
Toggle(
77-
"Enabled",
78-
systemImage: "power.circle",
79-
isOn: $store.isEnabled
106+
.accessibilityHint(
107+
"Defines light reach and calculates its falloff. Can greatly affect performance, so it should be used sparingly."
80108
)
81109
}
82110
}
83-
.onChange(of: store.isEnabled) { _, newValue in
84-
pointLight.isEnabled = newValue
85-
}
86111
}
87112
}
88-
89-
#Preview {
90-
PointLightControl(light: .init())
91-
}

Sources/LightControls/SpotLightControl.swift

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,64 @@ public struct SpotLightControl: View {
2121
orientation: spotLight.orientation,
2222
outerAngleInDegrees: spotLight.light.outerAngleInDegrees
2323
)
24-
) { SpotLight() }
24+
) {
25+
SpotLight()
26+
}
2527
}
2628

2729
public var body: some View {
2830
Form {
29-
//MARK: - Light Component
31+
LightComponentControl(store: store)
32+
.onChange(of: store.attenuationRadius) { _, newValue in
33+
spotLight.light.attenuationRadius = newValue
34+
}
35+
.onChange(of: store.color) { _, newValue in
36+
spotLight.light.color = UIColor(newValue)
37+
}
38+
.onChange(of: store.intensity) { _, newValue in
39+
spotLight.light.intensity = Float(newValue.lux)
40+
}
41+
.onChange(of: store.innerAngleInDegrees) { _, newValue in
42+
spotLight.light.innerAngleInDegrees = newValue
43+
}
3044

45+
OrientationControl(store: store)
46+
.onChange(of: store.orientation) { _, newValue in
47+
spotLight.orientation = newValue
48+
}
49+
.onChange(of: store.outerAngleInDegrees) { _, newValue in
50+
spotLight.light.outerAngleInDegrees = newValue
51+
}
52+
}
53+
.toolbar {
54+
ToolbarItem {
55+
Toggle(
56+
"Enabled",
57+
systemImage: "power.circle",
58+
isOn: $store.isEnabled
59+
)
60+
}
61+
}
62+
.onChange(of: store.isEnabled) { _, newValue in
63+
spotLight.isEnabled = newValue
64+
}
65+
}
66+
}
67+
68+
#Preview {
69+
SpotLightControl(light: .init())
70+
}
71+
72+
//MARK: - Light Component
73+
74+
extension SpotLightControl {
75+
struct LightComponentControl: View {
76+
@Bindable var store: StoreOf<SpotLight>
77+
78+
var body: some View {
3179
Section("Light Component") {
3280
ColorPicker("Color", selection: $store.color)
81+
.accessibilityHint("Sets the LightComponent color attribute.")
3382

3483
Picker(
3584
"Lux Preset",
@@ -44,8 +93,11 @@ public struct SpotLightControl: View {
4493
}
4594
}
4695
.pickerStyle(MenuPickerStyle())
96+
.accessibilityHint("Sets the intensity of light from a list of common lux settings.")
4797

4898
Text("Attenuation Radius: \(store.attenuationRadius, format: .number)")
99+
.accessibilityHidden(true)
100+
49101
Slider(
50102
value: $store.attenuationRadius,
51103
in: 0...10,
@@ -62,8 +114,13 @@ public struct SpotLightControl: View {
62114
.foregroundColor(.secondary)
63115
}
64116
)
117+
.accessibilityHint(
118+
"Defines light reach and calculates its falloff. Can greatly affect performance, so it should be used sparingly."
119+
)
65120

66121
Text("Inner Angle: \(store.innerAngleInDegrees, format: .number)")
122+
.accessibilityHidden(true)
123+
67124
Slider(
68125
value: $store.innerAngleInDegrees,
69126
in: 0...360,
@@ -75,13 +132,18 @@ public struct SpotLightControl: View {
75132
.foregroundColor(.secondary)
76133
},
77134
maximumValueLabel: {
78-
Text("10º")
135+
Text("360º")
79136
.font(.caption)
80137
.foregroundColor(.secondary)
81138
}
82139
)
140+
.accessibilityHint(
141+
"Defines the angle of the cone that emits light at full intensity, in degrees"
142+
)
83143

84144
Text("Outer Angle: \(store.outerAngleInDegrees, format: .number)")
145+
.accessibilityHidden(true)
146+
85147
Slider(
86148
value: $store.outerAngleInDegrees,
87149
in: 0...360,
@@ -93,32 +155,32 @@ public struct SpotLightControl: View {
93155
.foregroundColor(.secondary)
94156
},
95157
maximumValueLabel: {
96-
Text("10º")
158+
Text("360º")
97159
.font(.caption)
98160
.foregroundColor(.secondary)
99161
}
100162
)
163+
.accessibilityHint(
164+
"Defines the angle of the cone beyond which the light's intensity is zero, in degrees"
165+
)
101166
}
102-
.onChange(of: store.attenuationRadius) { _, newValue in
103-
spotLight.light.attenuationRadius = newValue
104-
}
105-
.onChange(of: store.color) { _, newValue in
106-
spotLight.light.color = UIColor(newValue)
107-
}
108-
.onChange(of: store.intensity) { _, newValue in
109-
spotLight.light.intensity = Float(newValue.lux)
110-
}
111-
.onChange(of: store.innerAngleInDegrees) { _, newValue in
112-
spotLight.light.innerAngleInDegrees = newValue
113-
}
167+
}
168+
}
169+
}
170+
171+
//MARK: - Orientation
114172

115-
//MARK: - Orientation
173+
extension SpotLightControl {
174+
struct OrientationControl: View {
175+
@Bindable var store: StoreOf<SpotLight>
116176

177+
var body: some View {
117178
Section("Orientation") {
118179
Stepper(
119180
"Rotation X: \(store.rotationX.degrees.formatted())",
120181
value: $store.rotationX.degrees
121182
)
183+
.accessibilityHidden(true)
122184

123185
//FIXME: use propper formatters
124186
Slider(
@@ -130,18 +192,21 @@ public struct SpotLightControl: View {
130192
Text("\(Int(store.rotationRange.lowerBound))º")
131193
.font(.caption)
132194
.foregroundColor(.secondary)
195+
.accessibilityHidden(true)
133196
},
134197
maximumValueLabel: {
135198
Text("\(Int(store.rotationRange.upperBound))º")
136199
.font(.caption)
137200
.foregroundColor(.secondary)
201+
.accessibilityHidden(true)
138202
}
139203
)
140204

141205
Stepper(
142206
"Rotation Y: \(store.rotationY.degrees.formatted())",
143207
value: $store.rotationY.degrees
144208
)
209+
.accessibilityHidden(true)
145210

146211
Slider(
147212
value: $store.rotationY.degrees,
@@ -152,36 +217,16 @@ public struct SpotLightControl: View {
152217
Text("\(Int(store.rotationRange.lowerBound))º")
153218
.font(.caption)
154219
.foregroundColor(.secondary)
220+
.accessibilityHidden(true)
155221
},
156222
maximumValueLabel: {
157223
Text("\(Int(store.rotationRange.upperBound))º")
158224
.font(.caption)
159225
.foregroundColor(.secondary)
226+
.accessibilityHidden(true)
160227
}
161228
)
162229
}
163-
.onChange(of: store.orientation) { _, newValue in
164-
spotLight.orientation = newValue
165-
}
166-
.onChange(of: store.outerAngleInDegrees) { _, newValue in
167-
spotLight.light.outerAngleInDegrees = newValue
168-
}
169-
}
170-
.toolbar {
171-
ToolbarItem {
172-
Toggle(
173-
"Enabled",
174-
systemImage: "power.circle",
175-
isOn: $store.isEnabled
176-
)
177-
}
178-
}
179-
.onChange(of: store.isEnabled) { _, newValue in
180-
spotLight.isEnabled = newValue
181230
}
182231
}
183232
}
184-
185-
#Preview {
186-
SpotLightControl(light: .init())
187-
}

0 commit comments

Comments
 (0)