Skip to content

Commit

Permalink
feat: make traffic lights symbols dark in light theme
Browse files Browse the repository at this point in the history
closes #132
  • Loading branch information
ShlomoCode committed Jul 10, 2024
1 parent c776d10 commit b7f4d13
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions DockDoor/Views/Hover Window/Traffic Light Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ struct TrafficLightButtons: View {

var body: some View {
HStack(spacing: 6) {
buttonFor(action: .quit, symbol: "power", color: .purple)
buttonFor(action: .close, symbol: "xmark", color: .red)
buttonFor(action: .minimize, symbol: "minus", color: .yellow)
buttonFor(action: .toggleFullScreen, symbol: "arrow.up.left.and.arrow.down.right", color: .green)
buttonFor(action: .quit, symbol: "power", color: Color(hex: "290133"), fillColor: .purple)
buttonFor(action: .close, symbol: "xmark", color: Color(hex: "7e0609"), fillColor: .red)
buttonFor(action: .minimize, symbol: "minus", color: Color(hex: "985712"), fillColor: .yellow)
buttonFor(action: .toggleFullScreen, symbol: "arrow.up.left.and.arrow.down.right", color: Color(hex: "0d650d"), fillColor: .green)
}
.padding(4)
.opacity(isHovering ? 1 : 0.25)
Expand All @@ -29,7 +29,7 @@ struct TrafficLightButtons: View {
}
}

private func buttonFor(action: WindowAction, symbol: String, color: Color) -> some View {
private func buttonFor(action: WindowAction, symbol: String, color: Color, fillColor: Color) -> some View {
Button(action: {
performAction(action)
onAction()
Expand All @@ -41,7 +41,7 @@ struct TrafficLightButtons: View {
}
}
.buttonBorderShape(.roundedRectangle)
.foregroundStyle(color)
.foregroundStyle(color, fillColor)
.buttonStyle(.plain)
.font(.system(size: 13))
}
Expand All @@ -63,3 +63,30 @@ struct TrafficLightButtons: View {
case quit, close, minimize, toggleFullScreen
}
}

extension Color {
init(hex: String) {
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
var int: UInt64 = 0
Scanner(string: hex).scanHexInt64(&int)
let a, r, g, b: UInt64
switch hex.count {
case 3: // RGB (12-bit)
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
case 6: // RGB (24-bit)
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
case 8: // ARGB (32-bit)
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
default:
(a, r, g, b) = (1, 1, 1, 0)
}

self.init(
.sRGB,
red: Double(r) / 255,
green: Double(g) / 255,
blue: Double(b) / 255,
opacity: Double(a) / 255
)
}
}

0 comments on commit b7f4d13

Please sign in to comment.