hzfont_page.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. --[[
  2. @module hzfont_page
  3. @summary 矢量字体演示页面
  4. @version 1.0
  5. @date 2026.01.30
  6. @author 江访
  7. @usage 本文件是矢量字体的演示页面,展示中文字体的各种用法。
  8. ]]
  9. local hzfont_page = {}
  10. ----------------------------------------------------------------
  11. -- 页面UI元素
  12. ----------------------------------------------------------------
  13. local main_container = nil
  14. local current_font = nil
  15. ----------------------------------------------------------------
  16. -- 辅助函数:创建带标题的容器
  17. ----------------------------------------------------------------
  18. local function create_demo_container(parent, title, x, y, width, height)
  19. local container = airui.container({
  20. parent = parent,
  21. x = x,
  22. y = y,
  23. w = width,
  24. h = height,
  25. color = 0xFFFFFF,
  26. radius = 8,
  27. })
  28. airui.label({
  29. parent = container,
  30. text = title,
  31. x = 10,
  32. y = 5,
  33. w = width - 20,
  34. h = 25,
  35. color = 0x333333,
  36. font_size = 14,
  37. })
  38. return container
  39. end
  40. ----------------------------------------------------------------
  41. -- 创建UI
  42. ----------------------------------------------------------------
  43. function hzfont_page.create_ui()
  44. main_container = airui.container({
  45. x = 0,
  46. y = 0,
  47. w = 320,
  48. h = 480,
  49. color = 0xF5F5F5,
  50. })
  51. -- 标题栏
  52. local title_bar = airui.container({
  53. parent = main_container,
  54. x = 0,
  55. y = 0,
  56. w = 320,
  57. h = 50,
  58. color = 0x2196F3,
  59. })
  60. airui.label({
  61. parent = title_bar,
  62. text = "矢量字体演示",
  63. x = 10,
  64. y = 15,
  65. w = 200,
  66. h = 20,
  67. font_size = 16,
  68. color = 0xFFFFFF,
  69. })
  70. -- 返回按钮
  71. local back_btn = airui.button({
  72. parent = title_bar,
  73. x = 250,
  74. y = 10,
  75. w = 60,
  76. h = 30,
  77. text = "返回",
  78. on_click = function(self)
  79. go_back()
  80. end
  81. })
  82. -- 滚动容器
  83. local scroll_container = airui.container({
  84. parent = main_container,
  85. x = 0,
  86. y = 60,
  87. w = 320,
  88. h = 370,
  89. color = 0xF5F5F5,
  90. })
  91. local current_y = 10
  92. --------------------------------------------------------------------
  93. -- 示例1: 基本中文显示
  94. --------------------------------------------------------------------
  95. local demo1_container = create_demo_container(scroll_container, "示例1: 基本中文显示", 10, current_y, 300, 80)
  96. current_y = current_y + 80 + 10
  97. airui.label({
  98. parent = demo1_container,
  99. text = "你好,世界!",
  100. x = 20,
  101. y = 30,
  102. w = 260,
  103. h = 40,
  104. color = 0x333333,
  105. font_size = 18,
  106. })
  107. --------------------------------------------------------------------
  108. -- 示例2: 长文本中文显示
  109. --------------------------------------------------------------------
  110. local demo2_container = create_demo_container(scroll_container, "示例2: 长文本中文", 10, current_y, 300, 100)
  111. current_y = current_y + 100 + 10
  112. local long_text = "矢量字体支持高质量的中文显示,可以在不同分辨率下保持清晰,提供更好的视觉体验。"
  113. airui.label({
  114. parent = demo2_container,
  115. text = long_text,
  116. x = 20,
  117. y = 30,
  118. w = 260,
  119. h = 60,
  120. color = 0x333333,
  121. font_size = 14,
  122. })
  123. --------------------------------------------------------------------
  124. -- 示例3: 中英文混合
  125. --------------------------------------------------------------------
  126. local demo3_container = create_demo_container(scroll_container, "示例3: 中英文混合", 10, current_y, 300, 80)
  127. current_y = current_y + 80 + 10
  128. airui.label({
  129. parent = demo3_container,
  130. text = "中文 Chinese 混合 Mixed 文本 Text",
  131. x = 20,
  132. y = 30,
  133. w = 260,
  134. h = 40,
  135. color = 0x333333,
  136. font_size = 16,
  137. })
  138. --------------------------------------------------------------------
  139. -- 示例4: 常用汉字显示
  140. --------------------------------------------------------------------
  141. local demo4_container = create_demo_container(scroll_container, "示例4: 常用汉字", 10, current_y, 300, 80)
  142. current_y = current_y + 80 + 10
  143. airui.label({
  144. parent = demo4_container,
  145. text = "天地玄黄 宇宙洪荒 日月盈昃 辰宿列张",
  146. x = 20,
  147. y = 30,
  148. w = 260,
  149. h = 40,
  150. color = 0x333333,
  151. font_size = 16,
  152. })
  153. --------------------------------------------------------------------
  154. -- 示例5: 数字和标点
  155. --------------------------------------------------------------------
  156. local demo5_container = create_demo_container(scroll_container, "示例5: 数字标点", 10, current_y, 300, 100)
  157. current_y = current_y + 100 + 10
  158. airui.label({
  159. parent = demo5_container,
  160. text = "数字: 1234567890\n标点: ,。!?;:\"'()【】《》",
  161. x = 20,
  162. y = 30,
  163. w = 260,
  164. h = 60,
  165. color = 0x333333,
  166. font_size = 14,
  167. })
  168. --------------------------------------------------------------------
  169. -- 示例6: 字体大小对比
  170. --------------------------------------------------------------------
  171. local demo7_container = create_demo_container(scroll_container, "示例6: 字体大小对比", 10, current_y, 300, 120)
  172. current_y = current_y + 120 + 10
  173. airui.label({
  174. parent = demo7_container,
  175. text = "12px - 小号字体",
  176. x = 20,
  177. y = 30,
  178. w = 260,
  179. h = 30,
  180. color = 0x333333,
  181. font_size = 12,
  182. })
  183. airui.label({
  184. parent = demo7_container,
  185. text = "16px - 中号字体",
  186. x = 20,
  187. y = 55,
  188. w = 260,
  189. h = 30,
  190. color = 0x333333,
  191. font_size = 16,
  192. })
  193. airui.label({
  194. parent = demo7_container,
  195. text = "20px - 大号字体",
  196. x = 20,
  197. y = 80,
  198. w = 260,
  199. h = 30,
  200. color = 0x333333,
  201. font_size = 20,
  202. })
  203. --------------------------------------------------------------------
  204. -- 示例7: 字体颜色对比
  205. --------------------------------------------------------------------
  206. local demo8_container = create_demo_container(scroll_container, "示例7: 字体颜色对比", 10, current_y, 300, 100)
  207. airui.label({
  208. parent = demo8_container,
  209. text = "红色字体",
  210. x = 20,
  211. y = 30,
  212. w = 260,
  213. h = 30,
  214. color = 0xFF0000,
  215. font_size = 16,
  216. })
  217. airui.label({
  218. parent = demo8_container,
  219. text = "绿色字体",
  220. x = 20,
  221. y = 55,
  222. w = 260,
  223. h = 30,
  224. color = 0x00FF00,
  225. font_size = 16,
  226. })
  227. airui.label({
  228. parent = demo8_container,
  229. text = "蓝色字体",
  230. x = 20,
  231. y = 80,
  232. w = 260,
  233. h = 30,
  234. color = 0x0000FF,
  235. font_size = 16,
  236. })
  237. -- 底部信息
  238. airui.label({
  239. parent = main_container,
  240. text = "提示: 矢量字体支持高质量中文显示",
  241. x = 10,
  242. y = 440,
  243. w = 300,
  244. h = 20,
  245. color = 0x666666,
  246. font_size = 12,
  247. })
  248. end
  249. ----------------------------------------------------------------
  250. -- 初始化页面
  251. ----------------------------------------------------------------
  252. function hzfont_page.init(params)
  253. hzfont_page.create_ui()
  254. end
  255. ----------------------------------------------------------------
  256. -- 清理页面
  257. ----------------------------------------------------------------
  258. function hzfont_page.cleanup()
  259. if main_container then
  260. main_container:destroy()
  261. main_container = nil
  262. end
  263. current_font = nil
  264. end
  265. return hzfont_page