Skip to content

Commit b243f93

Browse files
authored
Merge pull request #15 from spacenation/integers
Support for integer types
2 parents 135aef3 + 608a222 commit b243f93

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This package allows you to build highly customizable sliders and tracks for iOS,
2323

2424
Add this swift package to your project
2525
```
26-
[email protected]:SwiftUIExtensions/Sliders.git
26+
[email protected]:spacenation/swiftui-sliders.git
2727
```
2828

2929
Import and use
@@ -78,7 +78,6 @@ RangeSlider(range: $model.range2)
7878
- Xcode 11.0+
7979

8080
## Roadmap
81-
- Slider styles
8281
- Circular sliders and tracks
8382

8483
## Code Contributions

Sources/Sliders/PointSlider/PointSlider.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,21 @@ extension PointSlider {
3636
)
3737
}
3838
}
39+
40+
extension PointSlider {
41+
public init<V>(x: Binding<V>, xBounds: ClosedRange<V> = 0...1, xStep: V.Stride = 1, y: Binding<V>, yBounds: ClosedRange<V> = 0...1, yStep: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V : BinaryInteger, V.Stride : BinaryInteger {
42+
43+
self.init(
44+
PointSliderStyleConfiguration(
45+
x: Binding(get: { CGFloat(x.wrappedValue) }, set: { x.wrappedValue = V($0) }),
46+
xBounds: CGFloat(xBounds.lowerBound)...CGFloat(xBounds.upperBound),
47+
xStep: CGFloat(xStep),
48+
y: Binding(get: { CGFloat(y.wrappedValue) }, set: { y.wrappedValue = V($0) }),
49+
yBounds: CGFloat(yBounds.lowerBound)...CGFloat(yBounds.upperBound),
50+
yStep: CGFloat(yStep),
51+
onEditingChanged: onEditingChanged,
52+
dragOffset: .constant(.init())
53+
)
54+
)
55+
}
56+
}

Sources/Sliders/RangeSlider/RangeSlider.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,21 @@ extension RangeSlider {
3636
)
3737
}
3838
}
39+
40+
extension RangeSlider {
41+
public init<V>(range: Binding<ClosedRange<V>>, in bounds: ClosedRange<V> = 0...1, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V : BinaryInteger, V.Stride : BinaryInteger {
42+
43+
self.init(
44+
RangeSliderStyleConfiguration(
45+
range: Binding(
46+
get: { CGFloat(range.wrappedValue.lowerBound)...CGFloat(range.wrappedValue.upperBound) },
47+
set: { range.wrappedValue = V($0.lowerBound)...V($0.upperBound) }
48+
),
49+
bounds: CGFloat(bounds.lowerBound)...CGFloat(bounds.upperBound),
50+
step: CGFloat(step),
51+
onEditingChanged: onEditingChanged,
52+
dragOffset: .constant(0)
53+
)
54+
)
55+
}
56+
}

Sources/Sliders/ValueSlider/ValueSlider.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,17 @@ extension ValueSlider {
3333
)
3434
}
3535
}
36+
37+
extension ValueSlider {
38+
public init<V>(value: Binding<V>, in bounds: ClosedRange<V> = 0...1, step: V.Stride = 1, onEditingChanged: @escaping (Bool) -> Void = { _ in }) where V : BinaryInteger, V.Stride : BinaryInteger {
39+
self.init(
40+
ValueSliderStyleConfiguration(
41+
value: Binding(get: { CGFloat(value.wrappedValue) }, set: { value.wrappedValue = V($0) }),
42+
bounds: CGFloat(bounds.lowerBound)...CGFloat(bounds.upperBound),
43+
step: CGFloat(step),
44+
onEditingChanged: onEditingChanged,
45+
dragOffset: .constant(0)
46+
)
47+
)
48+
}
49+
}

0 commit comments

Comments
 (0)