changes for inversion

This commit is contained in:
Kevin G Christiano 2020-05-13 14:25:45 -04:00
parent 0d601d6b96
commit 7b2d684c4e
3 changed files with 82 additions and 23 deletions

View File

@ -9,7 +9,6 @@
open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Constants // MARK: - Constants
//------------------------------------------------------ //------------------------------------------------------
@ -123,7 +122,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true
contentHorizontalAlignment = .left contentHorizontalAlignment = .left
//set correct color after layout // Set correct color after layout
changeCaretColor() changeCaretColor()
} }
@ -135,6 +134,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Atomization // MARK: - Atomization
//------------------------------------------------------ //------------------------------------------------------
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
guard let model = model as? CaretLinkModel else { return } guard let model = model as? CaretLinkModel else { return }
@ -143,7 +143,8 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol {
backgroundColor = color.uiColor backgroundColor = color.uiColor
} }
enabledColor = model.enabledColor.uiColor enabledColor = (model.inverted ? model.enabled_inverted : model.enabledColor).uiColor
if let color = model.disabledColor { if let color = model.disabledColor {
disabledColor = color.uiColor disabledColor = color.uiColor
} }

View File

@ -9,43 +9,77 @@
import Foundation import Foundation
import MVMCore import MVMCore
public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol { public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "caretLink" public static var identifier: String = "caretLink"
public var backgroundColor: Color? public var backgroundColor: Color?
public var title: String public var title: String
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var enabledColor: Color = Color(uiColor: .black) public var enabledColor: Color = Color(uiColor: .mvmBlack)
public var disabledColor: Color? = Color(uiColor: .mvmCoolGray6) public var disabledColor: Color? = Color(uiColor: .mvmCoolGray6)
public var enabled_inverted: Color = Color(uiColor: .mvmWhite)
public var enabled = true public var enabled = true
public var inverted = false
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(title: String, action: ActionModelProtocol) { public init(title: String, action: ActionModelProtocol) {
self.title = title self.title = title
self.action = action self.action = action
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case backgroundColor case backgroundColor
case title case title
case action case action
case enabled_inverted
case enabledColor case enabledColor
case disabledColor case disabledColor
case enabled case enabled
case inverted
case moleculeName case moleculeName
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
title = try typeContainer.decode(String.self, forKey: .title) title = try typeContainer.decode(String.self, forKey: .title)
if let enabled_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabled_inverted) {
self.enabled_inverted = enabled_inverted
}
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor) {
enabledColor = color enabledColor = color
} }
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) { if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledColor) {
disabledColor = color disabledColor = color
} }
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled self.enabled = enabled
} }
if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) {
self.inverted = inverted
}
action = try typeContainer.decodeModel(codingKey: .action) action = try typeContainer.decodeModel(codingKey: .action)
} }
@ -58,5 +92,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol {
try container.encode(enabled, forKey: .enabledColor) try container.encode(enabled, forKey: .enabledColor)
try container.encodeIfPresent(disabledColor, forKey: .disabledColor) try container.encodeIfPresent(disabledColor, forKey: .disabledColor)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)
try container.encode(enabled_inverted, forKey: .enabled_inverted)
try container.encode(inverted, forKey: .inverted)
} }
} }

View File

@ -9,13 +9,16 @@
import UIKit import UIKit
@objcMembers public class LineModel: MoleculeModelProtocol { @objcMembers public class LineModel: MoleculeModelProtocol {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
/* /**
The frequency of the line in a moleculeList. The frequency of the line in a moleculeList:
all (between all cells, above top, below bottom) - all (between all cells, above top, below bottom)
allExceptTop (between all cells, below bottom) - allExceptTop (between all cells, below bottom)
allExceptBottom (between all cells, above top) - allExceptBottom (between all cells, above top)
between (between all cells) - between (between all cells)
*/ */
public enum Frequency: String, Codable { public enum Frequency: String, Codable {
case all case all
@ -24,13 +27,13 @@ import UIKit
case between case between
} }
/* /**
The style of the line. The style of the line:
standard (1 height, silver) - standard (1 height, silver)
thin (1 height, black) - thin (1 height, black)
medium (2 height, black) - medium (2 height, black)
heavy (4 height, black) - heavy (4 height, black)
none (hidden) - none (hidden)
*/ */
public enum Style: String, Codable { public enum Style: String, Codable {
case standard case standard
@ -40,23 +43,35 @@ import UIKit
case none case none
} }
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "line" public static var identifier: String = "line"
public var type: Style = .standard public var type: Style = .standard
public var frequency: Frequency? = .allExceptTop public var frequency: Frequency? = .allExceptTop
//TODO: use color insted of backgroundColor. Needs server changes //TODO: use color insted of backgroundColor. Needs server changes
// public var color: Color? // public var color: Color?
public var backgroundColor: Color? public var backgroundColor: Color?
// Use this to show vertical line // Use this to show vertical line
// Default is false // Default is false
public var useVerticalLine: Bool? public var useVerticalLine: Bool?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(type: Style) { public init(type: Style) {
self.type = type self.type = type
self.useVerticalLine = false self.useVerticalLine = false
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case type case type
@ -66,14 +81,21 @@ import UIKit
case useVerticalLine case useVerticalLine
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let type = try typeContainer.decodeIfPresent(Style.self, forKey: .type) { if let type = try typeContainer.decodeIfPresent(Style.self, forKey: .type) {
self.type = type self.type = type
} }
if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) { if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) {
self.frequency = frequency self.frequency = frequency
} }
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine)
} }