aboutsummaryrefslogtreecommitdiffstats
path: root/checkbox.lua
blob: db282a706db7b6f022648708060fddb2ada5d0db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local core = require((...):match("(.-)[^%.]+$") .. 'core')

return function(info, x,y, w,h, widgetHit, draw)
	local id = core.generateID()

	core.mouse.updateState(id, widgetHit or core.style.widgetHit, x,y,w,h)
	core.makeCyclable(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