diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-07-03 10:43:54 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-07-03 10:43:54 +1000 |
| commit | 88ac96242f0d36e53876ece9f90baf776616f0bc (patch) | |
| tree | 4a937dd3f5f0178e91d5b797a276187a0fa7b64b /lua/font.lua | |
| parent | cbcf1bea617a8f57fe80264e4b96da9274d133f0 (diff) | |
| download | tangara-fw-88ac96242f0d36e53876ece9f90baf776616f0bc.tar.gz | |
Load fonts asynchronously on a bg task
This saves a second or two from bootup; AFAICT this *mostly* reclaims
the dynamic fonts boot time regression.
Diffstat (limited to 'lua/font.lua')
| -rw-r--r-- | lua/font.lua | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/lua/font.lua b/lua/font.lua index 7afa1e01..c76602ec 100644 --- a/lua/font.lua +++ b/lua/font.lua @@ -1,6 +1,36 @@ local lvgl = require("lvgl") -return { - fusion_12 = lvgl.Font("//lua/fonts/fusion12"), - fusion_10 = lvgl.Font("//lua/fonts/fusion10"), +local fonts = {} +local fonts_priv = { + has_invoked_cb = false, + cb = nil, } + +function fonts_priv.has_loaded_all() + return fonts.fusion_12 and fonts.fusion_10 +end + +function fonts_priv.invoke_cb() + if fonts_priv.has_invoked_cb or not fonts_priv.cb then return end + if not fonts_priv.has_loaded_all() then return end + fonts_priv.has_invoked_cb = true + fonts_priv.cb() +end + +lvgl.Font("//lua/fonts/fusion12", function(font) + fonts.fusion_12 = font + fonts_priv.invoke_cb() +end) + +lvgl.Font("//lua/fonts/fusion10", function(font) + fonts.fusion_10 = font + fonts_priv.invoke_cb() +end) + +function fonts.on_loaded(cb) + fonts_priv.cb = cb + fonts_priv.has_invoked_cb = false + fonts_priv.invoke_cb() +end + +return fonts |
