Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An intuitive clickable text label for DFHack UI purposes.
local gui=require('gui')
local widgets=require('gui.widgets')
local ClickableLabel=defclass(ClickableLabel,widgets.Label)
ClickableLabel.ATTRS.on_click=DEFAULT_NIL
ClickableLabel.ATTRS.on_rclick=DEFAULT_NIL
ClickableLabel.ATTRS.default_pen=COLOR_CYAN
ClickableLabel.ATTRS.highlight_pen=DEFAULT_NIL
ClickableLabel.ATTRS.args={}
function ClickableLabel:onInput(keys)
if keys._MOUSE_L_DOWN and self:getMousePos() and self.on_click then
self:on_click()
end
if keys._MOUSE_R_DOWN and self:getMousePos() and self.on_rclick then
self:on_rclick()
end
end
function ClickableLabel:onRenderBody(dc)
if self:getMousePos() then
self.text_pen=self.highlight_pen
else
self.text_pen=self.default_pen
end
self.super.onRenderBody(self,dc)
end
function ClickableLabel:init(args)
if not self.highlight_pen then self.highlight_pen=(self.default_pen+8)%16 end
self.super.init(self,args)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment