From 872364ded3525e91f71d5f70622e25b875143d11 Mon Sep 17 00:00:00 2001 From: Takase <20792268+takase1121@users.noreply.github.com> Date: Wed, 4 Sep 2024 01:42:55 +0800 Subject: [PATCH] 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 * fix: never draw anything if disabled Co-authored-by: Guldoman * fix: always add stonks icon Co-authored-by: Guldoman * feat: add rgb functionality * fix: reduce number of color changes --------- Co-authored-by: Guldoman --- data/core/config.lua | 7 +++++ data/core/statusview.lua | 49 ++++++++++++++++++++++++++++++++--- data/fonts/icons.ttf | Bin 10516 -> 10684 bytes scripts/fontello-config.json | 14 ++++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/data/core/config.lua b/data/core/config.lua index 8e7df316..e564f42d 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -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 = {} diff --git a/data/core/statusview.lua b/data/core/statusview.lua index 74124768..f8d951bb 100644 --- a/data/core/statusview.lua +++ b/data/core/statusview.lua @@ -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 diff --git a/data/fonts/icons.ttf b/data/fonts/icons.ttf index 5fd6d9e9cc85ad0c24ecbc32cada5a97ee255a0c..33d62b11e17e5a8439e3240aad85f00cf9081b4e 100644 GIT binary patch delta 877 zcmZ`%T}YEr7=GV#zMpN*&6V5SH)-Z{R!;Mupud%Zqr8xkNQ!d)&f0YN-wz2Rq3)_L zLa4|~^Cn{`Swaw9bW!3(bR|VUf@Fo{4}$5}yP+3dbY9-?Jv0}=nH8^eT00r;VYo~{g|MJobOW=QuoM_R)5g=<#;oH_uLu_e$MAwGrl z_f&N)p-av4KRjOngax99gH3_P?D=oq0Maep~I1m zrbzSACl3I2r`}#YgZI=LY|mK%q{RRWz!NhsRRguJfB>)KwiE(@`W>CB%(8f|rm2O@ z<-&v#S9c}C3;BsCfOwRt9jsJT$VXBOxm$h5DpS%NiH){C3JF(LA4@hH;}rTg1tm7g z?dT2?jAt5U>t@CcdN-52V{^h!mUd(e5fH16k0w{2_9f9JaDaNucXVzwOIJ&}{(pMx zt?r?rp8;s|LNBiX2e`oJJD7wZSd0dauuWtPc@_Ntfjkig02#S6kqt;Fa&Z7S?@<)R zrMN7q9-Cd3ow?biB_1=PC)12MGTMp`Bg&F(KNgkQtvfBn7GbYdU$OB>GD*?7i&!b< zo5d*da=qTTC>#81H!CkMCK>b*idNeJehhPXkzy^Bp zD4xX#K4$`(;U0dCPYDIWiWn8gr5%!A>XD{ouY6rz)zu`doiT$=k65gx+DEWB_R?O2 z^iF=Kl`u?KJ&xHFb3-uD(Uli!ZEMPFZ0~JTlax#~SJ|V_(Vnt5+BDCJom0k5e*s+2 B$2B(v-R;Ad0S<`%J)+{!(Q9*A7 z1wnn{NeW*4Jeaz+Amk(-w5asrStu4n5OQdWVr898Q}F5zZ)bl0nLqn@`x+znPTcOk zUI8G(0FcS*nsMRUPy)FQz#hy_R>STtO9fDp*pKCnf_^UX`zmqyZYAu~UZ7riPjzY0q$!dw! zzN5$=Y=f@V3=;Lc29P-9@I_6}&3URT$UOkeQ=>9b{rdi;01#ZnO^+Fuaz_5hiw6L` z zuN?l(O>A=8WVdM5Rvx&xmS{1XV&5IxQz@Ltdt{N|b(9 TdYy4=mU(9_vT;)g&3pa=D)N__ diff --git a/scripts/fontello-config.json b/scripts/fontello-config.json index 76349182..e68f4cc3 100644 --- a/scripts/fontello-config.json +++ b/scripts/fontello-config.json @@ -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" + ] } ] } \ No newline at end of file