Added styling option for UISpinBox buttons.

This commit is contained in:
BeniS 2012-08-29 01:40:04 +12:00
parent 0c5479b031
commit 9c497f72f9
2 changed files with 24 additions and 4 deletions

View File

@ -4,6 +4,7 @@ UISpinBox = extends(UITextEdit)
function UISpinBox.create() function UISpinBox.create()
local spinbox = UISpinBox.internalCreate() local spinbox = UISpinBox.internalCreate()
spinbox:setValidCharacters('0123456789') spinbox:setValidCharacters('0123456789')
spinbox.displayButtons = true
spinbox.minimum = 0 spinbox.minimum = 0
spinbox.maximum = 0 spinbox.maximum = 0
spinbox.value = 0 spinbox.value = 0
@ -50,15 +51,33 @@ end
function UISpinBox:onStyleApply(styleName, styleNode) function UISpinBox:onStyleApply(styleName, styleNode)
for name, value in pairs(styleNode) do for name, value in pairs(styleNode) do
if name == 'maximum' then if name == 'maximum' then
addEvent(function() self:setMaximum(value) addEvent(function() self:setMaximum(value) end)
end)
elseif name == 'minimum' then elseif name == 'minimum' then
addEvent(function() self:setMinimum(value) addEvent(function() self:setMinimum(value) end)
end) elseif name == 'buttons' then
addEvent(function()
if value then
self:showButtons()
else
self:hideButtons()
end
end)
end end
end end
end end
function UISpinBox:showButtons()
self:getChildById('up'):show()
self:getChildById('down'):show()
self.displayButtons = true
end
function UISpinBox:hideButtons()
self:getChildById('up'):hide()
self:getChildById('down'):hide()
self.displayButtons = false
end
function UISpinBox:up() function UISpinBox:up()
self:setValue(self.value + 1) self:setValue(self.value + 1)
end end

View File

@ -149,6 +149,7 @@ Panel
anchors.left: prev.right anchors.left: prev.right
margin-left: 3 margin-left: 3
width: 55 width: 55
buttons: false
minimum: 1 minimum: 1
maximum: 64000 maximum: 64000