Configurable statusview icon (#1617)

* docs(core.statusview): fix item.visible being mandatory

* feat: make the line icon configurable

* fix: empty icons

* fix: use user specified font

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

* fix: never draw anything if disabled

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

* fix: always add stonks icon

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>

* feat: add rgb functionality

* fix: reduce number of color changes

---------

Co-authored-by: Guldoman <giulio.lettieri@gmail.com>
This commit is contained in:
Takase 2024-09-04 01:42:55 +08:00 committed by GitHub
parent f5df5d6626
commit 872364ded3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 4 deletions

View File

@ -260,6 +260,13 @@ config.max_clicks = 3
---@type boolean
config.skip_plugins_version = false
---Increases the performance of the editor and its user.
---Do not change this unless you know what you are doing.
---
---Defaults to true.
---@type boolean | { font: renderer.font, icon: string } | nil
config.stonks = true
-- holds the plugins real config table
local plugins_config = {}

View File

@ -94,7 +94,7 @@ local StatusViewItem = Object:extend()
---of 1 will insert the item at the beggining.
---@field position? integer
---@field tooltip? string @Text displayed when mouse hovers the item.
---@field visible boolean @Flag to show or hide the item
---@field visible? boolean @Flag to show or hide the item
---The type of separator rendered to the right of the item if another item
---follows it.
---@field separator? core.statusview.item.separator
@ -190,6 +190,9 @@ function StatusView:new()
self:register_command_items()
end
local clicks = -1
local gx, gy, dx, dy, gc = 0, 0, 2, -2, { table.unpack(style.text) }
---The predefined status bar items displayed when a document view is active.
function StatusView:register_docview_items()
if self:get_item("doc:file") then return end
@ -291,6 +294,28 @@ function StatusView:register_docview_items()
separator = self.separator2
})
self:add_item({
predicate = predicate_docview,
name = "doc:stats",
alignment = StatusView.Item.RIGHT,
get_item = function()
return config.stonks == nil and {} or {
style.text,
type(config.stonks) == "table" and config.stonks.font or style.icon_font,
type(config.stonks) == "table" and config.stonks.icon or ( config.stonks and "g" or "h" ),
}
end,
separator = self.separator2,
command = function(button, x, y)
if button == "left" then
clicks = clicks + 1
elseif button == "right" then
clicks = -1
end
gx, gy = x, y
end
})
self:add_item({
predicate = predicate_docview,
name = "doc:lines",
@ -298,9 +323,6 @@ function StatusView:register_docview_items()
get_item = function()
local dv = core.active_view
return {
style.text,
style.icon_font, "g",
style.font, style.dim, self.separator2,
style.text, #dv.doc.lines, " lines",
}
end,
@ -1213,6 +1235,25 @@ function StatusView:draw()
end
end
end
if clicks > 5 then
if config.stonks == nil then clicks = -1 end
core.root_view:defer_draw(function()
local font = type(config.stonks) == "table" and config.stonks.font or style.icon_font
local icon = type(config.stonks) == "table" and config.stonks.icon or ( config.stonks and "g" or "h" )
local xadv = renderer.draw_text(font, icon, gx, gy, gc)
local x2, y2 = core.root_view.size.x - (xadv - gx), core.root_view.size.y - font:get_height()
gx, gy = common.clamp(gx + dx, 0, x2), common.clamp(gy + dy, 0, y2)
local odx, ody = dx, dy
if gx <= 0 then dx = math.abs(dx) elseif gx >= x2 then dx = -math.abs(dx) end
if gy <= 0 then dy = math.abs(dy) elseif gy >= y2 then dy = -math.abs(dy) end
if odx ~= dx or ody ~= dy then
local major = math.random(1, 3)
for i = 1, 3 do gc[i] = major == i and math.random(200, 255) or math.random(0, 100) end
end
core.redraw = true
end)
end
end
return StatusView

Binary file not shown.

View File

@ -195,6 +195,20 @@
"search": [
"lite-xl4"
]
},
{
"uid": "b1c9ba6ba7db344177bf4906b41303ee",
"css": "chart-line-down",
"code": 104,
"src": "custom_icons",
"selected": true,
"svg": {
"path": "M1071.4 728.2V485.5Q1071.4 473.8 1060.5 469 1049.7 464.3 1040.7 473.2L973.2 540.7 620 187.5Q614.4 181.9 607.1 181.9 599.9 181.9 594.3 187.5L464.3 317.5 232.1 85.4 125 192.5 451.5 519Q457 524.6 464.3 524.6 471.5 524.6 477.1 519L607.1 389 866.1 647.9 798.5 715.4Q789.6 724.3 794.4 735.2 799.1 746.1 810.8 746.1H1053.6Q1061.4 746.1 1066.4 741.1 1071.4 736 1071.4 728.2ZM1142.9 799.7V871.1H0V14H71.4V799.7Z",
"width": 1154
},
"search": [
"_481_fontawesome"
]
}
]
}