Hack luminance tweaking for creating highlight color (needs a proper implementation)

This commit is contained in:
Roberto Alsina 2024-08-09 14:54:00 -03:00
parent be12e0f4f1
commit 86a5894429

View File

@ -173,17 +173,19 @@ module Tartrazine
# If the color is dark, make it brighter and viceversa
def self.make_highlight_color(base_color)
# FIXME: do a proper luminance adjustment in the color class
return nil if base_color.nil?
color = Color.new(base_color.hex)
if base_color.light?
color.r = [(base_color.r / 1.2), 255].min.to_u8
color.g = [(base_color.g / 1.2), 255].min.to_u8
color.b = [(base_color.b / 1.2), 255].min.to_u8
color.r = [(base_color.r - 40), 255].min.to_u8
color.g = [(base_color.g - 40), 255].min.to_u8
color.b = [(base_color.b - 40), 255].min.to_u8
else
color.r = [(base_color.r * 1.2), 255].min.to_u8
color.g = [(base_color.g * 1.2), 255].min.to_u8
color.b = [(base_color.b * 1.2), 255].min.to_u8
color.r = [(base_color.r + 40), 255].min.to_u8
color.g = [(base_color.g + 40), 255].min.to_u8
color.b = [(base_color.b + 40), 255].min.to_u8
end
# Bug in color, setting rgb doesn't update hex
color.hex = "#{color.r.to_s(16)}#{color.g.to_s(16)}#{color.b.to_s(16)}"
color
end