summaryrefslogtreecommitdiff
path: root/lib/luavgl/examples/group.lua
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-11-12 19:14:09 +1100
committerjacqueline <me@jacqueline.id.au>2023-11-12 19:14:09 +1100
commit8a0a167adbf3d9b6f8b6f16aaf20ca39ad5549de (patch)
tree02b6cf23f591915747ec2994381854a79979c4a0 /lib/luavgl/examples/group.lua
parent8471046a95ab9e00f7d42b56dbbc9ce3e5b424b9 (diff)
downloadtangara-fw-8a0a167adbf3d9b6f8b6f16aaf20ca39ad5549de.tar.gz
Convert the main menu screen to lua lol
Diffstat (limited to 'lib/luavgl/examples/group.lua')
-rw-r--r--lib/luavgl/examples/group.lua61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/luavgl/examples/group.lua b/lib/luavgl/examples/group.lua
new file mode 100644
index 00000000..f80dd325
--- /dev/null
+++ b/lib/luavgl/examples/group.lua
@@ -0,0 +1,61 @@
+local function group_example()
+ local g = lvgl.group.create()
+ g:set_default()
+
+ -- for demo purpose, set all indev to use this group
+ local indev = nil
+ while true do
+ indev = lvgl.indev.get_next(indev)
+ if not indev then break end
+
+ local t = indev:get_type()
+ if t == 2 or t == 4 then
+ indev:set_group(g)
+ end
+ end
+
+ local style = lvgl.Style({
+ border_width = 5,
+ border_color = "#a00",
+ })
+
+ local root = lvgl.Object(nil, {
+ w = lvgl.PCT(100),
+ h = lvgl.PCT(100),
+ align = lvgl.ALIGN.CENTER,
+ bg_color = "#aaa",
+ flex = {
+ flex_direction = "row",
+ flex_wrap = "wrap"
+ }
+ })
+
+ root:add_style(style, lvgl.STATE.FOCUSED)
+
+ for _ = 1, 5 do
+ local obj = root:Object({
+ w = lvgl.PCT(50),
+ h = lvgl.PCT(50),
+ bg_color = "#555",
+ })
+
+ obj:add_style(style, lvgl.STATE.FOCUSED)
+
+ obj:onClicked(function(obj, code)
+ print("clicked: ", obj)
+ end)
+
+ obj:onevent(lvgl.EVENT.FOCUSED, function(obj, code)
+ print("focused: ", obj)
+ obj:scroll_to_view(true)
+ end)
+
+ obj:onevent(lvgl.EVENT.DEFOCUSED, function(obj, code)
+ print("defocused: ", obj)
+ end)
+
+ g:add_obj(obj)
+ end
+end
+
+group_example()