aboutsummaryrefslogtreecommitdiffstats
path: root/checkbox.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 /checkbox.lua
downloadQuickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.tar.gz
Quickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.tar.bz2
Quickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.tar.xz
Quickie-40dbc7134bae5cff48c2262d92721a3dd5394f84.zip
Initial commit
Diffstat (limited to 'checkbox.lua')
-rw-r--r--checkbox.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/checkbox.lua b/checkbox.lua
new file mode 100644
index 0000000..c5f5fce
--- /dev/null
+++ b/checkbox.lua
@@ -0,0 +1,19 @@
+local core = require((...):match("^(.+)%.[^%.]+") .. '.core')
+
+return function(info, x,y, w,h, draw)
+ local id = core.generateID()
+
+ core.mouse.updateState(id, x,y,w,h)
+ core.makeTabable(id)
+ core.registerDraw(id, draw or core.style.Checkbox, info.checked,x,y,w,h)
+
+ local checked = info.checked
+ local key = core.keyboard.key
+ if core.mouse.releasedOn(id) or
+ (core.hasKeyFocus(id) and key == 'return' or key == ' ') then
+ info.checked = not info.checked
+ end
+
+ return info.checked ~= checked
+end
+