27 lines
824 B
Swift
27 lines
824 B
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
extension NSColor {
|
|
convenience init(hex: UInt32) {
|
|
self.init(
|
|
srgbRed: CGFloat((hex >> 16) & 0xFF) / 255,
|
|
green: CGFloat((hex >> 8) & 0xFF) / 255,
|
|
blue: CGFloat(hex & 0xFF) / 255,
|
|
alpha: 1)
|
|
}
|
|
}
|
|
|
|
extension Color {
|
|
/// A colour that switches between the Aluminium (light) and Graphite (dark) value with the appearance.
|
|
static func dynamic(light: UInt32, dark: UInt32) -> Color {
|
|
Color(nsColor: NSColor(name: nil) { appearance in
|
|
appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(hex: dark) : NSColor(hex: light)
|
|
})
|
|
}
|
|
|
|
/// The same colour in both finishes (shadow bases).
|
|
static func fixed(hex: UInt32) -> Color {
|
|
Color(nsColor: NSColor(hex: hex))
|
|
}
|
|
}
|