John Sundell 1e532a6c4c Theme: Streamline cross-platform implementation
Now that we’re making Splash support iOS as well as
Mac + Linux, we need to create some nice abstractions
to make sure that we can share as much code as possible
between all platforms.

- Define Font.Loaded and Color.Renderable as platform-
specific typealiases for system fonts and colors.
- Don’t compile in non-Linux compatible code when building
for Linux.
- Make Font and Color handle all conversion themselves, so
that AttributedStringOutputFormat can be kept more clean.
2018-08-26 00:54:44 +02:00

57 lines
1.1 KiB
Swift

/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import Foundation
/// A representation of a color, for use with a `Theme`.
/// Since Splash aims to be cross-platform, it uses this
/// simplified color representation rather than `NSColor`
/// or `UIColor`.
public struct Color {
public var red: Double
public var green: Double
public var blue: Double
public var alpha: Double
public init(red: Double, green: Double, blue: Double, alpha: Double = 1) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
}
}
#if !os(Linux)
internal extension Color {
var renderable: Renderable {
return Renderable(
red: CGFloat(red),
green: CGFloat(green),
blue: CGFloat(blue),
alpha: CGFloat(alpha)
)
}
}
#endif
#if os(iOS)
import UIKit
internal extension Color {
typealias Renderable = UIColor
}
#elseif os(macOS)
import Cocoa
internal extension Color {
typealias Renderable = NSColor
}
#endif