Merge pull request #7 from JohnSundell/remove-custom-color

Replace custom Color struct with typealiases
This commit is contained in:
John Sundell 2018-08-26 23:15:19 +02:00 committed by GitHub
commit f8523e3360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 48 deletions

View File

@ -56,7 +56,7 @@ public extension AttributedStringOutputFormat {
private extension NSMutableAttributedString {
func append(_ string: String, font: Font.Loaded, color: Color) {
let attributedString = NSAttributedString(string: string, attributes: [
.foregroundColor: color.renderable,
.foregroundColor: color,
.font: font
])

View File

@ -4,55 +4,18 @@
* MIT license - see LICENSE.md
*/
import Foundation
#if os(iOS)
import UIKit
public typealias Color = UIColor
#elseif os(macOS)
import Cocoa
public typealias Color = NSColor
#endif
#if !os(Linux)
/// 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
internal extension Color {
convenience init(red: CGFloat, green: CGFloat, blue: CGFloat) {
self.init(red: red, green: green, blue: blue, alpha: 1)
}
}
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