aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-06-03 14:18:00 +0100
committerrxi <rxi@users.noreply.github.com>2020-06-03 14:25:49 +0100
commit18cee87818658c49167123677c978c16c9d7318c (patch)
treef5ec01c7ebbcd62c3e476748d0217bd79d931228
parentb812a82c8ff186076cf570e242214cf714d64e64 (diff)
downloadlite-xl-plugins-18cee87818658c49167123677c978c16c9d7318c.tar.gz
lite-xl-plugins-18cee87818658c49167123677c978c16c9d7318c.zip
Added `scale` plugin
-rw-r--r--README.md1
-rw-r--r--plugins/scale.lua62
2 files changed, 63 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9c8a18d..466160a 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,7 @@ Plugin | Description
[`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))*
[`openfilelocation`](plugins/openfilelocation.lua?raw=1) | Opens the parent directory of the current file in the file manager
[`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url
+[`scale`](plugins/scale.lua?raw=1) | Provides support for dynamically adjusting the scale of the UI (`ctrl+-`, `ctrl+=`)
[`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection *([screenshot](https://user-images.githubusercontent.com/3920290/80710883-5f597c80-8ae7-11ea-97f0-76dfacc08439.png))*
[`sort`](plugins/sort.lua?raw=1) | Sorts selected lines alphabetically
[`spellcheck`](plugins/spellcheck.lua?raw=1) | Underlines misspelt words *([screenshot](https://user-images.githubusercontent.com/3920290/79923973-9caa7400-842e-11ea-85d4-7a196a91ca50.png))* On Windows no dictionary file exists for spellchecking. You can add a words.txt file beside the exe to remedy this. [Example file](https://github.com/dwyl/english-words/blob/master/words.txt)
diff --git a/plugins/scale.lua b/plugins/scale.lua
new file mode 100644
index 0000000..52ac73b
--- /dev/null
+++ b/plugins/scale.lua
@@ -0,0 +1,62 @@
+local core = require "core"
+local command = require "core.command"
+local keymap = require "core.keymap"
+local style = require "core.style"
+
+
+local font_cache = setmetatable({}, { __mode = "k" })
+
+-- the following should be kept in sync with core.style's default font settings
+font_cache[style.font] = { EXEDIR .. "/data/fonts/font.ttf", 14 * SCALE }
+font_cache[style.big_font] = { EXEDIR .. "/data/fonts/font.ttf", 34 * SCALE }
+font_cache[style.icon_font] = { EXEDIR .. "/data/fonts/icons.ttf", 14 * SCALE }
+font_cache[style.code_font] = { EXEDIR .. "/data/fonts/monospace.ttf", 13.5 * SCALE }
+
+
+local load_font = renderer.font.load
+function renderer.font.load(...)
+ local res = load_font(...)
+ font_cache[res] = { ... }
+ return res
+end
+
+
+local function scale_font(font, s)
+ local fc = font_cache[font]
+ return renderer.font.load(fc[1], fc[2] * s)
+end
+
+
+local function set_scale(scale)
+ local s = scale / SCALE
+
+ style.padding.x = style.padding.x * s
+ style.padding.y = style.padding.y * s
+ style.divider_size = style.divider_size * s
+ style.scrollbar_size = style.scrollbar_size * s
+ style.caret_width = style.caret_width * s
+ style.tab_width = style.tab_width * s
+
+ style.font = scale_font(style.font, s)
+ style.big_font = scale_font(style.big_font, s)
+ style.icon_font = scale_font(style.icon_font, s)
+ style.code_font = scale_font(style.code_font, s)
+
+ SCALE = scale
+ core.redraw = true
+end
+
+
+command.add(nil, {
+ ["scale:reset" ] = function() set_scale(1) end,
+ ["scale:decrease"] = function() set_scale(SCALE * 0.9) end,
+ ["scale:increase"] = function() set_scale(SCALE * 1.1) end,
+})
+
+keymap.add {
+ ["ctrl+0"] = "scale:reset",
+ ["ctrl+-"] = "scale:decrease",
+ ["ctrl+="] = "scale:increase",
+}
+
+return { set_scale = set_scale }