Fix #17: Support multiple instances
This commit is contained in:
parent
f77ab8e5e8
commit
aca8a297bb
14 changed files with 385 additions and 244 deletions
15
checkbox.lua
15
checkbox.lua
|
@ -1,9 +1,8 @@
|
|||
-- This file is part of SUIT, copyright (c) 2016 Matthias Richter
|
||||
|
||||
local BASE = (...):match('(.-)[^%.]+$')
|
||||
local core = require(BASE .. 'core')
|
||||
|
||||
return function(checkbox, ...)
|
||||
return function(core, checkbox, ...)
|
||||
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
||||
opt.id = opt.id or checkbox
|
||||
opt.font = opt.font or love.graphics.getFont()
|
||||
|
@ -11,18 +10,18 @@ return function(checkbox, ...)
|
|||
w = w or (opt.font:getWidth(checkbox.text) + opt.font:getHeight() + 4)
|
||||
h = h or opt.font:getHeight() + 4
|
||||
|
||||
core.registerHitbox(opt.id, x,y,w,h)
|
||||
local hit = core.mouseReleasedOn(opt.id)
|
||||
opt.state = core:registerHitbox(opt.id, x,y,w,h)
|
||||
local hit = core:mouseReleasedOn(opt.id)
|
||||
if hit then
|
||||
checkbox.checked = not checkbox.checked
|
||||
end
|
||||
core.registerDraw(core.theme.Checkbox, checkbox, opt, x,y,w,h)
|
||||
core:registerDraw(core.theme.Checkbox, checkbox, opt, x,y,w,h)
|
||||
|
||||
return {
|
||||
id = opt.id,
|
||||
hit = hit,
|
||||
hovered = core.isHot(opt.id),
|
||||
entered = core.isHot(opt.id) and not core.wasHot(opt.id),
|
||||
left = not core.isHot(opt.id) and core.wasHot(opt.id)
|
||||
hovered = core:isHovered(opt.id),
|
||||
entered = core:isHovered(opt.id) and not core:wasHovered(opt.id),
|
||||
left = not core:isHovered(opt.id) and core:wasHovered(opt.id)
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue