arrow updates.

This commit is contained in:
Kevin G Christiano 2020-04-02 11:47:47 -04:00
parent ed34ae3c19
commit bdda06629f
2 changed files with 45 additions and 20 deletions

View File

@ -20,6 +20,33 @@ open class Arrow: View {
return model as? ArrowModel
}
open var isEnabled: Bool = true {
didSet {
isUserInteractionEnabled = isEnabled
setNeedsDisplay()
}
}
open var disabledColor: UIColor {
get { return arrowModel?.disabledColor.uiColor ?? .mvmCoolGray3 }
set { arrowModel?.disabledColor = Color(uiColor: newValue) }
}
open var color: UIColor {
get { return arrowModel?.color.uiColor ?? .mvmBlack }
set { arrowModel?.color = Color(uiColor: newValue) }
}
open var degrees: Float {
get { return arrowModel?.degrees ?? 0 }
set { arrowModel?.degrees = newValue }
}
open var lineWidth: CGFloat {
get { return arrowModel?.lineWidth ?? 1 }
set { arrowModel?.lineWidth = newValue }
}
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
@ -88,7 +115,7 @@ open class Arrow: View {
private func drawShapeLayer() {
arrowLayer.frame = bounds
arrowLayer.strokeColor = arrowModel?.color.cgColor
arrowLayer.strokeColor = isEnabled ? arrowModel?.color.cgColor : arrowModel?.disabledColor.cgColor
arrowLayer.fillColor = UIColor.clear.cgColor
arrowLayer.path = arrowPath()
arrowLayer.lineJoin = .miter

View File

@ -20,22 +20,20 @@ open class ArrowModel: MoleculeModelProtocol {
public var moleculeName: String?
public var backgroundColor: Color?
public var enabledColor: Color?
public var disabledColor: Color?
public var disabledColor: Color = Color(uiColor: .mvmCoolGray3)
public var color: Color = Color(uiColor: .mvmBlack)
public var degrees: Float = 0
public var lineWidth: CGFloat = 1
public var height: CGFloat = 12
public var width: CGFloat = 12
public var isEnabled: Bool = true
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init() { }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
@ -43,14 +41,13 @@ open class ArrowModel: MoleculeModelProtocol {
private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
case enabledColor
case disabledColor
case color
case degrees
case size
case lineWidth
case height
case width
case isEnabled
}
//--------------------------------------------------
@ -59,17 +56,21 @@ open class ArrowModel: MoleculeModelProtocol {
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
disabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor)
enabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
if let disabledColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
self.disabledColor = disabledColor
}
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) {
self.color = color
}
if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) {
self.isEnabled = isEnabled
}
if let degrees = try typeContainer.decodeIfPresent(Float.self, forKey: .degrees) {
self.degrees = degrees
}
@ -79,7 +80,7 @@ open class ArrowModel: MoleculeModelProtocol {
}
if let height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) {
self.lineWidth = height
self.height = height
}
if let width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) {
@ -89,17 +90,14 @@ open class ArrowModel: MoleculeModelProtocol {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(enabledColor, forKey: .enabledColor)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(disabledColor, forKey: .disabledColor)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(disabledColor, forKey: .disabledColor)
try container.encode(color, forKey: .color)
try container.encode(degrees, forKey: .degrees)
try container.encodeIfPresent(backgroundColor, forKey: .lineWidth)
try container.encode(lineWidth, forKey: .lineWidth)
try container.encode(width, forKey: .width)
try container.encode(height, forKey: .height)
try container.encode(isEnabled, forKey: .isEnabled)
}
}