win_password_input.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --[[
  2. @module win_password_input
  3. @summary 密码输入框演示模块
  4. @version 1.0.0
  5. @date 2025.11.28
  6. @author 江访
  7. @usage
  8. 本文件为密码输入框演示模块,核心业务逻辑为:
  9. 1、创建窗口容器并设置白色背景;
  10. 2、添加密码输入框组件;
  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. -- 创建密码输入框组件
  24. local password_input = ui.input({
  25. x = 20, y = 20,
  26. w = 150, h = 30,
  27. placeholder = "Enter password...",
  28. input_type = "password",
  29. max_length = 16
  30. })
  31. -- 创建密码显示/隐藏切换按钮
  32. local password_visible = false
  33. local btn_password_toggle = ui.button({
  34. x = 180, y = 20,
  35. w = 60, h = 30,
  36. text = "Show",
  37. bg_color = ui.COLOR_BLUE,
  38. text_color = ui.COLOR_WHITE,
  39. on_click = function()
  40. password_visible = not password_visible
  41. password_input.input_type = password_visible and "text" or "password"
  42. btn_password_toggle:set_text(password_visible and "Hide" or "Show")
  43. end
  44. })
  45. -- 添加组件到窗口
  46. page1:add(password_input)
  47. page1:add(btn_password_toggle)
  48. -- 注册窗口到UI系统
  49. ui.add(page1)
  50. end
  51. sys.taskInit(ui_main)