Qivex

Texttafel (qua Example)

Apr 30th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. -- IMPORT
  2. local Display = require "qua.ui.display"
  3. local MultiScreen = require "qua.ui.multiscreen"
  4. local Label = require "qua.ui.label"
  5. local Markup = require "qua.ui.markup"
  6. local Button = require "qua.ui.button"
  7.  
  8.  
  9. -- CONSTANTS
  10. local PAGE_CONTENT = {
  11. [[
  12. Hier kann &5Falles
  13. stehen was man
  14. sich irgendwie
  15. ausdenken kann
  16. ]],
  17. [[
  18. Zum Beispiel
  19. einen tollen
  20. &FER&F1e&F4g&F5e&FDn&FBb&F9o&F3g&FAe&F2n
  21. ]],
  22. [[
  23. PS:
  24. Die Reihenfolge
  25. um an den besten
  26. Farbverlauf zu
  27. kommen ist:
  28. 087FCE145DB93A26
  29. ]],
  30. [[
  31. &F0 &F8 &F7 &FF &FC &FE &F1 &F4 &F5 &FD &FB &F9 &F3 &FA &F2 &F6
  32.  
  33. &0F@&8F@&7F@&FF@&CF@&EF@&1F@&4F@&5F@&DF@&BF@&9F@&3F@&AF@&2F@&6F@
  34. ]]
  35. }
  36.  
  37.  
  38. -- IMPLEMENTATION
  39. -- Screens
  40. local d = Display("left", 1)
  41. local w,h = d:getSize()
  42. local welcomeScreen = d:getNewScreen("welcome")
  43. local textScreen = d:getNewScreen("text")
  44. local textPages = MultiScreen({1,1}, {w,h-3})
  45. textScreen:addDynamic(textPages)
  46.  
  47. -- Pages
  48. local current = 1
  49. local screenNames = {}
  50. for index, multiline in pairs(PAGE_CONTENT) do
  51.     -- Keep track of screen names
  52.     local name = "page_" .. index
  53.     table.insert(screenNames, name)
  54.     -- Construct screen
  55.     local screen = textPages:getNewScreen(name)
  56.     local y = 2
  57.     for line in multiline:gmatch("(.-)\n") do
  58.         screen:addStatic(Markup(line, {2,y}))
  59.         y = y + 1
  60.     end
  61. end
  62. textPages:selectScreen(screenNames[1])
  63.  
  64. -- Navigation
  65. local pageDown = Button("<-", {1,h-2}, {6,3}, colors.black, colors.yellow)
  66. local pageUp = Button("->", {w-5,h-2}, {6,3}, colors.black, colors.yellow)
  67. textScreen:addStatic(pageDown)
  68. textScreen:addStatic(pageUp)
  69. pageDown:setAction(function()
  70.     current = current - 1
  71.     if current < 1 then
  72.         current = #screenNames
  73.     end
  74.     textPages:selectScreen(screenNames[current])
  75.     -- Update Page-Label
  76.     d:update()
  77. end)
  78. pageUp:setAction(function()
  79.     current = current + 1
  80.     if current > #screenNames then
  81.         current = 1
  82.     end
  83.     textPages:selectScreen(screenNames[current])
  84.     -- Update Page-Label
  85.     d:update()
  86. end)
  87.  
  88.  
  89. -- MAIN
  90. d:selectScreen("welcome")
  91. os.pullEvent("monitor_touch")
  92. d:selectScreen("text")
  93. while true do
  94.     local event, side, x, y = os.pullEvent("monitor_touch")
  95.     d:click(x, y)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment