home_page.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --[[
  2. @module home_page
  3. @summary AirUI演示系统主页
  4. @version 1.0
  5. @date 2026.02.05
  6. @author 江访
  7. @usage
  8. 本文件是AirUI演示系统的主页,提供所有功能演示的入口。
  9. ]]
  10. local home_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local scroll_container = nil
  14. -- 演示模块列表
  15. local demos = {
  16. -- AirUI组件演示
  17. {name = "所有组件演示", icon = airui.SYMBOL_OK, page = "all_component", color = 0x007AFF},
  18. {name = "标签组件", icon = airui.SYMBOL_REFRESH, page = "label", color = 0x4CAF50},
  19. {name = "按钮组件", icon = airui.SYMBOL_LOOP, page = "button", color = 0xF44336},
  20. {name = "容器组件", icon = airui.SYMBOL_SD_CARD, page = "container", color = 0xFF9800},
  21. {name = "进度条组件", icon = airui.SYMBOL_SHUFFLE, page = "bar", color = 0x9C27B0},
  22. {name = "开关组件", icon = airui.SYMBOL_COPY, page = "switch", color = 0x00BCD4},
  23. {name = "下拉框组件", icon = airui.SYMBOL_DOWN, page = "dropdown", color = 0x795548},
  24. {name = "表格组件", icon = airui.SYMBOL_LIST, page = "table", color = 0x607D8B},
  25. {name = "输入框组件", icon = airui.SYMBOL_EDIT, page = "input", color = 0x3F51B5},
  26. {name = "消息框组件", icon = airui.SYMBOL_CALL, page = "msgbox", color = 0xE91E63},
  27. {name = "图片组件", icon = airui.SYMBOL_IMAGE, page = "image", color = 0x8BC34A},
  28. {name = "选项卡组件", icon = airui.SYMBOL_PASTE, page = "tabview", color = 0xFF5722},
  29. {name = "窗口组件", icon = airui.SYMBOL_BELL, page = "win", color = 0x009688},
  30. {name = "页面切换演示", icon = airui.SYMBOL_LEFT, page = "switch_page_demo", color = 0x673AB7},
  31. {name = "矢量字体演示", icon = airui.SYMBOL_EYE_OPEN, page = "hzfont", color = 0x2196F3},
  32. {name = "俄罗斯方块游戏", icon = airui.SYMBOL_WARNING, page = "game", color = 0xFF4081},
  33. }
  34. -- 创建主页UI
  35. function home_page.create_ui()
  36. -- 创建主容器
  37. main_container = airui.container({
  38. x = 0,
  39. y = 0,
  40. w = 320,
  41. h = 480,
  42. color = 0xF8F9FA,
  43. })
  44. -- 标题栏
  45. local title_bar = airui.container({
  46. parent = main_container,
  47. x = 0,
  48. y = 0,
  49. w = 320,
  50. h = 50,
  51. color = 0x007AFF,
  52. })
  53. airui.label({
  54. parent = title_bar,
  55. text = "AirUI演示系统",
  56. x = 10,
  57. y = 20,
  58. w = 300,
  59. h = 30,
  60. })
  61. -- 滚动容器
  62. scroll_container = airui.container({
  63. parent = main_container,
  64. x = 0,
  65. y = 60,
  66. w = 320,
  67. h = 360,
  68. color = 0xF8F9FA,
  69. })
  70. -- 创建网格布局的演示按钮
  71. local button_width = 140
  72. local button_height = 70
  73. local columns = 2
  74. local padding = 10
  75. local y_offset = 0
  76. for i, demo in ipairs(demos) do
  77. local col = (i - 1) % columns
  78. local row = math.floor((i - 1) / columns)
  79. local x = padding + col * (button_width + padding)
  80. local y = y_offset + row * (button_height + padding)
  81. -- 创建按钮容器(卡片样式)
  82. local card = airui.container({
  83. parent = scroll_container,
  84. x = x,
  85. y = y,
  86. w = button_width,
  87. h = button_height,
  88. color = demo.color,
  89. radius = 8,
  90. })
  91. -- 图标标签
  92. airui.label({
  93. parent = card,
  94. text = demo.icon,
  95. x = 10,
  96. y = 15,
  97. w = 30,
  98. h = 50,
  99. })
  100. -- 演示名称标签
  101. airui.label({
  102. parent = card,
  103. text = demo.name,
  104. x = 50,
  105. y = 15,
  106. w = button_width - 60,
  107. h = 50,
  108. on_click = function()
  109. _G.show_page(demo.page) end
  110. })
  111. end
  112. -- 底部状态栏
  113. local status_bar = airui.container({
  114. parent = main_container,
  115. x = 0,
  116. y = 440,
  117. w = 320,
  118. h = 40,
  119. color = 0xCFCFCF,
  120. })
  121. airui.label({
  122. parent = status_bar,
  123. text = string.format("共%d个演示 - AirUI v1.0.3", #demos),
  124. x = 10,
  125. y = 12,
  126. w = 300,
  127. h = 16,
  128. })
  129. end
  130. -- 初始化页面
  131. function home_page.init(params)
  132. home_page.create_ui()
  133. end
  134. -- 清理页面
  135. function home_page.cleanup()
  136. -- 清理UI元素
  137. main_container = nil
  138. scroll_container = nil
  139. end
  140. return home_page