Permalink
Browse files

Let mouseWheel events obey scrollHorizontal and scrollVertical

Fixes #288
  • Loading branch information...
nvh committed Aug 2, 2016
1 parent 2a84e68 commit dc847a481372e4fcb9cbbaa23a2a9a9342b41f9f
Showing with 49 additions and 2 deletions.
  1. +12 −2 framer/Components/ScrollComponent.coffee
  2. +37 −0 test/tests/ScrollComponentTest.coffee
@@ -357,6 +357,15 @@ class exports.ScrollComponent extends Layer
@off(Events.MouseWheel, @_onMouseWheel)
_onMouseWheel: (event) =>
+ deltaX = 0
+ deltaY = 0
+ if @scrollHorizontal
+ deltaX = event.wheelDeltaX
+ if @scrollVertical
+ deltaY = event.wheelDeltaY
+
+ if deltaX == 0 and deltaY == 0
+ return
if not @_mouseWheelScrolling
@_mouseWheelScrolling = true
@@ -367,9 +376,10 @@ class exports.ScrollComponent extends Layer
{minX, maxX, minY, maxY} = @content.draggable._calculateConstraints(
@content.draggable.constraints)
+
point =
- x: Utils.clamp(@content.x + (event.wheelDeltaX * @mouseWheelSpeedMultiplier), minX, maxX)
- y: Utils.clamp(@content.y + (event.wheelDeltaY * @mouseWheelSpeedMultiplier), minY, maxY)
+ x: Utils.clamp(@content.x + (deltaX * @mouseWheelSpeedMultiplier), minX, maxX)
+ y: Utils.clamp(@content.y + (deltaY * @mouseWheelSpeedMultiplier), minY, maxY)
@content.point = point
@@ -35,6 +35,43 @@ describe "ScrollComponent", ->
copy = instance.copy()
copy.scrollHorizontal.should.be.false
+ describe "scolling with mousEvents", ->
+ it "should work", ->
+ scroll = new ScrollComponent size: 200
+ new Layer
+ width: 400
+ height: 400
+ parent: scroll.content
+ scroll.mouseWheelEnabled = true
+ scroll.emit(Events.MouseWheel, {wheelDeltaX: -75, wheelDeltaY: -150})
+ scroll.content.x.should.equal -75
+ scroll.content.y.should.equal -150
+
+ it "should respect scrollHorizontal = false", ->
+ scroll = new ScrollComponent size: 200
+ new Layer
+ width: 400
+ height: 400
+ parent: scroll.content
+ scroll.mouseWheelEnabled = true
+ scroll.scrollHorizontal = false
+ scroll.emit(Events.MouseWheel, {wheelDeltaX: -75, wheelDeltaY: -150})
+ scroll.content.x.should.equal 0
+ scroll.content.y.should.equal -150
+
+ it "should respect scrollVertial = false", ->
+ scroll = new ScrollComponent size: 200
+ new Layer
+ width: 400
+ height: 400
+ parent: scroll.content
+ scroll.mouseWheelEnabled = true
+ scroll.scrollVertical = false
+ scroll.emit(Events.MouseWheel, {wheelDeltaX: -75, wheelDeltaY: -150})
+ scroll.content.x.should.equal -75
+ scroll.content.y.should.equal 0
+
+
describe "wrap", ->
it "should use the wrapped layer as content layer when there are children", ->

0 comments on commit dc847a4

Please sign in to comment.