Skip to content

Commit

Permalink
Encode color to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
emorydunn committed Mar 11, 2024
1 parent 7458c89 commit f84aa99
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/SDPlusLayout/Color/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ public struct Color: Equatable, Hashable, Codable {
return "rgba(\(r),\(g),\(b),\(alpha))"
}

/// Return the color without transparency.
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.formatted(.hex))
}


// MARK: Opacity Modification
/// Return the color without transparency.
public var withoutAlpha: Color {
Color(red: red, green: green, blue: blue)
}
Expand All @@ -194,6 +201,8 @@ public struct Color: Equatable, Hashable, Codable {
Color(red: red, green: green, blue: blue, alpha: alpha)
}

// MARK: - Default Colors

/// Clear
public static let clear = Color(grey: 0, 0)

Expand Down

0 comments on commit f84aa99

Please sign in to comment.