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) function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
if self.verticalScrollBar then if self.verticalScrollBar then
if not self.verticalScrollBar:isOn() then
return false
end
if mouseWheel == MouseWheelUp then if mouseWheel == MouseWheelUp then
local minimum = self.verticalScrollBar:getMinimum()
if self.verticalScrollBar:getValue() <= minimum then
return false
end
self.verticalScrollBar:decrement() self.verticalScrollBar:decrement()
else else
local maximum = self.verticalScrollBar:getMaximum()
if self.verticalScrollBar:getValue() >= maximum then
return false
end
self.verticalScrollBar:increment() self.verticalScrollBar:increment()
end end
elseif self.horizontalScrollBar then elseif self.horizontalScrollBar then
if not self.horizontalScrollBar:isOn() then
return false
end
if mouseWheel == MouseWheelUp then if mouseWheel == MouseWheelUp then
local maximum = self.horizontalScrollBar:getMaximum()
if self.horizontalScrollBar:getValue() >= maximum then
return false
end
self.horizontalScrollBar:increment() self.horizontalScrollBar:increment()
else else
local minimum = self.horizontalScrollBar:getMinimum()
if self.horizontalScrollBar:getValue() <= minimum then
return false
end
self.horizontalScrollBar:decrement() self.horizontalScrollBar:decrement()
end end
end end

View File

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

View File

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