win_button.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --[[
  2. @module win_button
  3. @summary 基础按钮组件演示模块
  4. @version 1.0.0
  5. @date 2025.12.9
  6. @author 江访
  7. @usage
  8. 本文件为基础按钮组件演示模块,核心业务逻辑为:
  9. 1、创建窗口容器并设置白色背景;
  10. 2、添加基础按钮组件;
  11. 3、启动UI渲染循环持续刷新显示;
  12. 本文件没有对外接口;
  13. ]]
  14. local function ui_main()
  15. -- 显示触摸初始化
  16. hw_font_drv.init()
  17. -- 设置主题
  18. ui.sw_init({ theme = "light" })
  19. -- 创建窗口容器
  20. local page1 = ui.window({ background_color = ui.COLOR_WHITE })
  21. -- 计算居中位置
  22. local page_w, page_h = lcd.getSize()
  23. local button_width = 200
  24. local button_height = 50
  25. local button_x = (page_w - button_width) / 2
  26. local button_y = (page_h - button_height) / 2
  27. -- 创建按钮组件(文本模式)
  28. local btn1 = ui.button({
  29. x = button_x, y = button_y,
  30. w = button_width, h = button_height,
  31. text = "基础按钮",
  32. bg_color = ui.COLOR_BLUE,
  33. text_color = ui.COLOR_WHITE,
  34. size = 18
  35. })
  36. -- 添加说明标签
  37. local title_label = ui.label({
  38. x = button_x, y = button_y - 60,
  39. text = "基础按钮演示",
  40. color = ui.COLOR_BLACK,
  41. size = 24
  42. })
  43. -- 添加组件到窗口
  44. page1:add(title_label)
  45. page1:add(btn1)
  46. -- 注册窗口到UI系统
  47. ui.add(page1)
  48. -- 启动exeasyui刷新主循环
  49. while true do
  50. -- 刷新显示
  51. ui.refresh()
  52. -- 等待30ms
  53. sys.wait(30)
  54. end
  55. end
  56. sys.taskInit(ui_main)