Skip to content

Commit dbea550

Browse files
committed
context icons
1 parent d2c4a57 commit dbea550

File tree

6 files changed

+779
-156
lines changed

6 files changed

+779
-156
lines changed

Flitro.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
objectVersion = 77;
77
objects = {
88

9+
/* Begin PBXBuildFile section */
10+
B63A63842E20A1410032C498 /* PhosphorSwift in Frameworks */ = {isa = PBXBuildFile; productRef = B63A63832E20A1410032C498 /* PhosphorSwift */; };
11+
/* End PBXBuildFile section */
12+
913
/* Begin PBXContainerItemProxy section */
1014
B65885EC2E196B0700F19C4A /* PBXContainerItemProxy */ = {
1115
isa = PBXContainerItemProxy;
@@ -52,6 +56,7 @@
5256
isa = PBXFrameworksBuildPhase;
5357
buildActionMask = 2147483647;
5458
files = (
59+
B63A63842E20A1410032C498 /* PhosphorSwift in Frameworks */,
5560
);
5661
runOnlyForDeploymentPostprocessing = 0;
5762
};
@@ -112,6 +117,7 @@
112117
);
113118
name = Flitro;
114119
packageProductDependencies = (
120+
B63A63832E20A1410032C498 /* PhosphorSwift */,
115121
);
116122
productName = Flitro;
117123
productReference = B65885DD2E196B0600F19C4A /* Flitro.app */;
@@ -195,6 +201,9 @@
195201
);
196202
mainGroup = B65885D42E196B0600F19C4A;
197203
minimizedProjectReferenceProxies = 1;
204+
packageReferences = (
205+
B63A63822E20A1410032C498 /* XCRemoteSwiftPackageReference "swift" */,
206+
);
198207
preferredProjectObjectVersion = 77;
199208
productRefGroup = B65885DE2E196B0600F19C4A /* Products */;
200209
projectDirPath = "";
@@ -549,6 +558,25 @@
549558
defaultConfigurationName = Release;
550559
};
551560
/* End XCConfigurationList section */
561+
562+
/* Begin XCRemoteSwiftPackageReference section */
563+
B63A63822E20A1410032C498 /* XCRemoteSwiftPackageReference "swift" */ = {
564+
isa = XCRemoteSwiftPackageReference;
565+
repositoryURL = "https://github.com/phosphor-icons/swift";
566+
requirement = {
567+
kind = exactVersion;
568+
version = 2.1.0;
569+
};
570+
};
571+
/* End XCRemoteSwiftPackageReference section */
572+
573+
/* Begin XCSwiftPackageProductDependency section */
574+
B63A63832E20A1410032C498 /* PhosphorSwift */ = {
575+
isa = XCSwiftPackageProductDependency;
576+
package = B63A63822E20A1410032C498 /* XCRemoteSwiftPackageReference "swift" */;
577+
productName = PhosphorSwift;
578+
};
579+
/* End XCSwiftPackageProductDependency section */
552580
};
553581
rootObject = B65885D52E196B0600F19C4A /* Project object */;
554582
}

Flitro/ColorExtensions.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import SwiftUI
2+
3+
// MARK: - Color <-> Hex helpers
4+
extension Color {
5+
init?(hex: String) {
6+
var hex = hex
7+
if hex.hasPrefix("#") { hex.removeFirst() }
8+
guard hex.count == 6, let intVal = Int(hex, radix: 16) else { return nil }
9+
let r = Double((intVal >> 16) & 0xFF) / 255.0
10+
let g = Double((intVal >> 8) & 0xFF) / 255.0
11+
let b = Double(intVal & 0xFF) / 255.0
12+
self.init(red: r, green: g, blue: b)
13+
}
14+
15+
func toHexString() -> String? {
16+
let uiColor = NSColor(self)
17+
guard let rgb = uiColor.usingColorSpace(.deviceRGB) else { return nil }
18+
let r = Int(rgb.redComponent * 255)
19+
let g = Int(rgb.greenComponent * 255)
20+
let b = Int(rgb.blueComponent * 255)
21+
return String(format: "#%02X%02X%02X", r, g, b)
22+
}
23+
24+
// Returns a lighter version of the color by blending with white
25+
func lighter(by amount: CGFloat = 0.6) -> Color {
26+
let uiColor = NSColor(self)
27+
guard let rgb = uiColor.usingColorSpace(.deviceRGB) else { return self }
28+
let r = rgb.redComponent + (1.0 - rgb.redComponent) * amount
29+
let g = rgb.greenComponent + (1.0 - rgb.greenComponent) * amount
30+
let b = rgb.blueComponent + (1.0 - rgb.blueComponent) * amount
31+
return Color(red: r, green: g, blue: b)
32+
}
33+
34+
// Returns a darker version of the color by blending with black
35+
func darker(by amount: CGFloat = 0.3) -> Color {
36+
let uiColor = NSColor(self)
37+
guard let rgb = uiColor.usingColorSpace(.deviceRGB) else { return self }
38+
let r = rgb.redComponent * (1.0 - amount)
39+
let g = rgb.greenComponent * (1.0 - amount)
40+
let b = rgb.blueComponent * (1.0 - amount)
41+
return Color(red: r, green: g, blue: b)
42+
}
43+
44+
// Returns the contrast ratio between self and another color (WCAG 2.0)
45+
func contrastRatio(with other: Color) -> CGFloat {
46+
let c1 = NSColor(self).usingColorSpace(.deviceRGB) ?? .black
47+
let c2 = NSColor(other).usingColorSpace(.deviceRGB) ?? .white
48+
func luminance(_ c: NSColor) -> CGFloat {
49+
func channel(_ v: CGFloat) -> CGFloat {
50+
return v <= 0.03928 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4)
51+
}
52+
return 0.2126 * channel(c.redComponent) + 0.7152 * channel(c.greenComponent) + 0.0722 * channel(c.blueComponent)
53+
}
54+
let l1 = luminance(c1)
55+
let l2 = luminance(c2)
56+
return (max(l1, l2) + 0.05) / (min(l1, l2) + 0.05)
57+
}
58+
}

0 commit comments

Comments
 (0)