Skip to content

Commit 21c7c81

Browse files
committed
A specific appearance can now be passed.
1 parent 8e81e60 commit 21c7c81

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

ColorSetKit/NSColor+ColorSetKit.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ import Cocoa
6767
@objc( colorFromColorSet: )
6868
class func fromColorSet( name: String ) -> NSColor?
6969
{
70-
return NSColor.fromColorSet( name: name, forView: nil )
70+
return NSColor.fromColorSet( name: name, forAppearance: nil )
7171
}
7272

7373
@objc( colorFromColorSet:forView: )
7474
class func fromColorSet( name: String, forView view: NSView? ) -> NSColor?
75+
{
76+
return NSColor.fromColorSet( name: name, forAppearance: view?.effectiveAppearance )
77+
}
78+
79+
@objc( colorFromColorSet:forAppearance: )
80+
class func fromColorSet( name: String, forAppearance appearance: NSAppearance? ) -> NSColor?
7581
{
7682
if name.hasPrefix( "NS" )
7783
{
@@ -122,7 +128,7 @@ import Cocoa
122128

123129
if var l = lightness, abs( hsl.lightness - l ) > 0.001
124130
{
125-
if isDarkModeOn( forView: view )
131+
if isDarkModeOn( forAppearance: appearance )
126132
{
127133
var found = false
128134

@@ -153,7 +159,7 @@ import Cocoa
153159
return pair.color?.byChangingLightness( l )
154160
}
155161

156-
if isDarkModeOn( forView: view ), let variant = pair.variant
162+
if isDarkModeOn( forAppearance: appearance ), let variant = pair.variant
157163
{
158164
return variant
159165
}
@@ -548,7 +554,7 @@ import Cocoa
548554
return ( h, s, l )
549555
}
550556

551-
@nonobjc private class func isDarkModeOn( forView view: NSView? ) -> Bool
557+
@nonobjc private class func isDarkModeOn( forAppearance appearance: NSAppearance? ) -> Bool
552558
{
553559
if NSApp == nil
554560
{
@@ -557,7 +563,7 @@ import Cocoa
557563

558564
if #available( macOS 10.14, * )
559565
{
560-
let name = view?.effectiveAppearance.name ?? NSApp.effectiveAppearance.name
566+
let name = appearance?.name ?? NSApp.effectiveAppearance.name
561567

562568
if name == .darkAqua
563569
{

0 commit comments

Comments
 (0)