-
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.
added state attribute and drawing color based on state. additionally …
…moved to using gesture recognizers to more easily see taps vs drags. updated the README quite a bit.
- Loading branch information
Showing
4 changed files
with
166 additions
and
30 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
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,42 @@ | ||
import HexGrid | ||
import UIKit | ||
|
||
extension Cell { | ||
|
||
fileprivate static let kStateAttribute: String = "kStateAttribute-key" | ||
|
||
public enum State: Int { | ||
case empty | ||
case tapped | ||
case touchStarted | ||
case touchContinued | ||
case touchEnded | ||
|
||
public var color: UIColor { | ||
switch self { | ||
case .empty: | ||
return UIColor.lightGray | ||
case .tapped: | ||
return .systemOrange | ||
case .touchStarted: | ||
return UIColor(red: 59/256, green: 172/256, blue: 182/256, alpha: 1.0) | ||
case .touchContinued: | ||
return UIColor(red: 130/256, green: 219/256, blue: 216/256, alpha: 1.0) | ||
case .touchEnded: | ||
return UIColor(red: 179/256, green: 232/256, blue: 229/256, alpha: 1.0) | ||
} | ||
} | ||
} | ||
|
||
fileprivate var stateInt : Int { | ||
return self.attributes[Cell.kStateAttribute]?.value as? Int ?? -1 | ||
} | ||
|
||
var state: State { | ||
return State(rawValue: stateInt) ?? .empty | ||
} | ||
|
||
func setState(to: State) { | ||
self.attributes[Cell.kStateAttribute] = .init(to.rawValue) | ||
} | ||
} |
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