2011-12-28 20:38:29 +01:00
|
|
|
UIComboBox = extends(UIWidget)
|
2012-01-04 11:26:58 +01:00
|
|
|
|
|
|
|
function UIComboBox.create()
|
|
|
|
local combobox = UIComboBox.internalCreate()
|
|
|
|
combobox.options = {}
|
|
|
|
combobox.currentIndex = -1
|
|
|
|
return combobox
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIComboBox:setCurrentOption(text)
|
|
|
|
if not self.options then return end
|
|
|
|
for i,v in ipairs(self.options) do
|
|
|
|
if v.text == text and self.currentIndex ~= i then
|
|
|
|
self.currentIndex = i
|
|
|
|
self:setText(text)
|
|
|
|
self:onOptionChange(text, data)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIComboBox:addOption(text, data)
|
|
|
|
table.insert(self.options, { text = text, data = data })
|
|
|
|
local index = #self.options
|
|
|
|
if index == 1 then self:setCurrentOption(text) end
|
|
|
|
return index
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIComboBox:onMousePress(mousePos, mouseButton)
|
2012-01-04 12:24:29 +01:00
|
|
|
local menu = createWidget(self:getStyleName() .. 'PopupMenu', self)
|
2012-01-04 11:26:58 +01:00
|
|
|
for i,v in ipairs(self.options) do
|
|
|
|
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
|
|
|
|
end
|
|
|
|
menu:setWidth(self:getWidth())
|
|
|
|
menu:display({ x = self:getX(), y = self:getY() + self:getHeight() })
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIComboBox:onOptionChange(optionText, optionData)
|
|
|
|
-- nothing todo
|
|
|
|
end
|