aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-05-24 12:26:41 +0100
committerrxi <rxi@users.noreply.github.com>2020-05-24 12:26:41 +0100
commit9e2cf49be6973dbf6df380b43ccb929fb92761b0 (patch)
treec885039e3afafa7f120b3c9f58f49f7dc778ca77
parent7b3f917f65233d41918e4c0dd363ea75e04fb4b8 (diff)
downloadlite-xl-plugins-9e2cf49be6973dbf6df380b43ccb929fb92761b0.tar.gz
lite-xl-plugins-9e2cf49be6973dbf6df380b43ccb929fb92761b0.zip
Added `bigclock` plugin
-rw-r--r--README.md1
-rw-r--r--plugins/bigclock.lua71
2 files changed, 72 insertions, 0 deletions
diff --git a/README.md b/README.md
index e78823d..7861183 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ to a something other than a raw file it should be marked with an asterisk.*
Plugin | Description
-------|-----------------------------------------
[`autowrap`](plugins/autowrap.lua?raw=1) | Automatically hardwraps lines when typing
+[`bigclock`](plugins/bigclock.lua?raw=1) | Shows the current time and date in a view with large text *([screenshot](https://user-images.githubusercontent.com/3920290/82752891-3318df00-9db9-11ea-803f-261d80d5cf53.png))*
[`bracketmatch`](plugins/bracketmatch.lua?raw=1) | Underlines matching pair for bracket under the caret *([screenshot](https://user-images.githubusercontent.com/3920290/80132745-0c863f00-8594-11ea-8875-c455c6fd7eae.png))*
[`centerdoc`](plugins/centerdoc.lua?raw=1) | Centers document's content on the screen *([screenshot](https://user-images.githubusercontent.com/3920290/82127896-bf6e4500-97ae-11ea-97fc-ba9a552bc9a4.png))*
[`colorpreview`](plugins/colorpreview.lua?raw=1) | Underlays color values (eg. `#ff00ff` or `rgb(255, 0, 255)`) with their resultant color. *([screenshot](https://user-images.githubusercontent.com/3920290/80743752-731bd780-8b15-11ea-97d3-847db927c5dc.png))*
diff --git a/plugins/bigclock.lua b/plugins/bigclock.lua
new file mode 100644
index 0000000..67d62e2
--- /dev/null
+++ b/plugins/bigclock.lua
@@ -0,0 +1,71 @@
+local core = require "core"
+local style = require "core.style"
+local command = require "core.command"
+local common = require "core.common"
+local config = require "core.config"
+local View = require "core.view"
+
+
+config.bigclock_time_format = "%H:%M:%S"
+config.bigclock_date_format = "%A, %d %B %Y"
+config.bigclock_scale = 1
+
+
+local ClockView = View:extend()
+
+
+function ClockView:new()
+ ClockView.super.new(self)
+ self.time_text = ""
+ self.date_text = ""
+end
+
+
+function ClockView:get_name()
+ return "Big Clock"
+end
+
+
+function ClockView:update_fonts()
+ local size = math.floor(self.size.x * 0.15) * config.bigclock_scale
+ if self.font_size ~= size then
+ self.time_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", size)
+ self.date_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", size * 0.3)
+ self.font_size = size
+ end
+ return self.font
+end
+
+
+function ClockView:update()
+ local time_text = os.date(config.bigclock_time_format)
+ local date_text = os.date(config.bigclock_date_format)
+ if self.time_text ~= time_text or self.date_text ~= date_text then
+ core.redraw = true
+ self.time_text = time_text
+ self.date_text = date_text
+ end
+ ClockView.super.update(self)
+end
+
+
+function ClockView:draw()
+ self:update_fonts()
+ self:draw_background(style.background)
+ local x, y = self.position.x, self.position.y
+ local w, h = self.size.x, self.size.y
+ local _, y = common.draw_text(self.time_font, style.text, self.time_text, "center", x, y, w, h)
+ local th = self.date_font:get_height()
+ common.draw_text(self.date_font, style.dim, self.date_text, "center", x, y, w, th)
+end
+
+
+command.add(nil, {
+ ["big-clock:open"] = function()
+ local node = core.root_view:get_active_node()
+ node:add_view(ClockView())
+ end,
+})
+
+
+return ClockView