mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
create "pseudo-widget" for option groups
This commit is contained in:
@@ -89,11 +89,12 @@ return { id = 'mainWindow',
|
|||||||
{ type = 'check', text = 'Vertical controls', id = 'flowToggle', },
|
{ type = 'check', text = 'Vertical controls', id = 'flowToggle', },
|
||||||
{ type = 'label', text = 'Some radio widgets' },
|
{ type = 'label', text = 'Some radio widgets' },
|
||||||
{
|
{
|
||||||
{ type = 'radio', text = 'One fish' },
|
{ type = 'radio', group = 'fish', text = 'One fish' },
|
||||||
{ type = 'radio', text = 'Two fish' },
|
{ type = 'radio', group = 'fish', text = 'Two fish' },
|
||||||
{ type = 'radio', text = 'Red fish' },
|
{ type = 'radio', group = 'fish', text = 'Red fish' },
|
||||||
{ type = 'radio', text = 'Blue fish' },
|
{ type = 'radio', group = 'fish', text = 'Blue fish' },
|
||||||
},
|
},
|
||||||
|
{ type = 'label', id = 'fishStatus' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ layout.sans2:onPress(function()
|
|||||||
layout.stepper.font = false
|
layout.stepper.font = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
layout.fish:onChange(function()
|
||||||
|
layout.fishStatus.text = 'Selected: ' .. layout.fish.selected.text
|
||||||
|
end)
|
||||||
|
|
||||||
-- show the main layout
|
-- show the main layout
|
||||||
layout:show()
|
layout:show()
|
||||||
|
|
||||||
|
|||||||
@@ -236,6 +236,10 @@ local function metaCall (Widget, layout, self)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Widget:getMasterLayout ()
|
||||||
|
return self.layout.master or self.layout
|
||||||
|
end
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Define a custom attribute for this widget.
|
Define a custom attribute for this widget.
|
||||||
|
|
||||||
|
|||||||
@@ -27,21 +27,26 @@ local function setGroup (self, value)
|
|||||||
local oldGroup = oldValue and groups[oldValue]
|
local oldGroup = oldValue and groups[oldValue]
|
||||||
if oldGroup then
|
if oldGroup then
|
||||||
remove(oldGroup, self)
|
remove(oldGroup, self)
|
||||||
if #oldGroup < 1 then
|
-- TODO: is it safe to remove these?
|
||||||
groups[oldValue] = nil
|
if #oldGroup < 1 then groups[oldValue] = nil end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
-- add the widget to the new group, or 'default' if no group specified
|
-- add the widget to the new group, or 'defaultGroup' if no group specified
|
||||||
value = value or 'default'
|
value = value or 'defaultGroup'
|
||||||
if not groups[value] then
|
if not groups[value] then
|
||||||
groups[value] = {}
|
groups[value] = {}
|
||||||
end
|
end
|
||||||
local group = groups[value]
|
local group = groups[value]
|
||||||
group[#group + 1] = self
|
group[#group + 1] = self
|
||||||
self.attributes.group = value
|
self.attributes.group = value
|
||||||
|
local layout = self:getMasterLayout()
|
||||||
|
if not layout[value] then
|
||||||
|
layout:createWidget { id = value, items = group }
|
||||||
|
end
|
||||||
|
self.groupWidget = layout[value]
|
||||||
end
|
end
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Special Attributes
|
Special Attributes
|
||||||
|
|
||||||
@@ -64,6 +69,14 @@ in the same group change to `false`.
|
|||||||
@section end
|
@section end
|
||||||
--]]--
|
--]]--
|
||||||
|
|
||||||
|
-- when we bubble events, send them to the group widget
|
||||||
|
local bubbleEvent = self.bubbleEvent
|
||||||
|
function self:bubbleEvent (...)
|
||||||
|
local result = bubbleEvent(self, ...)
|
||||||
|
if result ~= nil then return result end
|
||||||
|
return self.groupWidget:bubbleEvent(...)
|
||||||
|
end
|
||||||
|
|
||||||
self:onPress(function (event)
|
self:onPress(function (event)
|
||||||
if event.button ~= 'left' then return end
|
if event.button ~= 'left' then return end
|
||||||
for _, widget in ipairs(groups[self.group]) do
|
for _, widget in ipairs(groups[self.group]) do
|
||||||
@@ -71,5 +84,11 @@ in the same group change to `false`.
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
self:onChange(function (event)
|
||||||
|
-- change event is only sent to group widget once.
|
||||||
|
if not self.value then return false end
|
||||||
|
self.groupWidget.selected = self
|
||||||
|
end)
|
||||||
|
|
||||||
self.value = not not self.value
|
self.value = not not self.value
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user