2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2014-06-06 18:10:14 +02:00
|
|
|
UIRadioGroup = newclass("UIRadioGroup")
|
2012-02-08 00:06:52 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function UIRadioGroup.create()
|
|
|
|
local radiogroup = UIRadioGroup.internalCreate()
|
2012-02-08 00:06:52 +01:00
|
|
|
radiogroup.widgets = {}
|
2012-07-22 16:02:01 +02:00
|
|
|
radiogroup.selectedWidget = nil
|
2012-02-08 00:06:52 +01:00
|
|
|
return radiogroup
|
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function UIRadioGroup:destroy()
|
2012-04-09 22:52:39 +02:00
|
|
|
for k,widget in pairs(self.widgets) do
|
2012-05-09 14:24:35 +02:00
|
|
|
widget.onClick = nil
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
2012-04-09 22:52:39 +02:00
|
|
|
self.widgets = {}
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function UIRadioGroup:addWidget(widget)
|
2012-02-08 00:06:52 +01:00
|
|
|
table.insert(self.widgets, widget)
|
2012-05-09 14:24:35 +02:00
|
|
|
widget.onClick = function(widget) self:selectWidget(widget) end
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function UIRadioGroup:removeWidget(widget)
|
2012-02-08 00:06:52 +01:00
|
|
|
if self.selectedWidget == widget then
|
|
|
|
self:selectWidget(nil)
|
|
|
|
end
|
2012-05-09 14:24:35 +02:00
|
|
|
widget.onClick = nil
|
2012-02-08 00:06:52 +01:00
|
|
|
table.removevalue(self.widgets, widget)
|
|
|
|
end
|
|
|
|
|
2014-07-12 21:38:11 +02:00
|
|
|
function UIRadioGroup:selectWidget(selectedWidget, dontSignal)
|
2012-02-08 00:06:52 +01:00
|
|
|
if selectedWidget == self.selectedWidget then return end
|
|
|
|
|
|
|
|
local previousSelectedWidget = self.selectedWidget
|
|
|
|
self.selectedWidget = selectedWidget
|
|
|
|
|
|
|
|
if previousSelectedWidget then
|
|
|
|
previousSelectedWidget:setChecked(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
if selectedWidget then
|
|
|
|
selectedWidget:setChecked(true)
|
|
|
|
end
|
|
|
|
|
2014-07-12 21:38:11 +02:00
|
|
|
if not dontSignal then
|
|
|
|
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
|
|
|
|
end
|
2012-02-08 00:06:52 +01:00
|
|
|
end
|
2012-07-22 16:02:01 +02:00
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
function UIRadioGroup:clearSelected()
|
|
|
|
if not self.selectedWidget then return end
|
2014-01-18 15:09:26 +01:00
|
|
|
|
2012-08-14 17:43:48 +02:00
|
|
|
local previousSelectedWidget = self.selectedWidget
|
|
|
|
self.selectedWidget:setChecked(false)
|
|
|
|
self.selectedWidget = nil
|
|
|
|
|
|
|
|
signalcall(self.onSelectionChange, self, nil, previousSelectedWidget)
|
|
|
|
end
|
|
|
|
|
2012-07-22 16:02:01 +02:00
|
|
|
function UIRadioGroup:getSelectedWidget()
|
|
|
|
return self.selectedWidget
|
2013-01-31 02:44:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function UIRadioGroup:getFirstWidget()
|
|
|
|
return self.widgets[1]
|
|
|
|
end
|