36 lines
1.5 KiB
Swift
36 lines
1.5 KiB
Swift
//
|
|
// TiletBadgeModel.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 1/6/23.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension Tilelet {
|
|
public struct BadgeModel: Codable {
|
|
public var text: String = ""
|
|
public var fillColor: Badge.FillColor = .red
|
|
public var surface: Surface = .light
|
|
public var numberOfLines: Int
|
|
public var maxWidth: CGFloat?
|
|
|
|
public init(text: String, fillColor: Badge.FillColor = .red, surface: Surface = .light, numberOfLines: Int = 0, maxWidth: CGFloat? = nil) {
|
|
self.text = text
|
|
self.fillColor = fillColor
|
|
self.surface = surface
|
|
self.numberOfLines = numberOfLines
|
|
self.maxWidth = maxWidth
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container: KeyedDecodingContainer<Tilelet.BadgeModel.CodingKeys> = try decoder.container(keyedBy: Tilelet.BadgeModel.CodingKeys.self)
|
|
self.text = try container.decode(String.self, forKey: Tilelet.BadgeModel.CodingKeys.text)
|
|
self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: Tilelet.BadgeModel.CodingKeys.fillColor) ?? .red
|
|
self.surface = try container.decodeIfPresent(Surface.self, forKey: Tilelet.BadgeModel.CodingKeys.surface) ?? .light
|
|
self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: Tilelet.BadgeModel.CodingKeys.numberOfLines) ?? 0
|
|
self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: Tilelet.BadgeModel.CodingKeys.maxWidth)
|
|
}
|
|
}
|
|
}
|