Skip to content

Commit

Permalink
Let mouseWheel events obey scrollHorizontal and scrollVertical
Browse files Browse the repository at this point in the history
Fixes #288
  • Loading branch information
nvh committed Aug 2, 2016
1 parent 2a84e68 commit dc847a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
14 changes: 12 additions & 2 deletions framer/Components/ScrollComponent.coffee
Expand Up @@ -357,6 +357,15 @@ class exports.ScrollComponent extends Layer
@off(Events.MouseWheel, @_onMouseWheel) @off(Events.MouseWheel, @_onMouseWheel)


_onMouseWheel: (event) => _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 if not @_mouseWheelScrolling
@_mouseWheelScrolling = true @_mouseWheelScrolling = true
Expand All @@ -367,9 +376,10 @@ class exports.ScrollComponent extends Layer
{minX, maxX, minY, maxY} = @content.draggable._calculateConstraints( {minX, maxX, minY, maxY} = @content.draggable._calculateConstraints(
@content.draggable.constraints) @content.draggable.constraints)



point = point =
x: Utils.clamp(@content.x + (event.wheelDeltaX * @mouseWheelSpeedMultiplier), minX, maxX) x: Utils.clamp(@content.x + (deltaX * @mouseWheelSpeedMultiplier), minX, maxX)
y: Utils.clamp(@content.y + (event.wheelDeltaY * @mouseWheelSpeedMultiplier), minY, maxY) y: Utils.clamp(@content.y + (deltaY * @mouseWheelSpeedMultiplier), minY, maxY)


@content.point = point @content.point = point


Expand Down
37 changes: 37 additions & 0 deletions test/tests/ScrollComponentTest.coffee
Expand Up @@ -35,6 +35,43 @@ describe "ScrollComponent", ->
copy = instance.copy() copy = instance.copy()
copy.scrollHorizontal.should.be.false 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", -> describe "wrap", ->


it "should use the wrapped layer as content layer when there are children", -> it "should use the wrapped layer as content layer when there are children", ->
Expand Down

0 comments on commit dc847a4

Please sign in to comment.