Refactored enums to look more swifty and shortened

This commit is contained in:
Zachary Duncan
2022-06-13 16:07:24 -04:00
committed by Zachary Duncan
parent 2819f1fd84
commit 5c44226a0c
13 changed files with 118 additions and 118 deletions

View File

@@ -28,14 +28,14 @@ class LayoutViewController: UIViewController {
func setFit(name: String = "") {
var fit: Fit = .fitContain
switch name {
case "Fill": fit = .fitFill
case "Contain": fit = .fitContain
case "Cover": fit = .fitCover
case "Fit Width": fit = .fitFitWidth
case "Fit Height": fit = .fitFitHeight
case "Scale Down": fit = .fitScaleDown
case "None": fit = .fitNone
default: fit = .fitContain
case "Fill": fit = .fill
case "Contain": fit = .contain
case "Cover": fit = .cover
case "Fit Width": fit = .fitWidth
case "Fit Height": fit = .fitHeight
case "Scale Down": fit = .scaleDown
case "None": fit = .noFit
default: fit = .contain
}
viewModel.fit = fit
}
@@ -43,16 +43,16 @@ class LayoutViewController: UIViewController {
func setAlignment(name: String = "") {
var alignment: Alignment = .alignmentCenter
switch name {
case "Top Left": alignment = .alignmentTopLeft
case "Top Center": alignment = .alignmentTopCenter
case "Top Right": alignment = .alignmentTopRight
case "Center Left": alignment = .alignmentCenterLeft
case "Center": alignment = .alignmentCenter
case "Center Right": alignment = .alignmentCenterRight
case "Bottom Left": alignment = .alignmentBottomLeft
case "Bottom Center": alignment = .alignmentBottomCenter
case "Bottom Right": alignment = .alignmentBottomRight
default: alignment = .alignmentCenter
case "Top Left": alignment = .topLeft
case "Top Center": alignment = .topCenter
case "Top Right": alignment = .topRight
case "Center Left": alignment = .centerLeft
case "Center": alignment = .center
case "Center Right": alignment = .centerRight
case "Bottom Left": alignment = .bottomLeft
case "Bottom Center": alignment = .bottomCenter
case "Bottom Right": alignment = .bottomRight
default: alignment = .center
}
viewModel.alignment = alignment
}

View File

@@ -12,8 +12,8 @@ import RiveRuntime
struct SwiftLayout: DismissableView {
var dismiss: () -> Void = {}
@State private var fit = Fit.fitContain
@State private var alignment = Alignment.alignmentCenter
@State private var fit: RiveFit = .contain
@State private var alignment: RiveAlignment = .center
var body: some View {
VStack {
@@ -23,35 +23,35 @@ struct SwiftLayout: DismissableView {
Text("Fit")
}
HStack {
Button("Fill", action: {fit = .fitFill})
Button("Contain", action: {fit = .fitContain})
Button("Cover", action: {fit = .fitCover})
Button("Fill", action: {fit = .fill})
Button("Contain", action: {fit = .contain})
Button("Cover", action: {fit = .cover})
}
HStack {
Button("Fit Width", action: {fit = .fitFitWidth})
Button("Fit Height", action: {fit = .fitFitHeight})
Button("Scale Down", action: {fit = .fitScaleDown})
Button("Fit Width", action: {fit = .fitWidth})
Button("Fit Height", action: {fit = .fitHeight})
Button("Scale Down", action: {fit = .scaleDown})
}
HStack {
Button("None", action: {fit = .fitNone})
Button("None", action: {fit = .noFit})
}
HStack {
Text("Alignment")
}
HStack {
Button("Top Left", action: {alignment = .alignmentTopLeft})
Button("Top Center", action: {alignment = .alignmentTopCenter})
Button("Top Right", action: {alignment = .alignmentTopRight})
Button("Top Left", action: {alignment = .topLeft})
Button("Top Center", action: {alignment = .topCenter})
Button("Top Right", action: {alignment = .topRight})
}
HStack {
Button("Center Left", action: {alignment = .alignmentCenterLeft})
Button("Center", action: {alignment = .alignmentCenter})
Button("Center Right", action: {alignment = .alignmentCenterRight})
Button("Center Left", action: {alignment = .centerLeft})
Button("Center", action: {alignment = .center})
Button("Center Right", action: {alignment = .centerRight})
}
HStack {
Button("Bottom Left", action: {alignment = .alignmentBottomLeft})
Button("Bottom Center", action: {alignment = .alignmentBottomCenter})
Button("Bottom Right", action: {alignment = .alignmentBottomRight})
Button("Bottom Left", action: {alignment = .bottomLeft})
Button("Bottom Center", action: {alignment = .bottomCenter})
Button("Bottom Right", action: {alignment = .bottomRight})
}
}
}

View File

@@ -14,7 +14,7 @@ class RiveButton: RiveViewModel {
var action: (() -> Void)? = nil
init(fileName: String = "rbutton") {
super.init(fileName: fileName, stateMachineName: "State Machine 1", fit: .fitCover, autoPlay: false)
super.init(fileName: fileName, stateMachineName: "State Machine 1", fit: .cover, autoPlay: false)
}
func view(_ action: (() -> Void)?) -> some View {

View File

@@ -18,7 +18,7 @@ class RiveProgressBar: RiveViewModel {
init(_ initialProgress: Double = 0) {
progress = initialProgress
super.init(fileName: "energy_bar_example", stateMachineName: "State Machine ", fit: .fitCover)
super.init(fileName: "energy_bar_example", stateMachineName: "State Machine ", fit: .cover)
}
override func view() -> AnyView {

View File

@@ -18,7 +18,7 @@ class RiveSlider: RiveViewModel {
init(_ initialProgress: Double = 0) {
progress = initialProgress
super.init(fileName: "riveslider", stateMachineName: "Slide", fit: .fitScaleDown)
super.init(fileName: "riveslider", stateMachineName: "Slide", fit: .scaleDown)
}
func touchBegan(onArtboard artboard: RiveArtboard?, atLocation location: CGPoint) {

View File

@@ -24,7 +24,7 @@ class RiveSwitch: RiveViewModel {
}
init() {
super.init(fileName: "switch", animationName: startAnimation, fit: .fitCover)
super.init(fileName: "switch", animationName: startAnimation, fit: .cover)
}
func view(_ action: ((Bool) -> Void)? = nil) -> some View {