Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit 8845958

Browse files
author
Amir Khorsandi
committed
Set ranges
1 parent c3f2f72 commit 8845958

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

Samples/PagingLayoutSamples/Modules/LayoutDesigner/LayoutDesignerViewModel.swift

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ class LayoutDesignerViewModel {
5353
}
5454

5555
optionViewModels = [
56-
.init(title: "Min scale", kind: .singleSlider(current: options.minScale) { n in
56+
.init(title: "Min scale", kind: .singleSlider(current: options.minScale, range: 0...2) { n in
5757
update { $0.minScale = n! }
5858
}),
59-
.init(title: "Max scale", kind: .singleSlider(current: options.maxScale) { n in
59+
.init(title: "Max scale", kind: .singleSlider(current: options.maxScale, range: 0...2) { n in
6060
update { $0.maxScale = n! }
6161
}),
62-
.init(title: "Scale ratio", kind: .singleSlider(current: options.scaleRatio) { n in
62+
.init(title: "Scale ratio", kind: .singleSlider(current: options.scaleRatio, range: 0...2) { n in
6363
update { $0.scaleRatio = n! }
6464
}),
65-
.init(title: "Translation ratio", kind: .doubleSlider(current: options.translationRatio.pair) { n in
65+
.init(title: "Translation ratio", kind: .doubleSlider(current: options.translationRatio.pair, range: -2...2) { n in
6666
update { $0.translationRatio = .by(pair: n!) }
6767
}),
68-
.init(title: "Min translation ratio", kind: .doubleSlider(current: options.minTranslationRatio?.pair, optional: true) { n in
68+
.init(title: "Min translation ratio", kind: .doubleSlider(current: options.minTranslationRatio?.pair, range: -5...5, optional: true) { n in
6969
update { $0.minTranslationRatio = n.map { .by(pair: $0) } }
7070
}),
71-
.init(title: "Max translation ratio", kind: .doubleSlider(current: options.maxTranslationRatio?.pair, optional: true) { n in
71+
.init(title: "Max translation ratio", kind: .doubleSlider(current: options.maxTranslationRatio?.pair, range: -5...5, optional: true) { n in
7272
update { $0.maxTranslationRatio = n.map { .by(pair: $0) } }
7373
}),
7474
.init(title: "Keep vertical spacing equal", kind: .toggleSwitch(current: options.keepVerticalSpacingEqual) { n in
@@ -79,6 +79,9 @@ class LayoutDesignerViewModel {
7979
}),
8080
.init(title: "Scale curve", kind: .segmented(options: TransformCurve.all.map(\.name), current: options.scaleCurve.name) { n in
8181
update { $0.scaleCurve = .by(name: n)! }
82+
}),
83+
.init(title: "Translation curve", kind: .segmented(options: TransformCurve.all.map(\.name), current: options.translationCurve.name) { n in
84+
update { $0.translationCurve = .by(name: n)! }
8285
})
8386
]
8487
} else if var options = selectedLayout.stackOptions {
@@ -88,7 +91,7 @@ class LayoutDesignerViewModel {
8891
}
8992

9093
optionViewModels = [
91-
.init(title: "Scale factor", kind: .singleSlider(current: options.scaleFactor) { n in
94+
.init(title: "Scale factor", kind: .singleSlider(current: options.scaleFactor, range: -1...1) { n in
9295
update { $0.scaleFactor = n! }
9396
}),
9497
.init(title: "Min scale", kind: .singleSlider(current: options.minScale, optional: true) { n in
@@ -97,7 +100,7 @@ class LayoutDesignerViewModel {
97100
.init(title: "Max scale", kind: .singleSlider(current: options.maxScale, optional: true) { n in
98101
update { $0.maxScale = n }
99102
}),
100-
.init(title: "Spacing factor", kind: .singleSlider(current: options.spacingFactor) { n in
103+
.init(title: "Spacing factor", kind: .singleSlider(current: options.spacingFactor, range: 0...0.5) { n in
101104
update { $0.spacingFactor = n! }
102105
}),
103106
.init(title: "Max spacing", kind: .singleSlider(current: options.maxSpacing, optional: true) { n in
@@ -106,13 +109,13 @@ class LayoutDesignerViewModel {
106109
.init(title: "Alpha factor", kind: .singleSlider(current: options.alphaFactor) { n in
107110
update { $0.alphaFactor = n! }
108111
}),
109-
.init(title: "Bottom stack alpha speed factor", kind: .singleSlider(current: options.bottomStackAlphaSpeedFactor) { n in
112+
.init(title: "Bottom stack alpha speed factor", kind: .singleSlider(current: options.bottomStackAlphaSpeedFactor, range: 0...10) { n in
110113
update { $0.bottomStackAlphaSpeedFactor = n! }
111114
}),
112-
.init(title: "Top stack alpha speed factor", kind: .singleSlider(current: options.topStackAlphaSpeedFactor) { n in
115+
.init(title: "Top stack alpha speed factor", kind: .singleSlider(current: options.topStackAlphaSpeedFactor, range: 0...10) { n in
113116
update { $0.topStackAlphaSpeedFactor = n! }
114117
}),
115-
.init(title: "Perspective ratio", kind: .singleSlider(current: options.perspectiveRatio) { n in
118+
.init(title: "Perspective ratio", kind: .singleSlider(current: options.perspectiveRatio, range: -1...1) { n in
116119
update { $0.perspectiveRatio = n! }
117120
}),
118121
.init(title: "Shadow enabled", kind: .toggleSwitch(current: options.shadowEnabled) { n in
@@ -124,19 +127,19 @@ class LayoutDesignerViewModel {
124127
.init(title: "Shadow offset", kind: .doubleSlider(current: options.shadowOffset.pair) { n in
125128
update { $0.shadowOffset = .by(pair: n!) }
126129
}),
127-
.init(title: "Shadow radius", kind: .singleSlider(current: options.shadowRadius) { n in
130+
.init(title: "Shadow radius", kind: .singleSlider(current: options.shadowRadius, range: 1...10) { n in
128131
update { $0.shadowRadius = n! }
129132
}),
130-
.init(title: "Rotate angel", kind: .singleSlider(current: options.stackRotateAngel) { n in
133+
.init(title: "Rotate angel", kind: .singleSlider(current: options.stackRotateAngel, range: -CGFloat.pi...CGFloat.pi) { n in
131134
update { $0.stackRotateAngel = n! }
132135
}),
133-
.init(title: "Pop angle", kind: .singleSlider(current: options.popAngle) { n in
136+
.init(title: "Pop angle", kind: .singleSlider(current: options.popAngle, range: -CGFloat.pi...CGFloat.pi) { n in
134137
update { $0.popAngle = n! }
135138
}),
136-
.init(title: "Pop offset ratio", kind: .doubleSlider(current: options.popOffsetRatio.pair) { n in
139+
.init(title: "Pop offset ratio", kind: .doubleSlider(current: options.popOffsetRatio.pair, range: -2...2) { n in
137140
update { $0.popOffsetRatio = .by(pair: n!) }
138141
}),
139-
.init(title: "Stack position", kind: .doubleSlider(current: options.stackPosition.pair) { n in
142+
.init(title: "Stack position", kind: .doubleSlider(current: options.stackPosition.pair, range: -1...1) { n in
140143
update { $0.stackPosition = .by(pair: n!) }
141144
}),
142145
.init(title: "Reverse", kind: .toggleSwitch(current: options.reverse) { n in
@@ -158,19 +161,19 @@ class LayoutDesignerViewModel {
158161
self?.update(options: &options, closure: $0)
159162
}
160163
optionViewModels = [
161-
.init(title: "Piece size ratio", kind: .doubleSlider(current: options.pieceSizeRatio.pair) { n in
164+
.init(title: "Piece size ratio", kind: .doubleSlider(current: options.pieceSizeRatio.pair, range: 0.01...1) { n in
162165
update { $0.pieceSizeRatio = .by(pair: n!) }
163166
}),
164167
.init(title: "Container scale ratio", kind: .singleSlider(current: options.containerScaleRatio) { n in
165168
update { $0.containerScaleRatio = n! }
166169
}),
167-
.init(title: "Container translation ratio", kind: .doubleSlider(current: options.containerTranslationRatio.pair) { n in
170+
.init(title: "Container translation ratio", kind: .doubleSlider(current: options.containerTranslationRatio.pair, range: 0...2) { n in
168171
update { $0.containerTranslationRatio = .by(pair: n!) }
169172
}),
170-
.init(title: "Container min translation ratio", kind: .doubleSlider(current: options.containerMinTranslationRatio?.pair, optional: true) { n in
173+
.init(title: "Container min translation ratio", kind: .doubleSlider(current: options.containerMinTranslationRatio?.pair, range: 0...2, optional: true) { n in
171174
update { $0.containerMinTranslationRatio = n.map { .by(pair: $0) } }
172175
}),
173-
.init(title: "Container max translation ratio", kind: .doubleSlider(current: options.containerMaxTranslationRatio?.pair, optional: true) { n in
176+
.init(title: "Container max translation ratio", kind: .doubleSlider(current: options.containerMaxTranslationRatio?.pair, range: 0...2, optional: true) { n in
174177
update { $0.containerMaxTranslationRatio = n.map { .by(pair: $0) } }
175178
})
176179
]

Samples/PagingLayoutSamples/Modules/LayoutDesigner/Options/cell/LayoutDesignerOptionCell.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ class LayoutDesignerOptionCell: UITableViewCell, NibBased {
144144

145145
switch viewModel.kind {
146146

147-
case let .singleSlider(current, optional, onChange):
147+
case let .singleSlider(current, range, optional, onChange):
148148
singleSlider.isHidden = false
149149
singleSliderInput.isHidden = false
150150
singleSliderInput.set(value: current ?? 0)
151151
singleSlider.value = Float(current ?? 0)
152+
singleSlider.maximumValue = Float(range.upperBound)
153+
singleSlider.minimumValue = Float(range.lowerBound)
152154
onSingleSliderChange = onChange
153155
if optional {
154156
switchView.isHidden = false
@@ -163,13 +165,17 @@ class LayoutDesignerOptionCell: UITableViewCell, NibBased {
163165
onSwitchChange(switchView.isOn)
164166
}
165167

166-
case let .doubleSlider(current, optional, onChange):
168+
case let .doubleSlider(current, range, optional, onChange):
167169
doubleSliderStackView.isHidden = false
168170
doubleSliderStackView.alpha = 1
169171
doubleSliderInput1.set(value: current?.0 ?? 0)
170172
doubleSlider1.value = Float(current?.0 ?? 0)
171173
doubleSliderInput2.set(value: current?.1 ?? 0)
172174
doubleSlider2.value = Float(current?.1 ?? 0)
175+
doubleSlider1.maximumValue = Float(range.upperBound)
176+
doubleSlider2.maximumValue = Float(range.upperBound)
177+
doubleSlider1.minimumValue = Float(range.lowerBound)
178+
doubleSlider2.minimumValue = Float(range.lowerBound)
173179
let getValues = { [weak self] in self.map { (CGFloat($0.doubleSlider1.value), CGFloat($0.doubleSlider2.value)) } }
174180

175181
onDoubleSlider1Change = { _ in onChange(getValues()) }

Samples/PagingLayoutSamples/Modules/LayoutDesigner/Options/cell/LayoutDesignerOptionCellViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class LayoutDesignerOptionCellViewModel {
1414
// MARK: Constants
1515

1616
enum Kind {
17-
case singleSlider(current: CGFloat?, optional: Bool = false, onChange: (CGFloat?) -> Void)
18-
case doubleSlider(current: (CGFloat, CGFloat)?, optional: Bool = false, onChange: ((CGFloat, CGFloat)?) -> Void)
17+
case singleSlider(current: CGFloat?, range: ClosedRange<CGFloat> = 0...1, optional: Bool = false, onChange: (CGFloat?) -> Void)
18+
case doubleSlider(current: (CGFloat, CGFloat)?, range: ClosedRange<CGFloat> = 0...1, optional: Bool = false, onChange: ((CGFloat, CGFloat)?) -> Void)
1919
case toggleSwitch(current: Bool, onChange: (Bool) -> Void)
2020
case segmented(options: [String], current: String, onChange: (String) -> Void)
2121
}

0 commit comments

Comments
 (0)