Created
May 8, 2016 05:56
-
-
Save Putnam3145/e5d4aab2228b44b51b830021da4631c2 to your computer and use it in GitHub Desktop.
An intuitive clickable text label for DFHack UI purposes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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