diff options
| author | Tommaso Negri <me@tommasongr.com> | 2026-10-14 22:18:15 +0200 |
|---|---|---|
| committer | Tommaso Negri <me@tommasongr.com> | 2026-10-14 22:18:15 +0200 |
| commit | ec076ee6e315e6059545d0364a329cdb4b80b306 (patch) | |
| tree | 7f2632a02085091bd7a309e1e5d659a7e017e4c5 /Sources | |
| parent | ed506be5076c500f19e8a39e89867ee54007577e (diff) | |
| download | bar-ec076ee6e315e6059545d0364a329cdb4b80b306.tar.gz bar-ec076ee6e315e6059545d0364a329cdb4b80b306.zip | |
remove leftover code in HEX
Diffstat (limited to 'Sources')
| -rw-r--r-- | Sources/bar/Config.swift | 2 | ||||
| -rw-r--r-- | Sources/bar/Models/Color+Hex.swift (renamed from Sources/bar/Models/HEX.swift) | 59 | ||||
| -rw-r--r-- | Sources/bar/bar.docc/bar.md | 1 | ||||
| -rw-r--r-- | Sources/bar/bar.docc/customisation.md | 4 |
4 files changed, 3 insertions, 63 deletions
diff --git a/Sources/bar/Config.swift b/Sources/bar/Config.swift index 565459b..d8c1350 100644 --- a/Sources/bar/Config.swift +++ b/Sources/bar/Config.swift @@ -30,7 +30,7 @@ enum Config { // // You can use system default colors and the standard SwiftUI // methods to define them. However, for convenience we added - // support for hex colors too (see ``HEX``). These strings are parsed + // support for hex colors too with `Color.hex(_:)`. These strings are parsed // at runtime, so the compiler does not check their format. // // E.g: `.hex("#000000")` diff --git a/Sources/bar/Models/HEX.swift b/Sources/bar/Models/Color+Hex.swift index 5ceb393..4f82e78 100644 --- a/Sources/bar/Models/HEX.swift +++ b/Sources/bar/Models/Color+Hex.swift @@ -1,42 +1,6 @@ import SwiftUI -/// A color described by a hexadecimal color code. -/// -/// `HEX` is a lightweight, string-backed representation: the code is stored -/// verbatim and parsed only when converted to a SwiftUI color via `Color(hex:)` -/// or `Color.hex(_:)`, which resolve it in the sRGB color space. -/// -/// Supported formats (the leading `#` is optional): -/// - `#RGB` -/// - `#RGBA` -/// - `#RRGGBB` -/// - `#RRGGBBAA` -/// -/// Single-digit components are expanded by repeating the digit; for example, -/// `#3aF` is read as `#33AAFF`. When present, the trailing digits encode alpha -/// (opacity); otherwise opacity defaults to `1`. Surrounding whitespace is -/// trimmed during conversion. Unsupported lengths resolve to opaque black; -/// characters are not fully validated, so use one of the formats above. -struct HEX { - /// The raw hex code, exactly as supplied. It is not validated or normalized; - /// parsing is performed lazily by `Color.hex(_:)`. - var code: String - - /// Creates a hex color from the given code. - /// - /// - Parameter code: A hex color code. Stored verbatim; see ``HEX`` for the - /// accepted formats. - init(code: String) { - self.code = code - } -} - extension SwiftUI.Color { - /// Creates a color from a ``HEX`` value. - init(hex: HEX) { - self = .hex(hex.code) - } - /// Creates a color from a hex code, resolving it in the sRGB color space. /// /// Supported formats (the leading `#` is optional): `#RGB`, `#RGBA`, @@ -94,26 +58,3 @@ extension SwiftUI.Color { return Color(.sRGB, red: red, green: green, blue: blue, opacity: opacity) } } - -extension SwiftUI.Color.Resolved { - /// The hex code for this resolved color. - /// - /// Components are clamped to `0...1` and quantized to 8 bits. - /// The result is a 6-digit `#RRGGBB` code, or an 8-digit `#RRGGBBAA` code - /// when the color is not fully opaque. - var hex: HEX { - let r = Int((min(max(Double(red), 0), 1) * 255).rounded()) - let g = Int((min(max(Double(green), 0), 1) * 255).rounded()) - let b = Int((min(max(Double(blue), 0), 1) * 255).rounded()) - - let code: String - if opacity < 1 { - let a = Int((min(max(Double(opacity), 0), 1) * 255).rounded()) - code = String(format: "#%02X%02X%02X%02X", r, g, b, a) - } else { - code = String(format: "#%02X%02X%02X", r, g, b) - } - - return HEX(code: code) - } -} diff --git a/Sources/bar/bar.docc/bar.md b/Sources/bar/bar.docc/bar.md index 61fee5b..bb17e56 100644 --- a/Sources/bar/bar.docc/bar.md +++ b/Sources/bar/bar.docc/bar.md @@ -31,7 +31,6 @@ If you specify the interval, the block will re-run the command with such frequen - <doc:patches> - <doc:daemons> - ``Config`` -- ``HEX`` ### Bar diff --git a/Sources/bar/bar.docc/customisation.md b/Sources/bar/bar.docc/customisation.md index e006fa3..f5d5195 100644 --- a/Sources/bar/bar.docc/customisation.md +++ b/Sources/bar/bar.docc/customisation.md @@ -27,9 +27,9 @@ enum Config { > Tip: While testing the configuration you might want to use the `make run` target. > It will build and execute the program right away, without copying the binaries. -## HEX Colors +## Hex colors -You can use any standard SwiftUI color. For convenience, `Color.hex(_:)` parses hex strings directly in source, and ``HEX`` wraps a stored hex code: +You can use any standard SwiftUI color. For convenience, `Color.hex(_:)` parses hex strings directly in source: ```swift static let foreground: Color = .hex("#CDD6F4") |
