192 lines
6.5 KiB
Swift
192 lines
6.5 KiB
Swift
//
|
|
// 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<TestModel>()
|
|
///
|
|
/// config.lightColor = .black
|
|
/// config.darkColor = .white
|
|
///
|
|
/// let textColor = config.getColor(model) //returns .black
|
|
final public class SurfaceColorConfiguration: ObjectColorable {
|
|
public typealias ModelType = Surfaceable
|
|
public var lightColor: UIColor = .clear
|
|
public var darkColor: UIColor = .clear
|
|
|
|
required public init(){}
|
|
public func getColor(_ viewModel: any ModelType) -> UIColor {
|
|
return viewModel.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<M: Surfaceable & Disabling> (_ viewModel: M) -> UIColor {
|
|
viewModel.disabled ? disabled.getColor(viewModel) : enabled.getColor(viewModel)
|
|
}
|
|
}
|
|
|
|
/// 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
|
|
///
|
|
///
|
|
final public class DisabledSurfaceColorConfiguration: DisabledSurfaceColorable {
|
|
public typealias ModelType = Surfaceable & Disabling
|
|
public var disabled = SurfaceColorConfiguration()
|
|
public var enabled = SurfaceColorConfiguration()
|
|
|
|
required public init(){}
|
|
|
|
public func getColor(_ viewModel: any ModelType) -> UIColor {
|
|
getDisabledColor(viewModel)
|
|
}
|
|
}
|
|
|
|
///-------------------------------------------------------------------
|
|
///MARK -- BinaryColorable
|
|
///-------------------------------------------------------------------
|
|
public protocol BinaryColorable{
|
|
var userTrueColor: Bool { get }
|
|
}
|
|
|
|
extension BinaryColorable where Self: Selectable {
|
|
public var userTrueColor: Bool { return selected }
|
|
}
|
|
|
|
///-------------------------------------------------------------------
|
|
///MARK -- BinarySurfaceColorable
|
|
///-------------------------------------------------------------------
|
|
public protocol BinarySurfaceColorable: ObjectColorable {
|
|
var forTrue: SurfaceColorConfiguration { get set }
|
|
var forFalse: SurfaceColorConfiguration { get set }
|
|
}
|
|
|
|
extension BinarySurfaceColorable {
|
|
public func getBinaryColor<M: Surfaceable & BinaryColorable>(_ viewModel: M) -> UIColor {
|
|
viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel)
|
|
}
|
|
}
|
|
|
|
/// 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 ModelType = Surfaceable & BinaryColorable
|
|
public var forTrue = SurfaceColorConfiguration()
|
|
public var forFalse = SurfaceColorConfiguration()
|
|
|
|
required public init(){}
|
|
|
|
public func getColor(_ viewModel: any ModelType) -> UIColor {
|
|
getBinaryColor(viewModel)
|
|
}
|
|
}
|
|
|
|
///-------------------------------------------------------------------
|
|
///MARK -- BinaryDisabledSurfaceColorable
|
|
///-------------------------------------------------------------------
|
|
|
|
public protocol BinaryDisabledSurfaceColorable: ObjectColorable {
|
|
var forTrue: DisabledSurfaceColorConfiguration { get set }
|
|
var forFalse: DisabledSurfaceColorConfiguration { get set }
|
|
}
|
|
|
|
extension BinaryDisabledSurfaceColorable {
|
|
public func getBinaryColor<M: Disabling & Surfaceable & BinaryColorable>(_ viewModel: M) -> UIColor {
|
|
viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel)
|
|
}
|
|
}
|
|
|
|
/// 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 ModelType = Disabling & Surfaceable & BinaryColorable
|
|
public var forTrue = DisabledSurfaceColorConfiguration()
|
|
public var forFalse = DisabledSurfaceColorConfiguration()
|
|
|
|
required public init(){}
|
|
|
|
public func getColor(_ viewModel: any ModelType) -> UIColor {
|
|
getBinaryColor(viewModel)
|
|
}
|
|
}
|