tsb_light_page.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. --[[
  2. @module tsb_light_page
  3. @summary 亮度演示页面
  4. @version 1.0
  5. @date 2026.03.04
  6. @author 李一玮
  7. @usage
  8. 本文件是亮度演示页面,展示亮度的各种用法。
  9. ]]
  10. local tsb_light_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_light_page.create_ui()
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 480,
  20. h = 320,
  21. color = 0xF5F5F5,
  22. })
  23. --------------------- 标题栏 ------------------------
  24. local title_bar = airui.container({
  25. parent = main_container,
  26. x = 0,
  27. y = 0,
  28. w = 480,
  29. h = 30,
  30. color = 0xF2E2C5,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "亮度管理",
  35. x = 190,
  36. y = 8,
  37. w = 100,
  38. h = 20,
  39. font_size = 16,
  40. color = 0xFFFFFF,
  41. })
  42. -- 标题栏公共信息展示
  43. common_ui.add_battery_display(title_bar)
  44. common_ui.create_back_button(title_bar, tsb_light_page.cleanup)
  45. ---------------------------------------------------
  46. -- 滚动容器
  47. local scroll_container = airui.container({
  48. parent = main_container,
  49. x = 0,
  50. y = 30,
  51. w = 480,
  52. h = 270,
  53. color = 0xFFFFFF,
  54. })
  55. --------------------- 屏幕亮度控制 ------------------------
  56. -- 亮度标签
  57. airui.label({
  58. parent = scroll_container,
  59. text = "屏幕亮度控制",
  60. x = 180,
  61. y = 50,
  62. w = 100,
  63. h = 30,
  64. font_size = 16,
  65. })
  66. -- 亮度进度条
  67. local brightness_bar = airui.bar({
  68. parent = scroll_container,
  69. x = 20,
  70. y = 90,
  71. w = 440,
  72. h = 20,
  73. value = 50,
  74. min = 10,
  75. max = 100,
  76. radius = 5,
  77. show_progress_text = true,
  78. indicator_color = 0x2196F3,
  79. progress_text_format = "%d%%",
  80. })
  81. -- 亮度控制按钮
  82. -- 降低亮度按钮
  83. local decrease_brightness_btn = airui.button({
  84. parent = scroll_container,
  85. x = 100,
  86. y = 140,
  87. w = 110,
  88. h = 40,
  89. text = "降低亮度",
  90. on_click = function(self)
  91. local current = brightness_bar:get_value()
  92. if current > 10 then
  93. current = current - 10
  94. brightness_bar:set_value(current, true)
  95. brightness_value_label:set_text(current .. "%")
  96. log.info("set_brightness", "亮度降低到:" .. current .. "%")
  97. end
  98. end
  99. })
  100. -- 提升亮度按钮
  101. local increase_brightness_btn = airui.button({
  102. parent = scroll_container,
  103. x = 280,
  104. y = 140,
  105. w = 110,
  106. h = 40,
  107. text = "提升亮度",
  108. on_click = function(self)
  109. local current = brightness_bar:get_value()
  110. if current < 100 then
  111. current = current + 10
  112. brightness_bar:set_value(current, true)
  113. brightness_value_label:set_text(current .. "%")
  114. log.info("set_brightness", "亮度提升到:" .. current .. "%")
  115. end
  116. end
  117. })
  118. ---------------------------------------------------
  119. -- 底部信息
  120. common_ui.create_status_bar(main_container)
  121. end
  122. -- 初始化页面
  123. function tsb_light_page.init(params)
  124. tsb_light_page.create_ui()
  125. end
  126. -- 清理页面
  127. function tsb_light_page.cleanup()
  128. if main_container then
  129. main_container:destroy()
  130. main_container = nil
  131. end
  132. end
  133. return tsb_light_page