Skip to content

Commit fbd67d9

Browse files
committed
Clean up the color calculation
1 parent 42f33ab commit fbd67d9

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

TORoundedButton/TORoundedButton.m

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -670,18 +670,16 @@ - (UIColor *)_labelBackgroundColor TOROUNDEDBUTTON_OBJC_DIRECT {
670670
}
671671

672672
- (UIColor *)_brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)amount TOROUNDEDBUTTON_OBJC_DIRECT {
673-
// Clamp
673+
// Clamp provided value just in case
674674
amount = fmaxf(0.0, fminf(amount, 1.0));
675675

676676
CGFloat h = 0, s = 0, b = 0, a = 0;
677-
if (![color getHue:&h saturation:&s brightness:&b alpha:&a]) {
678-
return color;
679-
}
677+
if (![color getHue:&h saturation:&s brightness:&b alpha:&a]) { return color; }
680678

681679
// Zones:
682-
// - RED 0.0 / 1.0
683-
// - GREEN 0.33
684-
// - BLUE 0.66
680+
// - RED - 0.0 / 1.0
681+
// - GREEN - 0.33
682+
// - BLUE - 0.66
685683
BOOL isRed = (h < 0.05f || h > 0.95f);
686684
BOOL isGreen = (h > 0.25f && h < 0.45f);
687685
BOOL isBlue = (h > 0.55f && h < 0.75f);
@@ -691,19 +689,19 @@ - (UIColor *)_brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)
691689
CGFloat brightnessAdd = 0.0f;
692690

693691
if (isRed) {
694-
// systemRed nudge toward orange/yellow, slightly brighter, modest sat
692+
// systemRed - nudge toward orange/yellow, slightly brighter, modest sat
695693
hueShift = 0.08f * amount; // towards yellow
696694
satBoost = 0.10f * amount;
697695
brightnessAdd = 0.18f * amount;
698696
}
699697
else if (isGreen) {
700-
// systemGreen nudge toward yellow-green, clearly brighter + more vivid
698+
// systemGreen - nudge toward yellow-green, clearly brighter + more vivid
701699
hueShift = -0.08f * amount; // toward yellow-green
702700
satBoost = 0.25f * amount; // push harder here
703701
brightnessAdd = 0.22f * amount; // stronger lift so it’s clearly changed
704702
}
705703
else if (isBlue) {
706-
// systemBlue nudge toward cyan, bright + vivid
704+
// systemBlue - nudge toward cyan, bright + vivid
707705
hueShift = -0.06f * amount; // toward cyan
708706
satBoost = 0.18f * amount;
709707
brightnessAdd = 0.18f * amount;
@@ -717,8 +715,8 @@ - (UIColor *)_brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)
717715

718716
// Apply hue shift with wrapping
719717
CGFloat newH = h + hueShift;
720-
if (newH < 0.0f) newH += 1.0f;
721-
if (newH > 1.0f) newH -= 1.0f;
718+
if (newH < 0.0f) { newH += 1.0f; }
719+
if (newH > 1.0f) { newH -= 1.0f; }
722720

723721
// Brighten: constant bump + small relative lift if not already maxed
724722
CGFloat newB = b + brightnessAdd + (1.0f - b) * 0.2f * amount;

0 commit comments

Comments
 (0)