SergOmarov

Menu for forms.lua

Sep 22nd, 2015
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Component Menu for forms.lua, (c)SergOmarov,2015
  2. local TMenu=setmetatable({W=20, H=10, selColor=0x0000ff, sfColor=0xffff00,
  3.   type=function() return "Menu" end},TComponent)
  4. TMenu.__index=TMenu
  5. function TMenu:clear()
  6.   self:redraw()
  7. end
  8.  
  9. function TMenu:paint()
  10. gpu.setForeground(self.sfColor)
  11. gpu.setBackground(self.selColor)
  12. local y=self.top-1
  13. local x=self.left
  14. for i=1,#self.items do
  15. gpu.set(x,y+i,self.items[i].text)
  16.  
  17. end
  18. end
  19. function TMenu:insert(pos,line,item)
  20. end
  21. function TMenu:sort(comp)
  22. end
  23.  
  24. function TMenu:touch(x, y, btn, user)
  25. self:hide()
  26. local select=self.items[y] or {text=""}
  27. if(x<=#select.text)then
  28. self.items[y].func()
  29. end
  30. end
  31.  
  32. function TComponent:addMenu(left, top,items)
  33.   local obj={left=left, top=top, items=items}
  34.   self:makeChild(obj)
  35.   local menu=setmetatable(obj,TMenu)
  36.   menu:hide()
  37.   return menu
  38. end
RAW Paste Data