add check and radio controls
@@ -101,6 +101,48 @@ return function (config)
|
||||
text_focused = {
|
||||
slices = RESOURCE .. 'text_focused.png',
|
||||
},
|
||||
check = {
|
||||
canFocus = true,
|
||||
},
|
||||
['check.unchecked'] = {
|
||||
icon = RESOURCE .. 'check_unchecked.png',
|
||||
},
|
||||
['check.checked'] = {
|
||||
icon = RESOURCE .. 'check_checked.png',
|
||||
},
|
||||
['check.unchecked_pressed'] = {
|
||||
icon = RESOURCE .. 'check_unchecked_pressed.png',
|
||||
},
|
||||
['check.checked_pressed'] = {
|
||||
icon = RESOURCE .. 'check_checked_pressed.png',
|
||||
},
|
||||
['check.unchecked_focused'] = {
|
||||
icon = RESOURCE .. 'check_unchecked_focused.png',
|
||||
},
|
||||
['check.checked_focused'] = {
|
||||
icon = RESOURCE .. 'check_checked_focused.png',
|
||||
},
|
||||
radio = {
|
||||
canFocus = true,
|
||||
},
|
||||
['radio.unchecked'] = {
|
||||
icon = RESOURCE .. 'radio_unchecked.png',
|
||||
},
|
||||
['radio.checked'] = {
|
||||
icon = RESOURCE .. 'radio_checked.png',
|
||||
},
|
||||
['radio.unchecked_pressed'] = {
|
||||
icon = RESOURCE .. 'radio_unchecked_pressed.png',
|
||||
},
|
||||
['radio.checked_pressed'] = {
|
||||
icon = RESOURCE .. 'radio_checked_pressed.png',
|
||||
},
|
||||
['radio.unchecked_focused'] = {
|
||||
icon = RESOURCE .. 'radio_unchecked_focused.png',
|
||||
},
|
||||
['radio.checked_focused'] = {
|
||||
icon = RESOURCE .. 'radio_checked_focused.png',
|
||||
},
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
BIN
luigi/theme/light/check_checked.png
Normal file
|
After Width: | Height: | Size: 563 B |
BIN
luigi/theme/light/check_checked_focused.png
Normal file
|
After Width: | Height: | Size: 648 B |
BIN
luigi/theme/light/check_checked_pressed.png
Normal file
|
After Width: | Height: | Size: 567 B |
BIN
luigi/theme/light/check_unchecked.png
Normal file
|
After Width: | Height: | Size: 297 B |
BIN
luigi/theme/light/check_unchecked_focused.png
Normal file
|
After Width: | Height: | Size: 313 B |
BIN
luigi/theme/light/check_unchecked_pressed.png
Normal file
|
After Width: | Height: | Size: 288 B |
BIN
luigi/theme/light/radio_checked.png
Normal file
|
After Width: | Height: | Size: 772 B |
BIN
luigi/theme/light/radio_checked_focused.png
Normal file
|
After Width: | Height: | Size: 815 B |
BIN
luigi/theme/light/radio_checked_pressed.png
Normal file
|
After Width: | Height: | Size: 724 B |
BIN
luigi/theme/light/radio_unchecked.png
Normal file
|
After Width: | Height: | Size: 538 B |
BIN
luigi/theme/light/radio_unchecked_focused.png
Normal file
|
After Width: | Height: | Size: 575 B |
BIN
luigi/theme/light/radio_unchecked_pressed.png
Normal file
|
After Width: | Height: | Size: 520 B |
@@ -19,9 +19,11 @@ Widget.isWidget = true
|
||||
|
||||
Widget.typeDecorators = {
|
||||
button = require(ROOT .. 'widget.button'),
|
||||
check = require(ROOT .. 'widget.check'),
|
||||
menu = require(ROOT .. 'widget.menu'),
|
||||
['menu.item'] = require(ROOT .. 'widget.menu.item'),
|
||||
progress = require(ROOT .. 'widget.progress'),
|
||||
radio = require(ROOT .. 'widget.radio'),
|
||||
sash = require(ROOT .. 'widget.sash'),
|
||||
slider = require(ROOT .. 'widget.slider'),
|
||||
stepper = require(ROOT .. 'widget.stepper'),
|
||||
|
||||
18
luigi/widget/check.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
--[[--
|
||||
A check box.
|
||||
|
||||
@widget check
|
||||
--]]--
|
||||
|
||||
return function (self)
|
||||
self:onPress(function ()
|
||||
self.value = not self.value
|
||||
end)
|
||||
|
||||
self:onChange(function ()
|
||||
local subtype = self.value and 'check.checked' or 'check.unchecked'
|
||||
self.type = { 'check', subtype }
|
||||
end)
|
||||
|
||||
self.value = not not self.value
|
||||
end
|
||||
33
luigi/widget/radio.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
--[[--
|
||||
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
|
||||