win_all_component.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. --[[
  2. @module win_all_component
  3. @summary 所有UI组件综合演示模块
  4. @version 1.0.0
  5. @date 2025.11.28
  6. @author 江访
  7. @usage
  8. 本文件为所有UI组件综合演示模块,核心业务逻辑为:
  9. 1、创建带滚动功能的窗口容器;
  10. 2、集成展示所有exEasyUI组件;
  11. 3、实现组件间的交互逻辑;
  12. 4、展示进度条、消息框、按钮、复选框、输入框等完整功能;
  13. 5、启动UI渲染循环持续刷新显示;
  14. 本文件没有对外接口;
  15. ]]
  16. local function ui_main()
  17. -- 显示触摸初始化
  18. hw_font_drv.init()
  19. -- 设置主题
  20. ui.sw_init({ theme = "light" })
  21. -- 创建窗口容器并启用滚动
  22. local page1 = ui.window({ background_color = ui.COLOR_WHITE })
  23. page1:enable_scroll({
  24. direction = "vertical",
  25. content_height = 1000,
  26. threshold = 8
  27. })
  28. -- ==================== 标题区域 ====================
  29. local title = ui.label({
  30. x = 100, y = 25,
  31. text = "组件演示页面",
  32. color = ui.COLOR_BLACK,
  33. size = 16
  34. })
  35. page1:add(title)
  36. -- ==================== 进度条组件区域 ====================
  37. local progress_label = ui.label({
  38. x = 20, y = 70,
  39. text = "1. 进度条组件演示:",
  40. color = ui.COLOR_BLACK,
  41. size = 14
  42. })
  43. local progress = 0
  44. local pb = ui.progress_bar({
  45. x = 20, y = 100,
  46. w = 200, h = 26,
  47. progress = progress
  48. })
  49. local btn_progress = ui.button({
  50. x = 230, y = 100,
  51. w = 70, h = 26,
  52. text = "+10%",
  53. on_click = function(self)
  54. progress = progress + 10
  55. if progress > 100 then
  56. progress = 0
  57. end
  58. pb:set_progress(progress)
  59. pb:set_text("进度: " .. progress .. "%")
  60. end
  61. })
  62. page1:add(progress_label)
  63. page1:add(pb)
  64. page1:add(btn_progress)
  65. -- ==================== 消息框组件区域 ====================
  66. local msgbox_label = ui.label({
  67. x = 20, y = 140,
  68. text = "2. 消息框组件演示:",
  69. color = ui.COLOR_BLACK,
  70. size = 14
  71. })
  72. local btn_msgbox = ui.button({
  73. x = 20, y = 170,
  74. w = 120, h = 30,
  75. text = "弹出消息框",
  76. on_click = function(self)
  77. local message_box = ui.message_box({
  78. x = 40, y = 150,
  79. w = 240, h = 180,
  80. wordWrap = true,
  81. title = "祝福",
  82. message = "愿你前路浩荡,未来可期.愿你保持热爱,奔赴山海。愿你所有的努力都不被辜负,最终活成自己最喜欢的模样.加油!",
  83. buttons = { "接受祝福" }
  84. })
  85. ui.add(message_box)
  86. end
  87. })
  88. page1:add(msgbox_label)
  89. page1:add(btn_msgbox)
  90. -- ==================== 切换按钮组件区域 ====================
  91. local toggle_label = ui.label({
  92. x = 20, y = 220,
  93. text = "3. 切换按钮演示:",
  94. color = ui.COLOR_BLACK,
  95. size = 14
  96. })
  97. local btn_toggle = ui.button({
  98. x = 20, y = 250,
  99. w = 64, h = 64,
  100. src = "/luadb/4.jpg",
  101. src_toggled = "/luadb/5.jpg",
  102. toggle = true,
  103. })
  104. page1:add(toggle_label)
  105. page1:add(btn_toggle)
  106. -- ==================== 复选框组件区域 ====================
  107. local checkbox_label = ui.label({
  108. x = 20, y = 330,
  109. text = "4. 复选框组件演示:",
  110. color = ui.COLOR_BLACK,
  111. size = 14
  112. })
  113. local checkbox1 = ui.check_box({
  114. x = 20, y = 360,
  115. text = "选项A",
  116. checked = false,
  117. on_change = function(checked)
  118. log.info("checkbox", "选项A:", checked)
  119. end
  120. })
  121. local checkbox2 = ui.check_box({
  122. x = 120, y = 360,
  123. text = "选项B",
  124. checked = true,
  125. on_change = function(checked)
  126. log.info("checkbox", "选项B:", checked)
  127. end
  128. })
  129. page1:add(checkbox_label)
  130. page1:add(checkbox1)
  131. page1:add(checkbox2)
  132. -- ==================== 输入框组件区域 ====================
  133. local input_label = ui.label({
  134. x = 20, y = 410,
  135. text = "5. 输入框组件演示:",
  136. color = ui.COLOR_BLACK,
  137. size = 14
  138. })
  139. local text_input = ui.input({
  140. x = 20, y = 440,
  141. w = 200, h = 30,
  142. placeholder = "请输入文本...",
  143. max_length = 20
  144. })
  145. page1:add(input_label)
  146. page1:add(text_input)
  147. -- ==================== 密码输入框组件区域 ====================
  148. local password_label = ui.label({
  149. x = 20, y = 490,
  150. text = "6. 密码输入框演示:",
  151. color = ui.COLOR_BLACK,
  152. size = 14
  153. })
  154. local password_input = ui.input({
  155. x = 20, y = 520,
  156. w = 150, h = 30,
  157. placeholder = "请输入密码...",
  158. input_type = "password",
  159. max_length = 16
  160. })
  161. local password_visible = false
  162. local btn_password_toggle = ui.button({
  163. x = 180, y = 520,
  164. w = 60, h = 30,
  165. text = "显示",
  166. bg_color = ui.COLOR_BLUE,
  167. text_color = ui.COLOR_WHITE,
  168. on_click = function()
  169. password_visible = not password_visible
  170. password_input.input_type = password_visible and "text" or "password"
  171. btn_password_toggle:set_text(password_visible and "隐藏" or "显示")
  172. end
  173. })
  174. page1:add(password_label)
  175. page1:add(password_input)
  176. page1:add(btn_password_toggle)
  177. -- ==================== 数字输入框组件区域 ====================
  178. local number_label = ui.label({
  179. x = 20, y = 570,
  180. text = "7. 数字输入框演示:",
  181. color = ui.COLOR_BLACK,
  182. size = 14
  183. })
  184. local number_input = ui.input({
  185. x = 20, y = 600,
  186. w = 100, h = 30,
  187. placeholder = "0-100",
  188. input_type = "number",
  189. max_length = 3
  190. })
  191. local btn_number_minus = ui.button({
  192. x = 130, y = 600,
  193. w = 40, h = 30,
  194. text = "-",
  195. on_click = function()
  196. local value = tonumber(number_input:get_text()) or 0
  197. if value > 0 then
  198. number_input:set_text(tostring(value - 1))
  199. end
  200. end
  201. })
  202. local btn_number_plus = ui.button({
  203. x = 180, y = 600,
  204. w = 40, h = 30,
  205. text = "+",
  206. on_click = function()
  207. local value = tonumber(number_input:get_text()) or 0
  208. if value < 100 then
  209. number_input:set_text(tostring(value + 1))
  210. end
  211. end
  212. })
  213. page1:add(number_label)
  214. page1:add(number_input)
  215. page1:add(btn_number_minus)
  216. page1:add(btn_number_plus)
  217. -- ==================== 下拉框组件区域 ====================
  218. local combo_label = ui.label({
  219. x = 20, y = 650,
  220. text = "8. 下拉框组件演示:",
  221. color = ui.COLOR_BLACK,
  222. size = 14
  223. })
  224. local combo_box = ui.combo_box({
  225. x = 20, y = 680,
  226. w = 200, h = 30,
  227. options = { "选项1", "选项2", "选项3" },
  228. placeholder = "请选择",
  229. selected = 1,
  230. on_select = function(value, index, text)
  231. log.info("combo_box", "选择了:", text, "索引:", index)
  232. end
  233. })
  234. page1:add(combo_label)
  235. page1:add(combo_box)
  236. -- ==================== 图片轮播组件区域 ====================
  237. local picture_label = ui.label({
  238. x = 20, y = 730,
  239. text = "9. 图片自动轮播组件演示:",
  240. color = ui.COLOR_BLACK,
  241. size = 14
  242. })
  243. local pic = ui.picture({
  244. x = 20, y = 760,
  245. w = 128, h = 128,
  246. sources = { "/luadb/1.jpg", "/luadb/2.jpg", "/luadb/3.jpg" },
  247. autoplay = true,
  248. interval = 1500
  249. })
  250. local btn_picture_toggle = ui.button({
  251. x = 160, y = 760,
  252. w = 80, h = 30,
  253. text = "手动切换图片",
  254. on_click = function()
  255. pic:next()
  256. end
  257. })
  258. page1:add(picture_label)
  259. page1:add(pic)
  260. page1:add(btn_picture_toggle)
  261. -- 注册窗口到UI系统
  262. ui.add(page1)
  263. end
  264. sys.taskInit(ui_main)