76 lines
2.5 KiB
Swift
76 lines
2.5 KiB
Swift
//
|
|
// TiletTitleModel.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 1/6/23.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension Tilelet {
|
|
public struct TitleModel {
|
|
//--------------------------------------------------
|
|
// MARK: - Enums
|
|
//--------------------------------------------------
|
|
public enum TextStyle: String, EnumSubset, Codable {
|
|
case titleXLarge
|
|
case boldTitleXLarge
|
|
case titleLarge
|
|
case boldTitleLarge
|
|
case titleMedium
|
|
case boldTitleMedium
|
|
case titleSmall
|
|
case boldTitleSmall
|
|
|
|
public var defaultValue: TitleLockup.TitleTextStyle { .boldTitleSmall }
|
|
}
|
|
//--------------------------------------------------
|
|
// MARK: - Public Properties
|
|
//--------------------------------------------------
|
|
public var text: String = ""
|
|
public var textAttributes: [any LabelAttributeModel]?
|
|
public var textStyle: TextStyle = .boldTitleSmall
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initializers
|
|
//--------------------------------------------------
|
|
public init(text: String,
|
|
textAttributes: [any LabelAttributeModel]? = nil,
|
|
textStyle: TextStyle = .boldTitleSmall) {
|
|
self.text = text
|
|
self.textAttributes = textAttributes
|
|
self.textStyle = textStyle
|
|
}
|
|
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Public Functions
|
|
//--------------------------------------------------
|
|
public func toTitleLockupTitleModel() -> TitleLockup.TitleModel {
|
|
TitleLockup.TitleModel(text: text,
|
|
textAttributes: nil,
|
|
textStyle: textStyle.value)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Tilelet.TitleModel: Codable {
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case text, textStyle
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
self.text = try container.decode(String.self, forKey: .text)
|
|
self.textStyle = try container.decodeIfPresent(TextStyle.self, forKey: .textStyle) ?? .boldTitleSmall
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(text, forKey: .text)
|
|
try container.encode(textStyle, forKey: .textStyle)
|
|
}
|
|
|
|
}
|