win_all_component.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. --[[
  2. @module win_all_component
  3. @summary 所有UI组件综合演示模块
  4. @version 1.0.0
  5. @date 2025.12.9
  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 = 600,
  26. threshold = 8
  27. })
  28. -- ==================== 标题区域 ====================
  29. local title = ui.label({
  30. x = 250, y = 25,
  31. text = "所有UI组件综合演示",
  32. color = ui.COLOR_BLACK,
  33. size = 24
  34. })
  35. page1:add(title)
  36. -- 左列和右列布局
  37. local left_column_x = 50
  38. local right_column_x = 450
  39. local current_y = 80
  40. -- ==================== 左列:基础组件 ====================
  41. -- 进度条组件
  42. local progress_label = ui.label({
  43. x = left_column_x, y = current_y,
  44. text = "1. 进度条组件",
  45. color = ui.COLOR_BLACK,
  46. size = 18
  47. })
  48. page1:add(progress_label)
  49. local progress = 50
  50. local pb = ui.progress_bar({
  51. x = left_column_x, y = current_y + 30,
  52. w = 300, h = 26,
  53. progress = progress
  54. })
  55. page1:add(pb)
  56. local btn_progress = ui.button({
  57. x = left_column_x + 310, y = current_y + 30,
  58. w = 80, h = 26,
  59. text = "+10%",
  60. size = 14,
  61. on_click = function(self)
  62. progress = progress + 10
  63. if progress > 100 then progress = 0 end
  64. pb:set_progress(progress)
  65. end
  66. })
  67. page1:add(btn_progress)
  68. current_y = current_y + 80
  69. -- 消息框按钮
  70. local msgbox_label = ui.label({
  71. x = left_column_x, y = current_y,
  72. text = "2. 消息框组件",
  73. color = ui.COLOR_BLACK,
  74. size = 18
  75. })
  76. page1:add(msgbox_label)
  77. local btn_msgbox = ui.button({
  78. x = left_column_x, y = current_y + 30,
  79. w = 150, h = 40,
  80. text = "弹出消息框",
  81. size = 16,
  82. on_click = function()
  83. local message_box = ui.message_box({
  84. x = 150, y = 150,
  85. w = 500, h = 200,
  86. wordWrap = true,
  87. title = "综合演示",
  88. message = "这是所有UI组件的综合演示页面,展示了exEasyUI的各种组件功能。",
  89. buttons = { "确定", "取消" }
  90. })
  91. ui.add(message_box)
  92. end
  93. })
  94. page1:add(btn_msgbox)
  95. current_y = current_y + 90
  96. -- 切换按钮
  97. local toggle_label = ui.label({
  98. x = left_column_x, y = current_y,
  99. text = "3. 切换按钮",
  100. color = ui.COLOR_BLACK,
  101. size = 18
  102. })
  103. page1:add(toggle_label)
  104. local btn_toggle = ui.button({
  105. x = left_column_x, y = current_y + 30,
  106. w = 80, h = 80,
  107. src = "/luadb/4.jpg",
  108. src_toggled = "/luadb/5.jpg",
  109. toggle = true,
  110. })
  111. page1:add(btn_toggle)
  112. current_y = current_y + 130
  113. -- 复选框
  114. local checkbox_label = ui.label({
  115. x = left_column_x, y = current_y,
  116. text = "4. 复选框组件",
  117. color = ui.COLOR_BLACK,
  118. size = 18
  119. })
  120. page1:add(checkbox_label)
  121. local checkbox1 = ui.check_box({
  122. x = left_column_x, y = current_y + 30,
  123. text = "选项A",
  124. checked = false,
  125. size = 16,
  126. on_change = function(checked)
  127. log.info("checkbox", "选项A:", checked)
  128. end
  129. })
  130. page1:add(checkbox1)
  131. local checkbox2 = ui.check_box({
  132. x = left_column_x + 120, y = current_y + 30,
  133. text = "选项B",
  134. checked = true,
  135. size = 16,
  136. on_change = function(checked)
  137. log.info("checkbox", "选项B:", checked)
  138. end
  139. })
  140. page1:add(checkbox2)
  141. current_y = current_y + 80
  142. -- 文本输入框
  143. local input_label = ui.label({
  144. x = left_column_x, y = current_y,
  145. text = "5. 文本输入框",
  146. color = ui.COLOR_BLACK,
  147. size = 18
  148. })
  149. page1:add(input_label)
  150. local text_input = ui.input({
  151. x = left_column_x, y = current_y + 30,
  152. w = 250, h = 35,
  153. placeholder = "请输入文本...",
  154. max_length = 20,
  155. size = 16
  156. })
  157. page1:add(text_input)
  158. current_y = current_y + 85
  159. -- ==================== 右列:高级组件 ====================
  160. local right_current_y = 80
  161. -- 密码输入框
  162. local password_label = ui.label({
  163. x = right_column_x, y = right_current_y,
  164. text = "6. 密码输入框",
  165. color = ui.COLOR_BLACK,
  166. size = 18
  167. })
  168. page1:add(password_label)
  169. local password_input = ui.input({
  170. x = right_column_x, y = right_current_y + 30,
  171. w = 200, h = 35,
  172. placeholder = "请输入密码...",
  173. input_type = "password",
  174. max_length = 16,
  175. size = 16
  176. })
  177. page1:add(password_input)
  178. local password_visible = false
  179. local btn_password_toggle = ui.button({
  180. x = right_column_x + 210, y = right_current_y + 30,
  181. w = 80, h = 35,
  182. text = "显示",
  183. size = 14,
  184. bg_color = ui.COLOR_BLUE,
  185. text_color = ui.COLOR_WHITE,
  186. on_click = function()
  187. password_visible = not password_visible
  188. password_input.input_type = password_visible and "text" or "password"
  189. btn_password_toggle:set_text(password_visible and "隐藏" or "显示")
  190. end
  191. })
  192. page1:add(btn_password_toggle)
  193. right_current_y = right_current_y + 85
  194. -- 数字输入框
  195. local number_label = ui.label({
  196. x = right_column_x, y = right_current_y,
  197. text = "7. 数字输入框",
  198. color = ui.COLOR_BLACK,
  199. size = 18
  200. })
  201. page1:add(number_label)
  202. local number_input = ui.input({
  203. x = right_column_x, y = right_current_y + 30,
  204. w = 120, h = 35,
  205. placeholder = "0-100",
  206. input_type = "number",
  207. max_length = 3,
  208. size = 16
  209. })
  210. page1:add(number_input)
  211. local btn_number_minus = ui.button({
  212. x = right_column_x + 130, y = right_current_y + 30,
  213. w = 40, h = 35,
  214. text = "-",
  215. size = 16,
  216. on_click = function()
  217. local value = tonumber(number_input:get_text()) or 0
  218. if value > 0 then
  219. number_input:set_text(tostring(value - 1))
  220. end
  221. end
  222. })
  223. page1:add(btn_number_minus)
  224. local btn_number_plus = ui.button({
  225. x = right_column_x + 180, y = right_current_y + 30,
  226. w = 40, h = 35,
  227. text = "+",
  228. size = 16,
  229. on_click = function()
  230. local value = tonumber(number_input:get_text()) or 0
  231. if value < 100 then
  232. number_input:set_text(tostring(value + 1))
  233. end
  234. end
  235. })
  236. page1:add(btn_number_plus)
  237. right_current_y = right_current_y + 85
  238. -- 下拉框
  239. local combo_label = ui.label({
  240. x = right_column_x, y = right_current_y,
  241. text = "8. 下拉框组件",
  242. color = ui.COLOR_BLACK,
  243. size = 18
  244. })
  245. page1:add(combo_label)
  246. local combo_box = ui.combo_box({
  247. x = right_column_x, y = right_current_y + 30,
  248. w = 200, h = 35,
  249. options = { "选项1", "选项2", "选项3", "选项4" },
  250. placeholder = "请选择",
  251. selected = 1,
  252. size = 16,
  253. on_select = function(value, index, text)
  254. log.info("combo_box", "选择了:", text, "索引:", index)
  255. end
  256. })
  257. page1:add(combo_box)
  258. right_current_y = right_current_y + 85
  259. -- 图片轮播
  260. local picture_label = ui.label({
  261. x = right_column_x, y = right_current_y,
  262. text = "9. 图片轮播",
  263. color = ui.COLOR_BLACK,
  264. size = 18
  265. })
  266. page1:add(picture_label)
  267. local pic = ui.picture({
  268. x = right_column_x, y = right_current_y + 30,
  269. w = 200, h = 150,
  270. sources = { "/luadb/1.jpg", "/luadb/2.jpg", "/luadb/3.jpg" },
  271. autoplay = true,
  272. interval = 2000
  273. })
  274. page1:add(pic)
  275. local btn_picture_toggle = ui.button({
  276. x = right_column_x, y = right_current_y + 190,
  277. w = 100, h = 35,
  278. text = "下一张",
  279. size = 14,
  280. on_click = function()
  281. pic:next()
  282. end
  283. })
  284. page1:add(btn_picture_toggle)
  285. -- 底部提示
  286. local hint = ui.label({
  287. x = 250, y = 1650,
  288. text = "上下滚动查看更多组件",
  289. color = ui.COLOR_GRAY,
  290. size = 16
  291. })
  292. page1:add(hint)
  293. -- 注册窗口到UI系统
  294. ui.add(page1)
  295. end
  296. sys.taskInit(ui_main)