From b07bfbc6c70fd0bba8dff85fe4149feb9fa9b8d4 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 23 Nov 2023 10:40:04 +1100 Subject: Add a second font, flesh out browser screen --- src/lua/lua_thread.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/lua') diff --git a/src/lua/lua_thread.cpp b/src/lua/lua_thread.cpp index e1df3087..4704c3e8 100644 --- a/src/lua/lua_thread.cpp +++ b/src/lua/lua_thread.cpp @@ -8,14 +8,20 @@ #include +#include "lua.hpp" + +#include "font/lv_font_loader.h" +#include "luavgl.h" + #include "esp_heap_caps.h" #include "esp_log.h" #include "event_queue.hpp" -#include "lua.hpp" -#include "luavgl.h" #include "service_locator.hpp" #include "ui_events.hpp" +LV_FONT_DECLARE(font_fusion_12); +LV_FONT_DECLARE(font_fusion_10); + namespace lua { [[maybe_unused]] static constexpr char kTag[] = "lua"; @@ -50,6 +56,21 @@ static int lua_panic(lua_State* L) { return 0; } +static auto make_font_cb(const char* name, int size, int weight) + -> const lv_font_t* { + if (std::string{"fusion"} == name) { + if (size == 12) { + return &font_fusion_12; + } + if (size == 10) { + return &font_fusion_10; + } + } + return NULL; +} + +static auto delete_font_cb(lv_font_t* font) -> void {} + auto LuaThread::Start(system_fsm::ServiceLocator& services, lv_obj_t* lvgl_root) -> LuaThread* { auto alloc = std::make_unique(); @@ -66,6 +87,7 @@ auto LuaThread::Start(system_fsm::ServiceLocator& services, lv_obj_t* lvgl_root) // FIXME: luavgl init should probably be a part of the bridge. if (lvgl_root) { luavgl_set_pcall(state, CallProtected); + luavgl_set_font_extension(state, make_font_cb, delete_font_cb); luavgl_set_root(state, lvgl_root); luaL_requiref(state, "lvgl", luaopen_lvgl, true); lua_pop(state, 1); -- cgit v1.2.3