container_page.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. --[[
  2. @module container_page
  3. @summary 容器组件演示页面
  4. @version 1.0
  5. @date 2026.02.05
  6. @author 江访
  7. @usage
  8. 本文件是容器组件的演示页面,展示容器的各种用法。
  9. ]]
  10. local container_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. -- 创建UI
  14. function container_page.create_ui()
  15. -- 创建主容器
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 320,
  20. h = 480,
  21. color = 0xF5F5F5,
  22. })
  23. -- 标题栏
  24. local title_bar = airui.container({
  25. parent = main_container,
  26. x = 0,
  27. y = 0,
  28. w = 320,
  29. h = 50,
  30. color = 0xFF9800,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "容器组件演示",
  35. x = 10,
  36. y = 15,
  37. w = 200,
  38. h = 20,
  39. font_size = 16,
  40. color = 0xFFFFFF,
  41. })
  42. -- 返回按钮
  43. local back_btn = airui.button({
  44. parent = title_bar,
  45. x = 250,
  46. y = 10,
  47. w = 60,
  48. h = 30,
  49. text = "返回",
  50. on_click = function(self)
  51. go_back()
  52. end
  53. })
  54. -- 滚动容器
  55. local scroll_container = airui.container({
  56. parent = main_container,
  57. x = 0,
  58. y = 60,
  59. w = 320,
  60. h = 370,
  61. color = 0xF5F5F5,
  62. })
  63. -- 示例1: 基本容器
  64. airui.label({
  65. parent = scroll_container,
  66. text = "示例1: 基本容器",
  67. x = 10,
  68. y = 10,
  69. w = 300,
  70. h = 20,
  71. font_size = 14,
  72. })
  73. local basic_container = airui.container({
  74. parent = scroll_container,
  75. x = 20,
  76. y = 40,
  77. w = 280,
  78. h = 80,
  79. color = 0xE3F2FD,
  80. radius = 8,
  81. })
  82. airui.label({
  83. parent = basic_container,
  84. text = "这是一个容器",
  85. x = 10,
  86. y = 10,
  87. w = 260,
  88. h = 20,
  89. font_size = 14,
  90. })
  91. airui.label({
  92. parent = basic_container,
  93. text = "容器可以作为其他组件的父容器",
  94. x = 10,
  95. y = 40,
  96. w = 260,
  97. h = 20,
  98. font_size = 14,
  99. })
  100. -- 示例2: 圆角容器
  101. airui.label({
  102. parent = scroll_container,
  103. text = "示例2: 圆角容器",
  104. x = 10,
  105. y = 130,
  106. w = 300,
  107. h = 20,
  108. font_size = 14,
  109. })
  110. local rounded_container = airui.container({
  111. parent = scroll_container,
  112. x = 20,
  113. y = 160,
  114. w = 280,
  115. h = 80,
  116. color = 0xFFEBEE,
  117. radius = 20,
  118. })
  119. airui.label({
  120. parent = rounded_container,
  121. text = "圆角半径: 20",
  122. x = 10,
  123. y = 30,
  124. w = 260,
  125. h = 20,
  126. font_size = 14,
  127. })
  128. -- 示例3: 嵌套容器
  129. airui.label({
  130. parent = scroll_container,
  131. text = "示例3: 嵌套容器",
  132. x = 10,
  133. y = 250,
  134. w = 300,
  135. h = 20,
  136. font_size = 14,
  137. })
  138. local parent_container = airui.container({
  139. parent = scroll_container,
  140. x = 20,
  141. y = 280,
  142. w = 280,
  143. h = 120,
  144. color = 0xE8F5E8,
  145. radius = 10,
  146. })
  147. local child1 = airui.container({
  148. parent = parent_container,
  149. x = 10,
  150. y = 10,
  151. w = 120,
  152. h = 50,
  153. color = 0xC8E6C9,
  154. radius = 5,
  155. })
  156. airui.label({
  157. parent = child1,
  158. text = "子容器1",
  159. x = 10,
  160. y = 15,
  161. w = 100,
  162. h = 20,
  163. font_size = 14,
  164. })
  165. local child2 = airui.container({
  166. parent = parent_container,
  167. x = 150,
  168. y = 10,
  169. w = 120,
  170. h = 50,
  171. color = 0xA5D6A7,
  172. radius = 5,
  173. })
  174. airui.label({
  175. parent = child2,
  176. text = "子容器2",
  177. x = 10,
  178. y = 15,
  179. w = 100,
  180. h = 20,
  181. font_size = 14,
  182. })
  183. -- 示例4: 动态显示/隐藏
  184. airui.label({
  185. parent = scroll_container,
  186. text = "示例4: 显示/隐藏容器",
  187. x = 10,
  188. y = 410,
  189. w = 300,
  190. h = 20,
  191. font_size = 14,
  192. })
  193. local toggle_container = airui.container({
  194. parent = scroll_container,
  195. x = 20,
  196. y = 440,
  197. w = 160,
  198. h = 60,
  199. color = 0xE1BEE7,
  200. radius = 8,
  201. })
  202. airui.label({
  203. parent = toggle_container,
  204. text = "可隐藏的容器",
  205. x = 10,
  206. y = 20,
  207. w = 140,
  208. h = 20,
  209. font_size = 14,
  210. })
  211. local toggle_btn = airui.button({
  212. parent = scroll_container,
  213. x = 190,
  214. y = 450,
  215. w = 100,
  216. h = 40,
  217. text = "隐藏",
  218. on_click = function(self)
  219. if toggle_container then
  220. toggle_container:hide()
  221. end
  222. end
  223. })
  224. -- 示例5: 动态改变颜色
  225. airui.label({
  226. parent = scroll_container,
  227. text = "示例5: 动态改变颜色",
  228. x = 10,
  229. y = 510,
  230. w = 300,
  231. h = 20,
  232. font_size = 14,
  233. })
  234. local color_container = airui.container({
  235. parent = scroll_container,
  236. x = 20,
  237. y = 540,
  238. w = 280,
  239. h = 80,
  240. color = 0x2196F3,
  241. radius = 8,
  242. })
  243. airui.label({
  244. parent = color_container,
  245. text = "点击按钮改变颜色",
  246. x = 10,
  247. y = 30,
  248. w = 260,
  249. h = 20,
  250. font_size = 14,
  251. })
  252. local color_btn = airui.button({
  253. parent = scroll_container,
  254. x = 20,
  255. y = 630,
  256. w = 130,
  257. h = 40,
  258. text = "随机颜色",
  259. on_click = function(self)
  260. local colors = {0xFF5722, 0x4CAF50, 0x9C27B0, 0xFF9800, 0x00BCD4}
  261. local random_color = colors[math.random(1, #colors)]
  262. color_container:set_color(random_color)
  263. end
  264. })
  265. local reset_btn = airui.button({
  266. parent = scroll_container,
  267. x = 170,
  268. y = 630,
  269. w = 130,
  270. h = 40,
  271. text = "重置颜色",
  272. on_click = function(self)
  273. color_container:set_color(0x2196F3)
  274. end
  275. })
  276. -- 底部信息
  277. airui.label({
  278. parent = main_container,
  279. text = "提示: 容器是布局的基础组件",
  280. x = 10,
  281. y = 440,
  282. w = 300,
  283. h = 20,
  284. font_size = 14,
  285. })
  286. end
  287. -- 初始化页面
  288. function container_page.init(params)
  289. math.randomseed(os.time())
  290. container_page.create_ui()
  291. end
  292. -- 清理页面
  293. function container_page.cleanup()
  294. if main_container then
  295. main_container:destroy()
  296. main_container = nil
  297. end
  298. end
  299. return container_page