// // ModelColorConfiguration.swift // VDS // // Created by Matt Bruce on 8/4/22. // import Foundation import UIKit public typealias ObjectColorable = Colorable & Initable & ObjectWithable /// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .light /// /// let config = SurfaceColorConfiguration() /// /// config.lightColor = .black /// config.darkColor = .white /// /// let textColor = config.getColor(model) //returns .black final public class SurfaceColorConfiguration: ObjectColorable { public typealias ObjectType = Surfaceable public var lightColor: UIColor = .clear public var darkColor: UIColor = .clear required public init(){} public func getColor(_ object: any ObjectType) -> UIColor { return object.surface == .light ? lightColor : darkColor } } ///------------------------------------------------------------------- ///MARK -- DisabledSurfaceColorable ///------------------------------------------------------------------- public protocol DisabledSurfaceColorable: ObjectColorable { var disabled: SurfaceColorConfiguration { get set } var enabled: SurfaceColorConfiguration { get set } } extension DisabledSurfaceColorable { public func getDisabledColor (_ object: M) -> UIColor { object.disabled ? disabled.getColor(object) : enabled.getColor(object) } } /// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations /// - Disabling (var disabled: Bool) /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .dark /// model.disabled = false /// /// let config = DisabledSurfaceColorConfiguration() /// /// //disabled == false /// config.enabled.lightColor = .black /// config.enabled.darkColor = .white /// /// //disabled == true /// config.disabled.lightColor = .gray /// config.disabled.darkColor = .lightGray /// /// let textColor = config.getColor(model) //returns .white /// /// open class DisabledSurfaceColorConfiguration: DisabledSurfaceColorable { public typealias ObjectType = Surfaceable & Disabling public var disabled = SurfaceColorConfiguration() public var enabled = SurfaceColorConfiguration() required public init(){} public func getColor(_ object: any ObjectType) -> UIColor { getDisabledColor(object) } } ///------------------------------------------------------------------- ///MARK -- BinaryColorable ///------------------------------------------------------------------- public protocol BinaryColorable{ var useTrueColor: Bool { get } } extension BinaryColorable where Self: Control { public var useTrueColor: Bool { return isSelected } } ///------------------------------------------------------------------- ///MARK -- BinarySurfaceColorable ///------------------------------------------------------------------- public protocol BinarySurfaceColorable: ObjectColorable { var forTrue: SurfaceColorConfiguration { get set } var forFalse: SurfaceColorConfiguration { get set } } extension BinarySurfaceColorable { public func getBinaryColor(_ object: M) -> UIColor { object.useTrueColor ? forTrue.getColor(object) : forFalse.getColor(object) } } /// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations /// - BinaryColorable (var userTrueColor: Bool) /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .dark /// model.on = true //this is read in the extension var userTrueColor /// let config = BinarySurfaceColorConfiguration() /// /// //True from BinaryColorable.userTrueColor /// config.forTrue.lightColor = .black /// config.forTrue.darkColor = .white /// /// //False from BinaryColorable.userTrueColor /// config.forFalse.lightColor = .red /// config.forFalse.darkColor = .red /// /// let textColor = config.getColor(model) //returns .white /// /// final public class BinarySurfaceColorConfiguration: BinarySurfaceColorable { public typealias ObjectType = Surfaceable & BinaryColorable public var forTrue = SurfaceColorConfiguration() public var forFalse = SurfaceColorConfiguration() required public init(){} public func getColor(_ object: any ObjectType) -> UIColor { getBinaryColor(object) } } ///------------------------------------------------------------------- ///MARK -- BinaryDisabledSurfaceColorable ///------------------------------------------------------------------- public protocol BinaryDisabledSurfaceColorable: ObjectColorable { var forTrue: DisabledSurfaceColorConfiguration { get set } var forFalse: DisabledSurfaceColorConfiguration { get set } } extension BinaryDisabledSurfaceColorable { public func getBinaryColor(_ object: M) -> UIColor { object.useTrueColor ? forTrue.getColor(object) : forFalse.getColor(object) } } /// Meant to be used in a Object that implements the following interfaces for 8 possible color combinations /// - BinaryColorable (var userTrueColor: Bool) /// - Disabling (var disabled: Bool) /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.on = false /// model.disabled = false /// model.surface = .light /// let config = BinaryDisabledSurfaceColorConfiguration() /// /// //True /// config.forTrue.enabled.lightColor = .black /// config.forTrue.enabled.darkColor = .white /// config.forTrue.disabled.lightColor = .darkGray /// config.forTrue.disabled.darkColor = .lightGray /// /// //False /// config.forFalse.enabled.lightColor = .red /// config.forFalse.enabled.darkColor = .red /// config.forFalse.disabled.lightColor =.darkGray /// config.forFalse.disabled.darkColor = .lightGray /// /// let textColor = config.getColor(model) /// /// final public class BinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfaceColorable { public typealias ObjectType = Disabling & Surfaceable & BinaryColorable public var forTrue = DisabledSurfaceColorConfiguration() public var forFalse = DisabledSurfaceColorConfiguration() required public init(){} public func getColor(_ object: any ObjectType) -> UIColor { getBinaryColor(object) } }