Skip to content

Commit

Permalink
Merge pull request #15 from spacenation/integers
Browse files Browse the repository at this point in the history
Support for integer types
  • Loading branch information
ay42 committed Apr 27, 2020
2 parents 135aef3 + 608a222 commit b243f93
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This package allows you to build highly customizable sliders and tracks for iOS,

Add this swift package to your project
```
git@github.com:SwiftUIExtensions/Sliders.git
git@github.com:spacenation/swiftui-sliders.git
```

Import and use
Expand Down Expand Up @@ -78,7 +78,6 @@ RangeSlider(range: $model.range2)
- Xcode 11.0+

## Roadmap
- Slider styles
- Circular sliders and tracks

## Code Contributions
Expand Down
18 changes: 18 additions & 0 deletions Sources/Sliders/PointSlider/PointSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ extension PointSlider {
)
}
}

extension PointSlider {
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 {

self.init(
PointSliderStyleConfiguration(
x: Binding(get: { CGFloat(x.wrappedValue) }, set: { x.wrappedValue = V($0) }),
xBounds: CGFloat(xBounds.lowerBound)...CGFloat(xBounds.upperBound),
xStep: CGFloat(xStep),
y: Binding(get: { CGFloat(y.wrappedValue) }, set: { y.wrappedValue = V($0) }),
yBounds: CGFloat(yBounds.lowerBound)...CGFloat(yBounds.upperBound),
yStep: CGFloat(yStep),
onEditingChanged: onEditingChanged,
dragOffset: .constant(.init())
)
)
}
}
18 changes: 18 additions & 0 deletions Sources/Sliders/RangeSlider/RangeSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ extension RangeSlider {
)
}
}

extension RangeSlider {
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 {

self.init(
RangeSliderStyleConfiguration(
range: Binding(
get: { CGFloat(range.wrappedValue.lowerBound)...CGFloat(range.wrappedValue.upperBound) },
set: { range.wrappedValue = V($0.lowerBound)...V($0.upperBound) }
),
bounds: CGFloat(bounds.lowerBound)...CGFloat(bounds.upperBound),
step: CGFloat(step),
onEditingChanged: onEditingChanged,
dragOffset: .constant(0)
)
)
}
}
14 changes: 14 additions & 0 deletions Sources/Sliders/ValueSlider/ValueSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ extension ValueSlider {
)
}
}

extension ValueSlider {
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 {
self.init(
ValueSliderStyleConfiguration(
value: Binding(get: { CGFloat(value.wrappedValue) }, set: { value.wrappedValue = V($0) }),
bounds: CGFloat(bounds.lowerBound)...CGFloat(bounds.upperBound),
step: CGFloat(step),
onEditingChanged: onEditingChanged,
dragOffset: .constant(0)
)
)
}
}

0 comments on commit b243f93

Please sign in to comment.