From 86a589442954fe60471d06c028a0ac65a53eca9e Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Fri, 9 Aug 2024 14:54:00 -0300 Subject: [PATCH] Hack luminance tweaking for creating highlight color (needs a proper implementation) --- src/styles.cr | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/styles.cr b/src/styles.cr index 08dba64..9b2686d 100644 --- a/src/styles.cr +++ b/src/styles.cr @@ -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