tibia-client/modules/corelib/ui/uiradiogroup.lua

46 lines
1.1 KiB
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docclass
UIRadioGroup = newclass()
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 = {}
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
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)
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
widget.onClick = nil
2012-02-08 00:06:52 +01:00
table.removevalue(self.widgets, widget)
end
2012-06-26 00:13:30 +02:00
function UIRadioGroup:selectWidget(selectedWidget)
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
signalcall(self.onSelectionChange, self, selectedWidget, previousSelectedWidget)
end