diff options
author | Matthias Richter <vrld@vrld.org> | 2013-01-23 12:40:07 +0100 |
---|---|---|
committer | Matthias Richter <vrld@vrld.org> | 2013-01-23 12:40:07 +0100 |
commit | 90eb0a91846a51787ff616fc174e809851077c6f (patch) | |
tree | ff65bdc55c37383dc259c66d97890d0fe0d43263 | |
parent | 84ac3c27820d43f0c348639c0d75701c49ee2f36 (diff) | |
download | Quickie-90eb0a91846a51787ff616fc174e809851077c6f.tar.gz Quickie-90eb0a91846a51787ff616fc174e809851077c6f.tar.bz2 Quickie-90eb0a91846a51787ff616fc174e809851077c6f.tar.xz Quickie-90eb0a91846a51787ff616fc174e809851077c6f.zip |
Change gui.checkbox interface.
Remove `info' table. The user is responsible for updating the checking
condition. Old style:
checkbox = {checked = true, label = "foo", align = "left"}
(...)
gui.Checkbox{info = checkbox}
New style:
checked = false
(...)
if gui.Checkbox{checked = checked, text = "foo", align = "left"} then
checked = not checked
end
Also note that `label' is renamed to `text'.
-rw-r--r-- | checkbox.lua | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/checkbox.lua b/checkbox.lua index e04f6a6..14a92a5 100644 --- a/checkbox.lua +++ b/checkbox.lua @@ -29,19 +29,19 @@ local group = require(BASE .. 'group') local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') --- {info = {checked = status, label = "", algin = "left"}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} +-- {checked = status, text = "", algin = "left", pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} return function(w) assert(type(w) == "table") - w.info.label = w.info.label or "" + w.text = w.text or "" local tight = w.size and (w.size[1] == 'tight' or w.size[2] == 'tight') if tight then local f = assert(love.graphics.getFont()) if w.size[1] == 'tight' then - w.size[1] = f:getWidth(w.info.label) + w.size[1] = f:getWidth(w.text) end if w.size[2] == 'tight' then - w.size[2] = f:getHeight(w.info.label) + w.size[2] = f:getHeight(w.text) end -- account for the checkbox local bw = math.min(w.size[1] or group.size[1], w.size[2] or group.size[2]) @@ -54,15 +54,15 @@ return function(w) mouse.updateWidget(id, pos, size, w.widgetHit) keyboard.makeCyclable(id) - local checked = w.info.checked + local checked = w.checked local key = keyboard.key if mouse.releasedOn(id) or ((key == 'return' or key == ' ') and keyboard.hasFocus(id)) then - w.info.checked = not w.info.checked + w.checked = not w.checked end core.registerDraw(id, w.draw or core.style.Checkbox, - w.info.checked, w.info.label, w.info.align or 'left', pos[1], pos[2], size[1], size[2]) + w.checked, w.text, w.align or 'left', pos[1], pos[2], size[1], size[2]) - return w.info.checked ~= checked + return w.checked ~= checked end |