Advertisement
Alakazard12

Scroll Bar Test

May 2nd, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. os.loadAPI("/agui")
  2. local update
  3. local on = 1
  4. local bX = 0
  5. local bY = 0
  6.  
  7. local function round(num)
  8.   return math.floor(num+0.5)
  9. end
  10.  
  11. local m = agui:new()
  12. m:setBackgroundColor(colors.cyan)
  13.  
  14. local bar = m:create("button")
  15. bar:setSize(1, 4)
  16. bar:setPosition(51, 1)
  17. bar:setBackgroundColor(colors.gray)
  18. bar:setText("")
  19. bar.button1Click(function(x, y)
  20.   local px, py = bar:getPosition()
  21.   bX = px - x
  22.   bY = py - y
  23. end)
  24. bar.button1Drag(function(x, y)
  25.   y = y + bY
  26.   if y < 1 then
  27.     y = 1
  28.   end
  29.   if y > 19-3 then
  30.     y = 19-3
  31.   end
  32.   on = round((((y-(19-3))/((19-3))+1))*(32-18))
  33.   bar:setPosition(51, y)
  34.   update()
  35.   m:draw()
  36. end)
  37.  
  38. local items = {}
  39. for i = 1, 19 do
  40.   local it = m:create("label")
  41.   it:setSize(50, 1)
  42.   it:setPosition(1, i)
  43.   it:setText("Derp")
  44.   it:setBackgroundColor(colors.black)
  45.   it:setTextColor(colors.white)
  46.   table.insert(items, it)
  47. end
  48.  
  49. function update()
  50.   for i = on, on + 18 do
  51.     local it = items[1 - on + i]
  52.     it:setText("Number: " .. i)
  53.   end
  54. end
  55.  
  56. update()
  57. m:draw()
  58. m:listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement