-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jhrcook/spinner-engine
New spinner engine
- Loading branch information
Showing
11 changed files
with
204 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Workout Spinner WatchKit Extension/Protocols/NumericType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// NumericType.swift | ||
// Workout Spinner WatchKit Extension | ||
// | ||
// Created by Joshua on 1/28/21. | ||
// Copyright © 2021 Joshua Cook. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol NumericType: Comparable { | ||
static func + (lhs: Self, rhs: Self) -> Self | ||
static func - (lhs: Self, rhs: Self) -> Self | ||
static func * (lhs: Self, rhs: Self) -> Self | ||
static func / (lhs: Self, rhs: Self) -> Self | ||
} | ||
|
||
extension Double: NumericType {} | ||
extension Int: NumericType {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Workout Spinner WatchKit Extension/Views/General Components/PlusMinusStepper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// PlusMinusStepper.swift | ||
// Workout Spinner WatchKit Extension | ||
// | ||
// Created by Joshua on 1/28/21. | ||
// Copyright © 2021 Joshua Cook. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PlusMinusStepper<T: NumericType>: View { | ||
@Binding var value: T | ||
let step: T | ||
var min: T? = nil | ||
var max: T? = nil | ||
var label: Text | ||
var extraDownAction: (() -> Void)? = nil | ||
var extraUpAction: (() -> Void)? = nil | ||
|
||
var body: some View { | ||
HStack { | ||
Button(action: { | ||
value = value - step | ||
if let f = extraDownAction { f() } | ||
}, label: { | ||
Image(systemName: "minus.circle").foregroundColor(.red).font(.system(size: 25)) | ||
}) | ||
.disabled(min != nil ? (value - step) < min! : false) | ||
.buttonStyle(PlainButtonStyle()) | ||
.padding(2) | ||
.frame(width: 60) | ||
|
||
Spacer() | ||
|
||
label.padding(3) | ||
|
||
Spacer() | ||
|
||
Button(action: { | ||
value = value + step | ||
if let f = extraUpAction { f() } | ||
}, label: { | ||
Image(systemName: "plus.circle").foregroundColor(.green).font(.system(size: 25)) | ||
}) | ||
.disabled(max != nil ? (value + step) > max! : false) | ||
.buttonStyle(PlainButtonStyle()) | ||
.padding(2) | ||
.frame(width: 60) | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct PlusMinusStepper_Previews: PreviewProvider { | ||
static var previews: some View { | ||
PlusMinusStepper<Int>(value: .constant(3), step: 1, label: Text("3")).previewLayout(.fixed(width: 100, height: 50)) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.