Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of mixed UI programming with Lua and C #65

Merged
merged 3 commits into from
Aug 18, 2024
Merged

Add example of mixed UI programming with Lua and C #65

merged 3 commits into from
Aug 18, 2024

Conversation

XuNeo
Copy link
Owner

@XuNeo XuNeo commented Aug 18, 2024

With this update, you can now design your UI in Lua and seamlessly integrate it with C, merging the simplicity of luavgl with the power of C.

Say goodbye to hundreds of lines of style settings—luavgl makes UI creation a breeze!

static const char lua_code_string[] = STRINGIZE(
    local root = lvgl.get_child_by_id("luaUIroot")
    root.w = lvgl.VER_RES(),
    root.h = lvgl.HOR_RES(),

    Button(root, {
        id = "Button in Lua",
        Label {
            text = "Hello, lua, C and lvgl!",
            align = lvgl.ALIGN_CENTER
        }
    }):center()
);

static int embed_lua_in_c(lua_State *L)
{
  /* We create a root obj in C and create other UIs in lua. */
  lv_obj_t *root = lv_obj_create(lv_screen_active());
  luavgl_add_lobj(L, root)->lua_created = false;
  lv_obj_set_id(root, lv_strdup("luaUIroot"));
  luaL_dostring(L, lua_code_string);
  return 0;
}

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
@XuNeo XuNeo merged commit 61f999d into master Aug 18, 2024
1 check passed
@XuNeo XuNeo deleted the t7 branch August 18, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant