MattiasBuelens

CCGUI button

Jul 6th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. --[[
  2.  
  3.     ComputerCraft GUI
  4.     Button element
  5.  
  6. --]]
  7.  
  8. ccgui = ccgui or {}
  9.  
  10. local Button = common.newClass({
  11.     -- Style
  12.     foreground = colours.grey,
  13.     background = colours.lightGrey,
  14.     border = ccgui.newBorder(0),
  15.     padding = ccgui.newMargins(1)
  16. }, ccgui.TextElement)
  17. ccgui.Button = Button
  18.  
  19. function Button:init()
  20.     ccgui.TextElement.init(self)
  21.  
  22.     self:on("mouse_click", self.buttonClick, self)
  23. end
  24.  
  25. function Button:buttonClick(button, x, y)
  26.     if button == 1 then
  27.         -- Left mouse button, trigger pressed
  28.         if self.isVisible and self:contains(x, y) then
  29.             self:trigger("buttonpress")
  30.         end
  31.     end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment