switch_page.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. --[[
  2. @module switch_page
  3. @summary 开关组件演示页面
  4. @version 1.0.0
  5. @date 2026.02.05
  6. @author 江访
  7. @usage
  8. 本文件展示开关组件的基本用法和常见场景。
  9. ]]
  10. local switch_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. -- 创建UI
  14. function switch_page.create_ui()
  15. main_container = airui.container({
  16. x = 0,
  17. y = 0,
  18. w = 320,
  19. h = 480,
  20. color = 0xF5F5F5,
  21. })
  22. -- 标题栏
  23. local title_bar = airui.container({
  24. parent = main_container,
  25. x = 0,
  26. y = 0,
  27. w = 320,
  28. h = 50,
  29. color = 0x00BCD4,
  30. })
  31. airui.label({
  32. parent = title_bar,
  33. text = "开关组件演示",
  34. x = 10,
  35. y = 15,
  36. w = 200,
  37. h = 20,
  38. font_size = 16,
  39. color = 0xFFFFFF,
  40. })
  41. -- 返回按钮
  42. airui.button({
  43. parent = title_bar,
  44. x = 250,
  45. y = 10,
  46. w = 60,
  47. h = 30,
  48. text = "返回",
  49. on_click = function(self)
  50. go_back()
  51. end
  52. })
  53. -- 内容区域
  54. local content = airui.container({
  55. parent = main_container,
  56. x = 0,
  57. y = 50,
  58. w = 320,
  59. h = 430,
  60. color = 0xF5F5F5,
  61. })
  62. airui.label({
  63. parent = main_container,
  64. text = "设置选项",
  65. x = 10,
  66. y = 60,
  67. w = 280,
  68. h = 20,
  69. font_size = 14,
  70. color = 0x333333,
  71. })
  72. -- 第一行
  73. local switch_wifi = airui.switch({
  74. parent = main_container,
  75. x = 20,
  76. y = 90,
  77. w = 50,
  78. h = 25,
  79. checked = true,
  80. on_change = function(self)
  81. log.info("WiFi", self:get_state() and "开启" or "关闭")
  82. end
  83. })
  84. airui.label({
  85. parent = main_container,
  86. text = "WiFi",
  87. x = 80,
  88. y = 92,
  89. w = 100,
  90. h = 20,
  91. font_size = 14,
  92. })
  93. local switch_bluetooth = airui.switch({
  94. parent = main_container,
  95. x = 160,
  96. y = 90,
  97. w = 50,
  98. h = 25,
  99. checked = false,
  100. on_change = function(self)
  101. log.info("蓝牙", self:get_state() and "开启" or "关闭")
  102. end
  103. })
  104. airui.label({
  105. parent = main_container,
  106. text = "蓝牙",
  107. x = 220,
  108. y = 92,
  109. w = 100,
  110. h = 20,
  111. font_size = 14,
  112. })
  113. -- 第二行
  114. local switch_data = airui.switch({
  115. parent = main_container,
  116. x = 20,
  117. y = 135,
  118. w = 50,
  119. h = 25,
  120. checked = false,
  121. on_change = function(self)
  122. log.info("移动数据", self:get_state() and "开启" or "关闭")
  123. end
  124. })
  125. airui.label({
  126. parent = main_container,
  127. text = "移动数据",
  128. x = 80,
  129. y = 137,
  130. w = 100,
  131. h = 20,
  132. font_size = 14,
  133. })
  134. local switch_gps = airui.switch({
  135. parent = main_container,
  136. x = 160,
  137. y = 135,
  138. w = 50,
  139. h = 25,
  140. checked = true,
  141. on_change = function(self)
  142. log.info("GPS", self:get_state() and "开启" or "关闭")
  143. end
  144. })
  145. airui.label({
  146. parent = main_container,
  147. text = "GPS定位",
  148. x = 220,
  149. y = 137,
  150. w = 100,
  151. h = 20,
  152. font_size = 14,
  153. })
  154. -- 底部提示
  155. airui.label({
  156. parent = main_container,
  157. text = "开关组件:点击切换状态,支持程序控制",
  158. x = 10,
  159. y = 450,
  160. w = 300,
  161. h = 20,
  162. color = 0x666666,
  163. font_size = 12,
  164. })
  165. end
  166. -- 初始化页面
  167. function switch_page.init(params)
  168. switch_page.create_ui()
  169. end
  170. -- 清理页面
  171. function switch_page.cleanup()
  172. if main_container then
  173. main_container:destroy()
  174. main_container = nil
  175. end
  176. end
  177. return switch_page