From a68e461eb4f96a20af243888be84dd1449e3ab66 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Sun, 26 Aug 2018 22:49:39 +0200 Subject: [PATCH 1/2] Replace custom Color struct with typealiases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that the decision not to support colors on Linux has been made, we can replace the custom `Color` struct with simple typealiases for `NSColor` and `UIColor`. The same can’t be done for font, since we want to enable loading of a font from a path, for SPM packages. --- .../Output/AttributedStringOutputFormat.swift | 2 +- Sources/Splash/Theming/Color.swift | 51 +++---------------- 2 files changed, 7 insertions(+), 46 deletions(-) diff --git a/Sources/Splash/Output/AttributedStringOutputFormat.swift b/Sources/Splash/Output/AttributedStringOutputFormat.swift index ee5bbd6..b418089 100644 --- a/Sources/Splash/Output/AttributedStringOutputFormat.swift +++ b/Sources/Splash/Output/AttributedStringOutputFormat.swift @@ -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 ]) diff --git a/Sources/Splash/Theming/Color.swift b/Sources/Splash/Theming/Color.swift index a75a46e..ad64279 100644 --- a/Sources/Splash/Theming/Color.swift +++ b/Sources/Splash/Theming/Color.swift @@ -4,55 +4,16 @@ * MIT license - see LICENSE.md */ -import Foundation - -#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 { - 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 -} - +public typealias Color = UIColor #elseif os(macOS) - import Cocoa +public typealias Color = NSColor +#endif internal extension Color { - typealias Renderable = NSColor + convenience init(red: CGFloat, green: CGFloat, blue: CGFloat) { + self.init(red: red, green: green, blue: blue, alpha: 1) + } } - -#endif From aea685e8b44520b825785afa4c62b0d92120d75d Mon Sep 17 00:00:00 2001 From: John Sundell Date: Sun, 26 Aug 2018 22:57:02 +0200 Subject: [PATCH 2/2] Color: Exclude internal extension on Linux --- Sources/Splash/Theming/Color.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Splash/Theming/Color.swift b/Sources/Splash/Theming/Color.swift index ad64279..7ffc1e9 100644 --- a/Sources/Splash/Theming/Color.swift +++ b/Sources/Splash/Theming/Color.swift @@ -12,8 +12,10 @@ import Cocoa public typealias Color = NSColor #endif +#if !os(Linux) internal extension Color { convenience init(red: CGFloat, green: CGFloat, blue: CGFloat) { self.init(red: red, green: green, blue: blue, alpha: 1) } } +#endif