diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-03-10 13:20:17 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-03-10 13:20:17 +1100 |
| commit | 1133d4621508b7ec6bac4ab8731f3493066ceeee (patch) | |
| tree | ef9e703effe08f9fb63e26a72c2e498e8ff62012 /src/lua/lua_theme.cpp | |
| parent | 20c2816a7b2497c2ab0d07a65fb640050a929371 (diff) | |
| download | tangara-fw-1133d4621508b7ec6bac4ab8731f3493066ceeee.tar.gz | |
WIP Lua Theming- style classes
Diffstat (limited to 'src/lua/lua_theme.cpp')
| -rw-r--r-- | src/lua/lua_theme.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lua/lua_theme.cpp b/src/lua/lua_theme.cpp index 7b007f4d..2fcd71e5 100644 --- a/src/lua/lua_theme.cpp +++ b/src/lua/lua_theme.cpp @@ -22,17 +22,19 @@ namespace lua { -static auto set_theme(lua_State* L) -> int { - // lv_style_t* style = luavgl_to_style(L, -1); - // if (style == NULL) { - // ESP_LOGI("DANIEL", "Style was null or malformed??"); - // return 0; - // } - - // ESP_LOGI("DANIEL", "GOT ONE!"); - // themes::Theme::instance()->...; +static auto set_style(lua_State* L) -> int { + // Get the object and class name from the stack + if (lua_type(L, -1) == LUA_TSTRING) { + std::string class_name = lua_tostring(L, -1); + lv_obj_t* obj = luavgl_to_obj(L, -2); + if (obj != NULL) { + ui::themes::Theme::instance()->ApplyStyle(obj, class_name); + } + } + return 0; +} - /* table is in the stack at index 't' */ +static auto set_theme(lua_State* L) -> int { std::string class_name; lua_pushnil(L); /* first key */ while (lua_next(L, -2) != 0) { @@ -61,7 +63,6 @@ static auto set_theme(lua_State* L) -> int { return 0; } else { ui::themes::Theme::instance()->AddStyle(class_name, selector, style); - ESP_LOGI("DANIEL", "Got style for class %s with selector %d", class_name.c_str(), selector); } } lua_pop(L, 1); @@ -75,7 +76,7 @@ static auto set_theme(lua_State* L) -> int { return 0; } -static const struct luaL_Reg kThemeFuncs[] = {{"set", set_theme}, {NULL, NULL}}; +static const struct luaL_Reg kThemeFuncs[] = {{"set", set_theme}, {"set_style", set_style}, {NULL, NULL}}; static auto lua_theme(lua_State* L) -> int { luaL_newlib(L, kThemeFuncs); |
