2012-02-08 00:06:52 +01:00
|
|
|
RadioGroup = newclass()
|
|
|
|
|
|
|
|
function RadioGroup.create()
|
|
|
|
local radiogroup = RadioGroup.internalCreate()
|
|
|
|
radiogroup.widgets = {}
|
|
|
|
return radiogroup
|
|
|
|
end
|
|
|
|
|
|
|
|
function RadioGroup: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
|
|
|
|
|
|
|
|
function RadioGroup:addWidget(widget)
|
|
|
|
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
|
|
|
|
|
|
|
|
function RadioGroup:removeWidget(widget)
|
|
|
|
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
|
|
|
|
|
|
|
|
function RadioGroup:selectWidget(selectedWidget)
|
|
|
|
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
|
|
|
|
|
|
|
|
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
|
|
|
|
end
|