Reimplement text edit scrolling in C++

* And update some corelib APIs
This commit is contained in:
Eduardo Bart
2013-01-16 14:20:17 -02:00
parent a3fcf2e8e7
commit 2e75380218
21 changed files with 540 additions and 295 deletions

View File

@@ -3,11 +3,14 @@ UISpinBox = extends(UITextEdit)
function UISpinBox.create()
local spinbox = UISpinBox.internalCreate()
spinbox:setFocusable(false)
spinbox:setValidCharacters('0123456789')
spinbox.displayButtons = true
spinbox.minimum = 0
spinbox.maximum = 0
spinbox.value = 0
spinbox.step = 1
spinbox.firstchange = true
spinbox:setText("0")
return spinbox
end
@@ -21,6 +24,14 @@ function UISpinBox:onMouseWheel(mousePos, direction)
return true
end
function UISpinBox:onKeyPress()
if self.firstchange then
self.firstchange = false
self:setText('')
end
return false
end
function UISpinBox:onTextChange(text, oldText)
if text:len() == 0 then
self:setValue(self.minimum)
@@ -79,14 +90,15 @@ function UISpinBox:hideButtons()
end
function UISpinBox:up()
self:setValue(self.value + 1)
self:setValue(self.value + self.step)
end
function UISpinBox:down()
self:setValue(self.value - 1)
self:setValue(self.value - self.step)
end
function UISpinBox:setValue(value)
value = value or 0
value = math.max(math.min(self.maximum, value), self.minimum)
if value == self.value then return end
if self:getText():len() > 0 then
@@ -107,6 +119,7 @@ function UISpinBox:setValue(value)
end
function UISpinBox:setMinimum(minimum)
minimum = minimum or -9223372036854775808
self.minimum = minimum
if self.minimum > self.maximum then
self.maximum = self.minimum
@@ -117,12 +130,17 @@ function UISpinBox:setMinimum(minimum)
end
function UISpinBox:setMaximum(maximum)
maximum = maximum or 9223372036854775807
self.maximum = maximum
if self.value > maximum then
self:setValue(maximum)
end
end
function UISpinBox:setStep(step)
self.step = step or 1
end
function UISpinBox:getValue()
return self.value
end