diff options
author | jgmdev <jgmdev@gmail.com> | 2022-05-24 19:29:50 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-05-24 19:29:50 -0400 |
commit | 35e947d1933613bb0b5a1488bf0fa4587f98ef7d (patch) | |
tree | 07d2515f44db03b1e865f6aef6adfd12b118890b /plugins/tabnumbers.lua | |
parent | c1f3671e2a8defbc67d1e77c72d5866f2825cdb5 (diff) | |
download | lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.tar.gz lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.zip |
added config_spec and other plugin compatibility fixes.
Diffstat (limited to 'plugins/tabnumbers.lua')
-rw-r--r-- | plugins/tabnumbers.lua | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/plugins/tabnumbers.lua b/plugins/tabnumbers.lua index 1656100..3a842b7 100644 --- a/plugins/tabnumbers.lua +++ b/plugins/tabnumbers.lua @@ -1,28 +1,44 @@ -- mod-version:3 --lite-xl 2.1 +local config = require "core.config" local common = require "core.common" -local core = require "core" local style = require "core.style" +local Node = require "core.node" --- quite hackish, but Node isn't normally public -local Node = getmetatable(core.root_view.root_node) -local draw_tabs = Node.draw_tabs +config.plugins.tabnumbers = common.merge({ + enabled = true, + -- The config specification used by the settings gui + config_spec = { + name = "Tab Numbers", + { + label = "Draw Tab Numbers", + description = "Show or hide numbers on the interface tabs.", + path = "enabled", + type = "toggle", + default = true + } + } +}, config.plugins.tabnumbers) -function Node:draw_tabs(...) - draw_tabs(self, ...) - - for i, view in ipairs(self.views) do - if i > 9 then break end - - local x, y, w, h = self:get_tab_rect(i) - local number = tostring(i) - local color = style.dim - local title_width = style.font:get_width(view:get_name()) - local free_real_estate = - math.min(math.max((w - title_width) / 2, style.padding.x), h) - if view == self.active_view then - color = style.accent +-- Overwrite draw_tab_title to prepend tab number +local Node_draw_tab_title = Node.draw_tab_title +function Node:draw_tab_title(view, font, is_active, is_hovered, x, y, w, h) + if config.plugins.tabnumbers.enabled then + local number = "" + for i, v in ipairs(self.views) do + if view == v then + number = tostring(i) + end + end + local padx = 0 + if number ~= "" then + padx = style.font:get_width(number) + (style.padding.x / 2) + w = w - padx + local color = is_active and style.text or style.dim + common.draw_text(style.font, color, number, nil, x, y, w, h) end - -- renderer.draw_rect(x, y + h - 1, free_real_estate, 1, color) - common.draw_text(style.font, color, number, "center", x, y, free_real_estate, h) + local tx = x + padx -- Space for number + Node_draw_tab_title(self, view, font, is_active, is_hovered, tx, y, w, h) + else + Node_draw_tab_title(self, view, font, is_active, is_hovered, x, y, w, h) end end |