XuNeo / luavgl

lua + lvgl = luavgl An optimized lvgl Lua binding
MIT License
68 stars 15 forks source link

feat(obj): allow to create child obj inside property table #47

Closed XuNeo closed 5 months ago

XuNeo commented 5 months ago

This patch allows to create child obj directly in the property table. To make it looks like children are created recursively.

In fact, with this coding style, the children is created firstly and it's stored to property table with integer key. Simply find them out and set parent for them.

local lvgl = require("lvgl")

local root = lvgl.Object(nil, {
    flex = {
        flex_direction = "row",
        flex_wrap = "wrap",
        justify_content = "center",
        align_items = "center",
        align_content = "center",
    },
    w = 300,
    h = 75,
    align = lvgl.ALIGN.CENTER,
    lvgl.Object(nil, {
        w = 100,
        h = lvgl.PCT(100),
        lvgl.Label(nil, {
            text = string.format("label %d", 1)
        }):center()
    }):clear_flag(lvgl.FLAG.SCROLLABLE),

    lvgl.Object(nil, {
        w = 100,
        h = lvgl.PCT(100),
        lvgl.Label(nil, {
            text = string.format("label %d", 1)
        }):center()
    }):clear_flag(lvgl.FLAG.SCROLLABLE)
})