win_message_box.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --[[
  2. @module win_message_box
  3. @summary 消息框组件演示模块
  4. @version 1.0.0
  5. @date 2025.12.9
  6. @author 江访
  7. @usage
  8. 本文件为消息框组件演示模块,核心业务逻辑为:
  9. 1、创建窗口容器并设置白色背景;
  10. 2、添加消息框组件显示通知信息;
  11. 3、启用自动换行功能显示长文本;
  12. 4、启动UI渲染循环持续刷新显示;
  13. 本文件没有对外接口;
  14. ]]
  15. local function ui_main()
  16. -- 显示触摸初始化
  17. hw_font_drv.init()
  18. -- 设置主题
  19. ui.sw_init({ theme = "light" })
  20. -- 创建窗口容器
  21. local page1 = ui.window({ background_color = ui.COLOR_WHITE })
  22. -- 计算居中位置
  23. local page_w, page_h = lcd.getSize()
  24. local message_width = 500
  25. local message_height = 300
  26. local message_x = (page_w - message_width) / 2
  27. local message_y = (page_h - message_height) / 2
  28. -- 创建消息框组件
  29. local box = ui.message_box({
  30. x = message_x, y = message_y,
  31. w = message_width, h = message_height,
  32. wordWrap = true,
  33. title = "通知",
  34. message = "愿你前路浩荡,未来可期.愿你保持热爱,奔赴山海。愿你所有的努力都不被辜负,最终活成自己最喜欢的模样.加油!"
  35. })
  36. -- 添加标题
  37. local title_label = ui.label({
  38. x = message_x, y = message_y - 60,
  39. text = "消息框组件演示",
  40. color = ui.COLOR_BLACK,
  41. size = 24
  42. })
  43. -- 添加组件到窗口
  44. page1:add(title_label)
  45. page1:add(box)
  46. -- 注册窗口到UI系统
  47. ui.add(page1)
  48. end
  49. sys.taskInit(ui_main)