main.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. -- Win 组件测试脚本
  2. PROJECT = "easylvgl"
  3. VERSION = "1.0.0"
  4. sys.taskInit(function()
  5. -- 1. 初始化 EasyLVGL
  6. -- easylvgl.init(w, h, buff_size, buff_mode)
  7. -- w: 屏幕宽,可选,默认480
  8. -- h: 屏幕高,可选,默认320
  9. -- color_format: 颜色格式,可选,默认ARGB8888
  10. -- 可用值:easylvgl.COLOR_FORMAT_RGB565(默认,嵌入式,节省内存)
  11. -- easylvgl.COLOR_FORMAT_ARGB8888(pc,高质量)
  12. local ret = easylvgl.init(800, 600, easylvgl.COLOR_FORMAT_ARGB8888)
  13. if not ret then
  14. log.error("easylvgl", "init failed")
  15. return
  16. end
  17. -- 窗口组件
  18. local win = easylvgl.win({
  19. parent = easylvgl.screen,
  20. title = "Settings", -- 标题文本,可选
  21. x = 40, y = 40, w = 600, h = 400, -- x, y, w, h
  22. close_btn = false, -- 是否显示关闭按钮,默认 false
  23. auto_center = false, -- 是否自动居中,默认 true
  24. on_close = function(self) -- 关闭回调
  25. log.info("easylvgl.win", "win:on_close called")
  26. end
  27. })
  28. --label
  29. local label = easylvgl.label({
  30. text = "win test",
  31. x = 0, y = 0, w = 120, h = 40,
  32. })
  33. -- 下拉框组件
  34. local dropdown = easylvgl.dropdown({
  35. options = {"Option A", "Option B", "Option C"}, -- 选项列表(字符串数组)
  36. default_index = 2, -- 默认选中项索引,默认 -1
  37. x = 0, y = 40, w = 180, h = 50,
  38. on_change = function(self, index) -- 选中项变化回调
  39. log.info("dropdown", "selected index", index)
  40. end
  41. })
  42. -- 不可点击图片
  43. local img = easylvgl.image({
  44. src = "/luadb/logo.png",
  45. x = 0, y = 240, w = 80, h = 80,
  46. zoom = 256, -- 缩放比例,默认 256(100%)
  47. opacity = 255, -- 透明度,默认 255(不透明),范围 0-255
  48. })
  49. --先创建按钮(不指定 parent,默认添加到屏幕)
  50. local inner_btn = easylvgl.button({
  51. text = "Close",
  52. x = 0, y = 340, w = 120, h = 40,
  53. on_click = function(self)
  54. log.info("easylvgl.win", "inner button closing window")
  55. win:close()
  56. end
  57. })
  58. -- 将按钮添加到窗口内容区域
  59. win:add_content(inner_btn)
  60. win:add_content(label)
  61. win:add_content(dropdown)
  62. win:add_content(img)
  63. -- 设置窗口标题
  64. win:set_title("Settings Window")
  65. while true do
  66. easylvgl.refresh()
  67. sys.wait(10)
  68. end
  69. end)
  70. sys.run()