@@ -24,7 +24,7 @@ class LayoutDesignerViewModel {
24
24
var shapesViewModel : ShapesViewModel {
25
25
ShapesViewModel ( layouts: layouts, showBackButton: false )
26
26
}
27
- private( set) var optionViewModels : [ LayoutDesignerOptionCellViewModel ] = [ ]
27
+ private( set) var optionViewModels : [ LayoutDesignerOptionSectionViewModel ] = [ ]
28
28
private let codeGenerator = OptionsCodeGenerator ( )
29
29
30
30
@@ -52,7 +52,7 @@ class LayoutDesignerViewModel {
52
52
self ? . update ( options: & options, closure: $0)
53
53
}
54
54
55
- optionViewModels = [
55
+ let generalOptions : [ LayoutDesignerOptionViewModel ] = [
56
56
. init( title: " Min scale " , kind: . singleSlider( current: options. minScale, range: 0 ... 2 ) { n in
57
57
update { $0. minScale = n! }
58
58
} ) ,
@@ -82,15 +82,158 @@ class LayoutDesignerViewModel {
82
82
} ) ,
83
83
. init( title: " Translation curve " , kind: . segmented( options: TransformCurve . all. map ( \. name) , current: options. translationCurve. name) { n in
84
84
update { $0. translationCurve = . by( name: n) ! }
85
+ } ) ,
86
+ . init( title: " Shadow enabled " , kind: . toggleSwitch( current: options. shadowEnabled) { n in
87
+ update { $0. shadowEnabled = n }
88
+ } ) ,
89
+ . init( title: " Shadow opacity " , kind: . singleSlider( current: CGFloat ( options. shadowOpacity) ) { n in
90
+ update { $0. shadowOpacity = Float ( n!) }
91
+ } ) ,
92
+ . init( title: " Shadow opacity min " , kind: . singleSlider( current: CGFloat ( options. shadowOpacityMin) ) { n in
93
+ update { $0. shadowOpacityMin = Float ( n!) }
94
+ } ) ,
95
+ . init( title: " Shadow opacity max " , kind: . singleSlider( current: CGFloat ( options. shadowOpacityMax) ) { n in
96
+ update { $0. shadowOpacityMax = Float ( n!) }
97
+ } ) ,
98
+ . init( title: " Shadow radius max " , kind: . singleSlider( current: options. shadowRadiusMax, range: 0 ... 15 ) { n in
99
+ update { $0. shadowRadiusMax = n! }
100
+ } ) ,
101
+ . init( title: " Shadow radius min " , kind: . singleSlider( current: options. shadowRadiusMin, range: 0 ... 15 ) { n in
102
+ update { $0. shadowRadiusMin = n! }
103
+ } ) ,
104
+ . init( title: " Shadow offset min " , kind: . doubleSlider( current: options. shadowOffsetMin. pair, range: - 7 ... 7 ) { n in
105
+ update { $0. shadowOffsetMin = . by( pair: n!) }
106
+ } ) ,
107
+ . init( title: " Shadow offset max " , kind: . doubleSlider( current: options. shadowOffsetMax. pair, range: - 7 ... 7 ) { n in
108
+ update { $0. shadowOffsetMax = . by( pair: n!) }
109
+ } ) ,
110
+ . init( title: " Blur effect enabled " , kind: . toggleSwitch( current: options. blurEffectEnabled) { n in
111
+ update { $0. blurEffectEnabled = n }
112
+ } ) ,
113
+ . init( title: " Blur effect radius ratio " , kind: . singleSlider( current: options. blurEffectRadiusRatio) { n in
114
+ update { $0. blurEffectRadiusRatio = n! }
115
+ } ) ,
116
+ . init( title: " Blur effect style " , kind: . segmented( options: UIBlurEffect . Style. all. map ( \. name) , current: options. blurEffectStyle. name) { n in
117
+ update { $0. blurEffectStyle = . by( name: n) ! }
118
+ } )
119
+ ]
120
+
121
+ let originalRotation3dOptions = options. rotation3d ?? ScaleTransformViewOptions . Rotation3dOptions (
122
+ angle: . pi / 3 ,
123
+ minAngle: 0 ,
124
+ maxAngle: . pi,
125
+ x: 0 ,
126
+ y: 1 ,
127
+ z: 0 ,
128
+ m34: - 0.000_1
129
+ )
130
+
131
+ let rotation3dOptions : [ LayoutDesignerOptionViewModel ] = [
132
+ . init( title: " Enabled " , kind: . toggleSwitch( current: options. rotation3d != nil ) { n in
133
+ update { $0. rotation3d = !n ? nil : originalRotation3dOptions }
134
+ } ) ,
135
+ . init( title: " Angle " , kind: . singleSlider( current: options. rotation3d? . angle, range: - . pi... CGFloat . pi) { n in
136
+ update { $0. rotation3d? . angle = n! }
137
+ } ) ,
138
+ . init( title: " Min angle " , kind: . singleSlider( current: options. rotation3d? . minAngle, range: - . pi... CGFloat . pi) { n in
139
+ update { $0. rotation3d? . minAngle = n! }
140
+ } ) ,
141
+ . init( title: " Max angle " , kind: . singleSlider( current: options. rotation3d? . maxAngle, range: - . pi... CGFloat . pi) { n in
142
+ update { $0. rotation3d? . maxAngle = n! }
143
+ } ) ,
144
+ . init( title: " X " , kind: . singleSlider( current: options. rotation3d? . x, range: - 1 ... 1 ) { n in
145
+ update { $0. rotation3d? . x = n! }
146
+ } ) ,
147
+ . init( title: " Y " , kind: . singleSlider( current: options. rotation3d? . y, range: - 1 ... 1 ) { n in
148
+ update { $0. rotation3d? . y = n! }
149
+ } ) ,
150
+ . init( title: " Z " , kind: . singleSlider( current: options. rotation3d? . z, range: - 1 ... 1 ) { n in
151
+ update { $0. rotation3d? . z = n! }
152
+ } ) ,
153
+ . init( title: " m34 " , kind: . singleSlider( current: options. rotation3d. map { $0. m34 * 1_000 } , range: - 2 ... 2 ) { n in
154
+ update { $0. rotation3d? . m34 = n! / 1_000 }
155
+ } )
156
+ ]
157
+
158
+ let originalTranslation3dOptions = options. translation3d ?? ScaleTransformViewOptions . Translation3dOptions (
159
+ translateRatios: ( 30 , 0 , - 375 * 0.42 ) ,
160
+ minTranslates: ( - 30 , 0 , - 1_000 ) ,
161
+ maxTranslates: ( 30 , 0 , 0 )
162
+ )
163
+
164
+ let translation3dOptions : [ LayoutDesignerOptionViewModel ] = [
165
+ . init( title: " Enabled " , kind: . toggleSwitch( current: options. translation3d != nil ) { n in
166
+ update { $0. translation3d = !n ? nil : originalTranslation3dOptions }
167
+ } ) ,
168
+ . init( title: " X ratio " , kind: . singleSlider( current: options. translation3d? . translateRatios. 0 , range: - 500 ... 500 ) { n in
169
+ update {
170
+ guard let current = $0. translation3d? . translateRatios else { return }
171
+ $0. translation3d? . translateRatios = ( n!, current. 1 , current. 2 )
172
+ }
173
+ } ) ,
174
+ . init( title: " Y ratio " , kind: . singleSlider( current: options. translation3d? . translateRatios. 1 , range: - 500 ... 500 ) { n in
175
+ update {
176
+ guard let current = $0. translation3d? . translateRatios else { return }
177
+ $0. translation3d? . translateRatios = ( current. 0 , n!, current. 2 )
178
+ }
179
+ } ) ,
180
+ . init( title: " Z ratio " , kind: . singleSlider( current: options. translation3d? . translateRatios. 2 , range: - 500 ... 500 ) { n in
181
+ update {
182
+ guard let current = $0. translation3d? . translateRatios else { return }
183
+ $0. translation3d? . translateRatios = ( current. 0 , current. 1 , n!)
184
+ }
185
+ } ) ,
186
+ . init( title: " X min " , kind: . singleSlider( current: options. translation3d? . minTranslates. 0 , range: - 2_000 ... 2_000 ) { n in
187
+ update {
188
+ guard let current = $0. translation3d? . minTranslates else { return }
189
+ $0. translation3d? . minTranslates = ( n!, current. 1 , current. 2 )
190
+ }
191
+ } ) ,
192
+ . init( title: " X max " , kind: . singleSlider( current: options. translation3d? . maxTranslates. 0 , range: - 2_000 ... 2_000 ) { n in
193
+ update {
194
+ guard let current = $0. translation3d? . maxTranslates else { return }
195
+ $0. translation3d? . maxTranslates = ( n!, current. 1 , current. 2 )
196
+ }
197
+ } ) ,
198
+ . init( title: " Y min " , kind: . singleSlider( current: options. translation3d? . minTranslates. 1 , range: - 2_000 ... 2_000 ) { n in
199
+ update {
200
+ guard let current = $0. translation3d? . minTranslates else { return }
201
+ $0. translation3d? . minTranslates = ( current. 0 , n!, current. 2 )
202
+ }
203
+ } ) ,
204
+ . init( title: " Y max " , kind: . singleSlider( current: options. translation3d? . maxTranslates. 1 , range: - 2_000 ... 2_000 ) { n in
205
+ update {
206
+ guard let current = $0. translation3d? . maxTranslates else { return }
207
+ $0. translation3d? . maxTranslates = ( current. 0 , n!, current. 2 )
208
+ }
209
+ } ) ,
210
+ . init( title: " Z min " , kind: . singleSlider( current: options. translation3d? . minTranslates. 2 , range: - 2_000 ... 2_000 ) { n in
211
+ update {
212
+ guard let current = $0. translation3d? . minTranslates else { return }
213
+ $0. translation3d? . minTranslates = ( current. 0 , current. 1 , n!)
214
+ }
215
+ } ) ,
216
+ . init( title: " Z max " , kind: . singleSlider( current: options. translation3d? . maxTranslates. 2 , range: - 2_000 ... 2_000 ) { n in
217
+ update {
218
+ guard let current = $0. translation3d? . maxTranslates else { return }
219
+ $0. translation3d? . maxTranslates = ( current. 0 , current. 1 , n!)
220
+ }
85
221
} )
86
222
]
223
+
224
+
225
+ optionViewModels = [
226
+ . init( title: " Options " , items: generalOptions) ,
227
+ . init( title: " Rotation 3D options " , items: rotation3dOptions) ,
228
+ . init( title: " Translation 3D options " , items: translation3dOptions)
229
+ ]
87
230
} else if var options = selectedLayout. stackOptions {
88
231
updateCodePreview ( options: options)
89
232
let update : ( ( inout StackTransformViewOptions ) -> Void ) -> Void = { [ weak self] in
90
233
self ? . update ( options: & options, closure: $0)
91
234
}
92
235
93
- optionViewModels = [
236
+ let options : [ LayoutDesignerOptionViewModel ] = [
94
237
. init( title: " Scale factor " , kind: . singleSlider( current: options. scaleFactor, range: - 1 ... 1 ) { n in
95
238
update { $0. scaleFactor = n! }
96
239
} ) ,
@@ -155,12 +298,16 @@ class LayoutDesignerViewModel {
155
298
update { $0. blurEffectStyle = . by( name: n) ! }
156
299
} )
157
300
]
301
+
302
+ optionViewModels = [
303
+ . init( title: " Options " , items: options)
304
+ ]
158
305
} else if var options = selectedLayout. snapshotOptions {
159
306
updateCodePreview ( options: options)
160
307
let update : ( ( inout SnapshotTransformViewOptions ) -> Void ) -> Void = { [ weak self] in
161
308
self ? . update ( options: & options, closure: $0)
162
309
}
163
- optionViewModels = [
310
+ let options : [ LayoutDesignerOptionViewModel ] = [
164
311
. init( title: " Piece size ratio " , kind: . doubleSlider( current: options. pieceSizeRatio. pair, range: 0.01 ... 1 ) { n in
165
312
update { $0. pieceSizeRatio = . by( pair: n!) }
166
313
} ) ,
@@ -177,6 +324,9 @@ class LayoutDesignerViewModel {
177
324
update { $0. containerMaxTranslationRatio = n. map { . by( pair: $0) } }
178
325
} )
179
326
]
327
+ optionViewModels = [
328
+ . init( title: " Options " , items: options)
329
+ ]
180
330
}
181
331
}
182
332
0 commit comments