From 7c0551c6624b6e2c165b52840ca001ce7cb8fb19 Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Sun, 12 Jul 2026 11:16:54 +0200 Subject: [PATCH] make colors and padding optional --- Sources/phbar/Models/Theme/PHThemePadding.swift | 11 +++++------ Sources/phbar/Models/Theme/PHThemeStyle.swift | 8 ++++---- Sources/phbar/Models/Theme/theme.toml | 11 ++++------- Sources/phbar/Views/SpaceBlockView.swift | 2 +- Sources/phbar/Views/TextBlockView.swift | 8 ++++---- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Sources/phbar/Models/Theme/PHThemePadding.swift b/Sources/phbar/Models/Theme/PHThemePadding.swift index 27866ff..c26c676 100644 --- a/Sources/phbar/Models/Theme/PHThemePadding.swift +++ b/Sources/phbar/Models/Theme/PHThemePadding.swift @@ -1,10 +1,9 @@ struct PHThemePadding: Decodable { - let leading: Double - let trailing: Double + let trailing: Double? + let leading: Double? - var total: Double { leading + trailing } - - static var zero: PHThemePadding { - Self.init(leading: 0, trailing: 0) + private enum CodingKeys: String, CodingKey { + case trailing = "right" + case leading = "left" } } diff --git a/Sources/phbar/Models/Theme/PHThemeStyle.swift b/Sources/phbar/Models/Theme/PHThemeStyle.swift index 2350e4a..8c44608 100644 --- a/Sources/phbar/Models/Theme/PHThemeStyle.swift +++ b/Sources/phbar/Models/Theme/PHThemeStyle.swift @@ -1,15 +1,15 @@ struct PHThemeStyle: Decodable { let name: String - let foreground: PHThemeColor - let background: PHThemeColor - let padding: PHThemePadding + let foreground: PHThemeColor? + let background: PHThemeColor? + let padding: PHThemePadding? static let `default`: Self = { PHThemeStyle( name: "_default", foreground: .init(color: "#000000", alpha: nil), background: .init(color: "#ffffff", alpha: nil), - padding: .init(leading: 10, trailing: 10) + padding: .init(trailing: 12, leading: 12) ) }() } diff --git a/Sources/phbar/Models/Theme/theme.toml b/Sources/phbar/Models/Theme/theme.toml index d4a5135..01c526f 100644 --- a/Sources/phbar/Models/Theme/theme.toml +++ b/Sources/phbar/Models/Theme/theme.toml @@ -7,19 +7,16 @@ shadow = false blur = 0.0 [[style]] -name = "default" +name = "default" foreground = { color = "#aed3f3" } background = { color = "#010408", alpha = 0.825 } -padding = { leading = 0.0, trailing = 0.0 } [[style]] -name = "floating" +name = "floating" foreground = { color = "#aed3f3" } -background = { color = "#000000", alpha = 0 } -padding = { leading = 0.0, trailing = 0.0 } [[style]] -name = "tinted" +name = "tinted" foreground = { color = "#aed3f3" } background = { color = "#0f304a" } -padding = { leading = 12.0, trailing = 12.0 } +padding = { left = 12.0, right = 12.0 } diff --git a/Sources/phbar/Views/SpaceBlockView.swift b/Sources/phbar/Views/SpaceBlockView.swift index e825268..4d41199 100644 --- a/Sources/phbar/Views/SpaceBlockView.swift +++ b/Sources/phbar/Views/SpaceBlockView.swift @@ -11,7 +11,7 @@ struct SpaceBlockView: View { var body: some View { Rectangle() - .fill(block.style.background) + .fill(block.style.background?.uiColor ?? .clear) .frame(width: width) } } diff --git a/Sources/phbar/Views/TextBlockView.swift b/Sources/phbar/Views/TextBlockView.swift index 73e4d85..4ef076c 100644 --- a/Sources/phbar/Views/TextBlockView.swift +++ b/Sources/phbar/Views/TextBlockView.swift @@ -15,16 +15,16 @@ struct TextBlockView: View { if let label = block.label, !label.isEmpty { ZStack(alignment: .center) { RoundedRectangle(cornerRadius: 0) - .fill(block.style.background) + .foregroundStyle(block.style.background?.uiColor ?? .clear) Group { Text(label) - .foregroundStyle(block.style.foreground) + .foregroundStyle(block.style.foreground?.uiColor ?? .clear) .transformEffect(adjustOffset) .border(bar.debug ? .blue : .clear) } - .padding(.leading, block.style.padding.leading) - .padding(.trailing, block.style.padding.trailing) + .padding(.trailing, block.style.padding?.trailing ?? 0) + .padding(.leading, block.style.padding?.leading ?? 0) } .fixedSize(horizontal: true, vertical: false) .border(bar.debug ? .red : .clear)