aboutsummaryrefslogtreecommitdiffstats
path: root/button.lua
diff options
context:
space:
mode:
authorMatthias Richter <vrld@vrld.org>2012-02-07 23:10:29 +0100
committerMatthias Richter <vrld@vrld.org>2012-02-07 23:10:29 +0100
commit40dbc7134bae5cff48c2262d92721a3dd5394f84 (patch)
treede6097abf421b873aa6052928c56fbd578bafa01 /button.lua
downloadQuickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.tar.gz
Quickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.tar.bz2
Quickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.tar.xz
Quickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.zip
Initial commit
Diffstat (limited to 'button.lua')
-rw-r--r--button.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/button.lua b/button.lua
new file mode 100644
index 0000000..2374645
--- /dev/null
+++ b/button.lua
@@ -0,0 +1,27 @@
+local core = require((...):match("^(.+)%.[^%.]+") .. '.core')
+
+-- the widget
+return function(title, x,y, w,h, draw)
+ -- Generate unique identifier for gui state update and querying.
+ local id = core.generateID()
+
+ -- The widget mouse-state can be:
+ -- hot (mouse over widget),
+ -- active (mouse pressed on widget) or
+ -- normal (mouse not on widget and not pressed on widget).
+ --
+ -- core.mouse.updateState(id, x,y,w,h) updates the state for this widget.
+ core.mouse.updateState(id, x,y,w,h)
+
+ -- core.makeTabable makes the item focus on tab. Tab order is determied
+ -- by the order you call the widget functions.
+ core.makeTabable(id)
+
+ -- core.registerDraw(id, drawfunction, drawfunction-arguments...)
+ -- shows widget when core.draw() is called.
+ core.registerDraw(id, draw or core.style.Button, title,x,y,w,h)
+
+ return core.mouse.releasedOn(id) or
+ (core.keyboard.key == 'return' and core.hasKeyFocus(id))
+end
+