Skip to content

Instantly share code, notes, and snippets.

@drhayes
Created April 3, 2020 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhayes/f8a189795b1716ac75b0e3e236610fef to your computer and use it in GitHub Desktop.
Save drhayes/f8a189795b1716ac75b0e3e236610fef to your computer and use it in GitHub Desktop.
The basic button control from my GUI lib in Gemini Rising
local Button = Control:extend()
Button:implement(EventEmitter)
function Button:new(text, x, y, w, h)
self.text = text
w = w or (ui.font:getWidth(text) + 20)
h = h or 20
Button.super.new(self, x, y, w or 40, h)
self.layout = fillLayout(0)
self.fill = self:add(Fill())
self.label = self:add(Label(text, 0, 0, w or 40, h, 'center', 'middle'))
self.label:setColor(1, 1, 1)
self.label.isBold = true
self:updateLayout()
end
function Button:userInput(input)
if input == 'trigger' then
self:emit('trigger')
return true
end
return Button.super.userInput(self, input)
end
function Button:onFocus()
self.fill.isFocused = true
self:emit('focus', self)
end
function Button:onBlur()
self.fill.isFocused = false
self:emit('blur', self)
end
function Button:__tostring()
return 'Button'
end
return Button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment