Skip to content

Commit

Permalink
feat(example): add userdata example
Browse files Browse the repository at this point in the history
Similar to lvgl user_data, the lua lvgl obj also have user_data for user. It uses userdata's uservalue for this purpose.

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
  • Loading branch information
XuNeo committed Aug 5, 2024
1 parent 6cae749 commit 55a7606
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
1 change: 1 addition & 0 deletions examples/examples.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ createBtn(container, "keyboard")
createBtn(container, "animation")
createBtn(container, "pointer")
createBtn(container, "analogTime")
createBtn(container, "userdata")
createBtn(container, "flappyBird/flappyBird")
createBtn(container, "tests")
29 changes: 29 additions & 0 deletions examples/userdata.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- user_data can store any type of lua value
local obj1 = lvgl.Label {
text_color = "#333",
border_color = "#f00",
border_width = 1,
align = lvgl.ALIGN.TOP_LEFT
}

obj1.user_data = 123.456
obj1.text = "user_data:\n" .. obj1.user_data

-- use user_data to store table
local obj2 = lvgl.Label {
text_color = "#333",
border_color = "#f00",
border_width = 1,
align = lvgl.ALIGN.TOP_RIGHT
}

obj2.user_data = {
abc = "hello",
def = "world",
[1] = 123,
}
obj2.text = "user_data:"
for k, v in pairs(obj2.user_data) do
print(k, v)
obj2.text = obj2.text .. string.format("%s: %s\n", k, v)
end
34 changes: 0 additions & 34 deletions examples/uservalue.lua

This file was deleted.

0 comments on commit 55a7606

Please sign in to comment.