mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
34 lines
654 B
Lua
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
|