prompt.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --- 模块功能:提示框窗口
  2. -- @author openLuat
  3. -- @module ui.prompt
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2018.03.27
  7. module(...,package.seeall)
  8. --appid:窗口id
  9. --str1,str2,str3:最多显示的3行字符串
  10. --callback,callbackpara:提示框窗口关闭后的回调函数以及回调函数的参数
  11. local appid,str1,str2,str3,callback,callbackpara
  12. local pos =
  13. {
  14. {24},--显示1行字符串时的Y坐标
  15. {10,37},--显示2行字符串时,每行字符串对应的Y坐标
  16. {4,24,44},--显示3行字符串时,每行字符串对应的Y坐标
  17. }
  18. --[[
  19. 函数名:refresh
  20. 功能 :窗口刷新处理
  21. 参数 :无
  22. 返回值:无
  23. ]]
  24. local function refresh()
  25. disp.clear()
  26. if str3 then
  27. disp.puttext(str3,lcd.getxpos(str3),pos[3][3])
  28. end
  29. if str2 then
  30. disp.puttext(str2,lcd.getxpos(str2),pos[str3 and 3 or 2][2])
  31. end
  32. if str1 then
  33. disp.puttext(str1,lcd.getxpos(str1),pos[str3 and 3 or (str2 and 2 or 1)][1])
  34. end
  35. disp.update()
  36. end
  37. --[[
  38. 函数名:close
  39. 功能 :关闭提示框窗口
  40. 参数 :无
  41. 返回值:无
  42. ]]
  43. local function close()
  44. if not appid then return end
  45. sys.timerStop(close)
  46. if callback then callback(callbackpara) end
  47. uiWin.remove(appid)
  48. appid = nil
  49. end
  50. --窗口的消息处理函数表
  51. local app = {
  52. onUpdate = refresh,
  53. }
  54. --[[
  55. 函数名:open
  56. 功能 :打开提示框窗口
  57. 参数 :
  58. s1:string类型,显示的第1行字符串
  59. s2:string类型,显示的第2行字符串,可以为空或者nil
  60. s3:string类型,显示的第3行字符串,可以为空或者nil
  61. cb:function类型,提示框关闭时的回调函数,可以为nil
  62. cbpara:提示框关闭时回调函数的参数,可以为nil
  63. prd:number类型,提示框自动关闭的超时时间,单位毫秒,默认3000毫秒
  64. 返回值:无
  65. ]]
  66. function open(s1,s2,s3,cb,cbpara,prd)
  67. str1,str2,str3,callback,callbackpara = s1,s2,s3,cb,cbpara
  68. appid = uiWin.add(app)
  69. sys.timerStart(close,prd or 3000)
  70. end