label_page.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. --[[
  2. @module label_page
  3. @summary 标签组件演示页面
  4. @version 1.0
  5. @date 2026.02.05
  6. @author 江访
  7. @usage
  8. 本文件是标签组件的演示页面,展示标签的各种用法。
  9. ]]
  10. local label_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local current_font = nil
  14. -- 创建UI
  15. function label_page.create_ui()
  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 = 0x4CAF50,
  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 label1 = airui.label({
  74. parent = scroll_container,
  75. text = "这是一个文本标签",
  76. x = 20,
  77. y = 40,
  78. w = 280,
  79. h = 30,
  80. font_size = 14,
  81. })
  82. -- 示例2: 图标标签(使用符号)
  83. airui.label({
  84. parent = scroll_container,
  85. text = "示例2: 图标标签",
  86. x = 10,
  87. y = 80,
  88. w = 300,
  89. h = 20,
  90. font_size = 14,
  91. })
  92. local icon_label = airui.label({
  93. parent = scroll_container,
  94. symbol = airui.SYMBOL_SETTINGS, -- 使用符号字符串
  95. x = 20,
  96. y = 115,
  97. w = 40,
  98. h = 40,
  99. font_size = 24,
  100. on_click = function(self)
  101. log.info("label", "图标标签被点击")
  102. end
  103. })
  104. airui.label({
  105. parent = scroll_container,
  106. text = "点击图标",
  107. x = 70,
  108. y = 120,
  109. w = 100,
  110. h = 30,
  111. font_size = 14,
  112. })
  113. -- 示例3: 动态更新文本
  114. airui.label({
  115. parent = scroll_container,
  116. text = "示例3: 动态更新文本",
  117. x = 10,
  118. y = 160,
  119. w = 300,
  120. h = 20,
  121. font_size = 14,
  122. })
  123. local dynamic_label = airui.label({
  124. parent = scroll_container,
  125. text = "初始文本",
  126. x = 20,
  127. y = 190,
  128. w = 200,
  129. h = 30,
  130. font_size = 14,
  131. })
  132. local update_btn = airui.button({
  133. parent = scroll_container,
  134. x = 230,
  135. y = 185,
  136. w = 70,
  137. h = 40,
  138. text = "更新",
  139. on_click = function(self)
  140. local current_time = os.date("%H:%M:%S")
  141. dynamic_label:set_text("时间: " .. current_time)
  142. end
  143. })
  144. -- 示例4: 多行文本
  145. airui.label({
  146. parent = scroll_container,
  147. text = "示例4: 多行文本",
  148. x = 10,
  149. y = 240,
  150. w = 300,
  151. h = 20,
  152. font_size = 14,
  153. })
  154. local multiline_label = airui.label({
  155. parent = scroll_container,
  156. text = "这是一个多行文本标签,可以显示较长的文本内容。标签支持自动换行功能。",
  157. x = 20,
  158. y = 270,
  159. w = 280,
  160. h = 60,
  161. font_size = 14,
  162. })
  163. -- 示例5: 不同字体大小和颜色
  164. airui.label({
  165. parent = scroll_container,
  166. text = "示例5: 不同字体大小和颜色",
  167. x = 10,
  168. y = 330,
  169. w = 300,
  170. h = 20,
  171. font_size = 14,
  172. })
  173. local size_label1 = airui.label({
  174. parent = scroll_container,
  175. text = "12px 红色",
  176. x = 20,
  177. y = 360,
  178. w = 100,
  179. h = 30,
  180. font_size = 12,
  181. color = 0xFF0000,
  182. })
  183. local size_label2 = airui.label({
  184. parent = scroll_container,
  185. text = "16px 绿色",
  186. x = 130,
  187. y = 360,
  188. w = 100,
  189. h = 30,
  190. font_size = 16,
  191. color = 0x00FF00,
  192. })
  193. local size_label3 = airui.label({
  194. parent = scroll_container,
  195. text = "20px 蓝色",
  196. x = 240,
  197. y = 360,
  198. w = 60,
  199. h = 50,
  200. font_size = 20,
  201. color = 0x0000FF,
  202. })
  203. -- 底部信息
  204. airui.label({
  205. parent = main_container,
  206. text = "提示: 点击标签可以触发事件",
  207. x = 10,
  208. y = 440,
  209. w = 300,
  210. h = 20,
  211. font_size = 14,
  212. })
  213. end
  214. -- 初始化页面
  215. function label_page.init(params)
  216. label_page.create_ui()
  217. end
  218. -- 清理页面
  219. function label_page.cleanup()
  220. if main_container then
  221. main_container:destroy()
  222. main_container = nil
  223. end
  224. end
  225. return label_page