Files
love-luigi/luigi/widget/radio.lua
2015-11-29 23:24:12 -05:00

34 lines
654 B
Lua

--[[--
A radio button.
@widget radio
--]]--
-- TODO: make `group` a first-class attribute
local groups = {}
return function (self)
local groupName = self.group or 'default'
if not groups[groupName] then
groups[groupName] = {}
end
local group = groups[groupName]
group[#group + 1] = self
self:onPress(function ()
for _, widget in ipairs(group) do
widget.value = widget == self
end
end)
self:onChange(function ()
local subtype = self.value and 'radio.checked' or 'radio.unchecked'
self.type = { 'radio', subtype }
end)
self.value = not not self.value
end