From bede0ff878c2720402c9fbd4152f9ad359cac134 Mon Sep 17 00:00:00 2001 From: Joshua Minor Date: Sun, 21 Nov 2021 00:24:24 -0800 Subject: [PATCH 1/2] Allow for color overrides in the tree view --- data/plugins/treeview.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index fa3ab53a..8768f036 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -43,6 +43,7 @@ function TreeView:new() self.cache = {} self.last = {} self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 } + self.color_overrides = {} end @@ -295,6 +296,16 @@ function TreeView:draw_tooltip() end +function TreeView:set_color_override(abs_filename, color) + self.color_overrides[abs_filename] = color +end + + +function TreeView:clear_all_color_overrides() + self.color_overrides = {} +end + + function TreeView:draw() self:draw_background(style.background2) @@ -318,6 +329,9 @@ function TreeView:draw() color = style.accent end + -- allow for color overrides + local icon_color = self.color_overrides[item.abs_filename] or color + -- icons x = x + item.depth * style.padding.x + style.padding.x if item.type == "dir" then @@ -325,11 +339,11 @@ function TreeView:draw() local icon2 = item.expanded and "D" or "d" common.draw_text(style.icon_font, color, icon1, nil, x, y, 0, h) x = x + style.padding.x - common.draw_text(style.icon_font, color, icon2, nil, x, y, 0, h) + common.draw_text(style.icon_font, icon_color, icon2, nil, x, y, 0, h) x = x + icon_width else x = x + style.padding.x - common.draw_text(style.icon_font, color, "f", nil, x, y, 0, h) + common.draw_text(style.icon_font, icon_color, "f", nil, x, y, 0, h) x = x + icon_width end From 373007a7675a0de7add8447c0b42eb5bd64f5f24 Mon Sep 17 00:00:00 2001 From: Joshua Minor Date: Sun, 21 Nov 2021 15:24:45 -0800 Subject: [PATCH 2/2] Switched to TreeView:color_for_item(abs_path) --- data/plugins/treeview.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 8768f036..70dca08f 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -43,7 +43,6 @@ function TreeView:new() self.cache = {} self.last = {} self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 } - self.color_overrides = {} end @@ -296,13 +295,9 @@ function TreeView:draw_tooltip() end -function TreeView:set_color_override(abs_filename, color) - self.color_overrides[abs_filename] = color -end - - -function TreeView:clear_all_color_overrides() - self.color_overrides = {} +function TreeView:color_for_item(abs_filename) + -- other plugins can override this to customize the color of each icon + return nil end @@ -330,7 +325,7 @@ function TreeView:draw() end -- allow for color overrides - local icon_color = self.color_overrides[item.abs_filename] or color + local icon_color = self:color_for_item(item.abs_filename) or color -- icons x = x + item.depth * style.padding.x + style.padding.x