This commit is contained in:
Sam 2014-07-12 18:44:15 +02:00
commit 6b8e810466
3 changed files with 43 additions and 2 deletions

View File

@ -107,15 +107,37 @@ end
function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
if self.verticalScrollBar then
if not self.verticalScrollBar:isOn() then
return false
end
if mouseWheel == MouseWheelUp then
local minimum = self.verticalScrollBar:getMinimum()
if self.verticalScrollBar:getValue() <= minimum then
return false
end
self.verticalScrollBar:decrement()
else
local maximum = self.verticalScrollBar:getMaximum()
if self.verticalScrollBar:getValue() >= maximum then
return false
end
self.verticalScrollBar:increment()
end
elseif self.horizontalScrollBar then
if not self.horizontalScrollBar:isOn() then
return false
end
if mouseWheel == MouseWheelUp then
local maximum = self.horizontalScrollBar:getMaximum()
if self.horizontalScrollBar:getValue() >= maximum then
return false
end
self.horizontalScrollBar:increment()
else
local minimum = self.horizontalScrollBar:getMinimum()
if self.horizontalScrollBar:getValue() <= minimum then
return false
end
self.horizontalScrollBar:decrement()
end
end

View File

@ -234,19 +234,23 @@ function UIScrollBar:onGeometryChange()
end
function UIScrollBar:onMouseWheel(mousePos, mouseWheel)
if not self.mouseScroll then
if not self.mouseScroll or not self:isOn() then
return false
end
if mouseWheel == MouseWheelUp then
if self.orientation == 'vertical' then
if self.value <= self.minimum then return false end
self:decrement()
else
if self.value >= self.maximum then return false end
self:increment()
end
else
if self.orientation == 'vertical' then
if self.value >= self.maximum then return false end
self:increment()
else
if self.value <= self.minimum then return false end
self:decrement()
end
end

View File

@ -7,11 +7,13 @@ function UISpinBox.create()
spinbox:setValidCharacters('0123456789')
spinbox.displayButtons = true
spinbox.minimum = 0
spinbox.maximum = 0
spinbox.maximum = 1
spinbox.value = 0
spinbox.step = 1
spinbox.firstchange = true
spinbox.mouseScroll = true
spinbox:setText("0")
spinbox:setValue(1)
return spinbox
end
@ -21,6 +23,9 @@ function UISpinBox:onSetup()
end
function UISpinBox:onMouseWheel(mousePos, direction)
if not self.mouseScroll then
return false
end
if direction == MouseWheelUp then
self:up()
elseif direction == MouseWheelDown then
@ -70,6 +75,8 @@ function UISpinBox:onStyleApply(styleName, styleNode)
addEvent(function() self:setMaximum(value) end)
elseif name == 'minimum' then
addEvent(function() self:setMinimum(value) end)
elseif name == 'mouse-scroll' then
addEvent(function() self:setMouseScroll(value) end)
elseif name == 'buttons' then
addEvent(function()
if value then
@ -157,3 +164,11 @@ end
function UISpinBox:setStep(step)
self.step = step or 1
end
function UISpinBox:setMouseScroll(mouseScroll)
self.mouseScroll = mouseScroll
end
function UISpinBox:getMouseScroll()
return self.mouseScroll
end