Skip to content

Commit dc47b87

Browse files
authored
Merge pull request #812 from TomaszLizer/fix/improper-color-opacity
Fix improper color opacity when using double
2 parents 0ac3231 + 3370335 commit dc47b87

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/Ignite/Framework/Color.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public struct Color: CustomStringConvertible, Equatable, Hashable, Sendable {
541541
let intRed = Int(red * 255)
542542
let intGreen = Int(green * 255)
543543
let intBlue = Int(blue * 255)
544-
let intOpacity = Int(opacity * 255)
544+
let intOpacity = Int(opacity * 100)
545545

546546
self.init(red: intRed, green: intGreen, blue: intBlue, opacity: intOpacity%)
547547
}
@@ -554,7 +554,7 @@ public struct Color: CustomStringConvertible, Equatable, Hashable, Sendable {
554554
/// (transparent) through to 1 (opaque).
555555
public init(white: Double, opacity: Double = 1) {
556556
let intWhite = Int(white * 255)
557-
let intOpacity = Int(opacity * 255)
557+
let intOpacity = Int(opacity * 100)
558558

559559
self.init(red: intWhite, green: intWhite, blue: intWhite, opacity: intOpacity%)
560560
}

Tests/IgniteTesting/Types/Color.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,16 @@ struct ColorTypeTests {
5050

5151
#expect(color.description == "rgb(\(red) \(blue) \(green) / \(opacity.roundedValue)%)")
5252
}
53+
54+
@Test("Double to Int Conversion in init(red:green:blue:opacity:)")
55+
func rbgaInitWithDouble() {
56+
let color = Color(red: 1.0, green: 1.0, blue: 1.0, opacity: 1.0)
57+
#expect(color.description == "rgb(255 255 255 / 100%)")
58+
}
59+
60+
@Test("Double to Int Conversion in init(white:opacity:)")
61+
func whiteAndOpacityInitWithDouble() {
62+
let color = Color(white: 1.0, opacity: 1.0)
63+
#expect(color.description == "rgb(255 255 255 / 100%)")
64+
}
5365
}

0 commit comments

Comments
 (0)