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'.
This commit is contained in:
parent
84ac3c2782
commit
90eb0a9184
1 changed files with 8 additions and 8 deletions
16
checkbox.lua
16
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue