From 03243c57410f11c2ee9cd8cbf37ad28bf197f138 Mon Sep 17 00:00:00 2001 From: Ramojus Lapinskas <41536253+ramojus@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:01:12 +0200 Subject: [PATCH] fix(shader): handle cases when one of the colors is NONE (transparent) (#71) * fix(shader): handle cases when one of the shade colors is NONE (transparent) * remove no longer necessary `fallback_if_none` functionality in custom groups No longer needed with the new change in shader. --- lua/mellifluous/highlights/custom_groups.lua | 10 ---------- lua/mellifluous/init.lua | 1 + lua/mellifluous/utils/shader.lua | 11 +++++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/mellifluous/highlights/custom_groups.lua b/lua/mellifluous/highlights/custom_groups.lua index 0ac9ea1..011f11e 100644 --- a/lua/mellifluous/highlights/custom_groups.lua +++ b/lua/mellifluous/highlights/custom_groups.lua @@ -1,12 +1,5 @@ local M = {} -local function fallback_if_none(color, fallback_color) - if type(color) == "string" and color == "NONE" then - return fallback_color - end - return color -end - -- Any shared highlight groups that cannot be found in general highlights or -- treesitter highlights are created here. function M.get(colors) @@ -17,11 +10,9 @@ function M.get(colors) MainKeyword = { fg = colors.main_keywords, style = config.styles.main_keywords or {} }, IndentLine = function(bg) - bg = fallback_if_none(bg, colors.bg) return { fg = shader.replicate_shade(colors.bg, colors.fg5, bg) } end, IndentLineInactive = function(bg) - bg = fallback_if_none(bg, colors.bg) return { fg = config.is_bg_dark and shader.replicate_shade(colors.bg, colors.bg4, bg) or shader.replicate_shade(colors.bg, colors.dark_bg2, bg), @@ -30,7 +21,6 @@ function M.get(colors) MenuButton = { fg = colors.ui_blue }, MenuButtonSelected = function(bg) - bg = fallback_if_none(bg, colors.bg) local applied_bg = config.is_bg_dark and shader.replicate_shade(colors.bg, colors.bg4, bg) or shader.replicate_shade(colors.bg, colors.dark_bg2, bg) return { diff --git a/lua/mellifluous/init.lua b/lua/mellifluous/init.lua index d415abd..92bd016 100644 --- a/lua/mellifluous/init.lua +++ b/lua/mellifluous/init.lua @@ -19,6 +19,7 @@ function M.load() local colors = require("mellifluous.colors").get_colors() local highlighter = require("mellifluous.utils.highlighter") + require("mellifluous.utils.shader").set_background_color(colors.bg) require("mellifluous.highlights").set(highlighter, colors) require("mellifluous.config").set_highlight_overrides(highlighter, colors) diff --git a/lua/mellifluous/utils/shader.lua b/lua/mellifluous/utils/shader.lua index c6373c0..24db30c 100644 --- a/lua/mellifluous/utils/shader.lua +++ b/lua/mellifluous/utils/shader.lua @@ -1,5 +1,7 @@ local M = {} +local bg_color + local function clip(val, from, to) if val > to then return to @@ -10,6 +12,11 @@ local function clip(val, from, to) end function M.replicate_shade(from_color, to_color, target) + -- assume bg_color for any transparent colors + from_color = from_color ~= "NONE" and from_color or bg_color + to_color = to_color ~= "NONE" and to_color or bg_color + target = target ~= "NONE" and target or bg_color + local from_hsl = from_color:get_hsl() local to_hsl = to_color:get_hsl() local color = require("mellifluous.color") @@ -52,4 +59,8 @@ function M.get_higher_contrast(color, amount) return color:darkened(amount) end +function M.set_background_color(new_bg_color) + bg_color = new_bg_color +end + return M