Skip to content

Commit

Permalink
ToScrollableBarElement: use of smoothScrollBy:
Browse files Browse the repository at this point in the history
  • Loading branch information
plantec committed May 22, 2024
1 parent 713d475 commit ab077af
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2728,8 +2728,9 @@ ToSandBox class >> example_nodeBar [
bar vFitContent.

barPane addChild: bar.
bar dataAccessor addAll:
(ToSandBox statesOfAmerica copyFrom: 1 to: 6).
"bar dataAccessor addAll:
(ToSandBox statesOfAmerica ""copyFrom: 1 to: 20"")."
bar dataAccessor addAll: ((Smalltalk globals allClasses) copyFrom: 1 to: 500).

verticalSwitch := ToSwitchButton new labelText: 'Vertical'.
verticalSwitch endToStart: true.
Expand Down
8 changes: 7 additions & 1 deletion src/Toplo-Widget-List/ToInnerBarElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ ToInnerBarElement >> defaultDataSourceObserver [
]

{ #category : #initialization }
ToInnerBarElement >> initialize [
ToInnerBarElement >> initialize [

super initialize.
self initializeDataSource.
self id: #innerElement.
scrollable := ToScrollableBarElement new.
scrollable id: #scrollable.
self middleElement: scrollable.
scrollable
addEventHandlerOn: BlElementScrolledEvent
do: [ :event | self dispatchEvent: event copy ].
scrollable
addEventHandlerOn: ToInfiniteScrollFinishedEvent
do: [ :event | self dispatchEvent: event copy ].
self addEventHandler: ToInfiniteElementEventHandler new.

self matchParent
Expand Down
75 changes: 75 additions & 0 deletions src/Toplo-Widget-List/ToScrollableBarElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ ToScrollableBarElement >> configureLayoutIn: aListElement [
self nodesDo: [ :n | n autoDistribute: self isNodeAutoDistribution ] ]
]

{ #category : #'private - commands' }
ToScrollableBarElement >> consumePendingDataSourceCommands [
]

{ #category : #initialization }
ToScrollableBarElement >> defaultEventHandler [

^ ToScrollableElementEventHandler new
]

{ #category : #initialization }
ToScrollableBarElement >> defaultScrollFlinger [

"Return class, actuall instantiation happens in initialize"
^ ToInfiniteScrollFlinger
]

{ #category : #initialization }
ToScrollableBarElement >> initialize [

Expand Down Expand Up @@ -153,6 +170,20 @@ ToScrollableBarElement >> nodesWithIndexDo: aBlock [
aBlock value: node value: node holder position ]
]

{ #category : #'hooks - layout' }
ToScrollableBarElement >> onEnterLayoutOrScroll [
]

{ #category : #'children add/remove' }
ToScrollableBarElement >> onExitLayoutOrScroll [
]

{ #category : #'children add/remove' }
ToScrollableBarElement >> prefetchingAllowed [

^ false
]

{ #category : #'accessing - children' }
ToScrollableBarElement >> removeAllNodes: anArray [

Expand All @@ -166,3 +197,47 @@ ToScrollableBarElement >> removeNode: aNode [
release;
removeFromParent
]

{ #category : #'children add/remove' }
ToScrollableBarElement >> repositionShadowingElements [
]

{ #category : #scrolling }
ToScrollableBarElement >> smoothScrollBy: aPoint [
"Animate a scroll by the given amount of pixels along either axis"
| dX dY aContent |

self hasScrolledElement
ifFalse: [ ^ self ].

aContent := self scrolledElement.

dX := aPoint x.
dY := aPoint y negated.

self canScrollHorizontally
ifTrue: [
| aNewPosition aMinPosition aMaxPosition aNewClampedPosition |

aNewPosition := self scrollPosition x + dX.
aMinPosition := (self width - aContent width) min: 0.0.
aMaxPosition := 0.0.
aNewClampedPosition := (aNewPosition max: aMinPosition) min: aMaxPosition.

dX := aNewClampedPosition - self scrollPosition x ]
ifFalse: [ dX := 0.0 ].

self canScrollVertically
ifTrue: [
| aNewPosition aMinPosition aMaxPosition aNewClampedPosition |

aNewPosition := self scrollPosition y + dY.
aMinPosition := (self height - aContent height) min: 0.0.
aMaxPosition := 0.0.
aNewClampedPosition := (aNewPosition max: aMinPosition) min: aMaxPosition.
dY := aNewClampedPosition - self scrollPosition y ]
ifFalse: [ dY := 0.0 ].

(dX isZero and: [ dY isZero ])
ifFalse: [ scrollFlinger smoothScrollBy: dX @ dY]
]
16 changes: 16 additions & 0 deletions src/Toplo-Widget-List/ToScrollableElementEventHandler.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Class {
#name : #ToScrollableElementEventHandler,
#superclass : #BlEventListener,
#category : #'Toplo-Widget-List-InnerBar'
}

{ #category : #'mouse handlers' }
ToScrollableElementEventHandler >> mouseWheelEvent: anEvent [

"I implement touch support, so ignore fake mouse wheel events"
anEvent isTouch
ifTrue: [ ^ self ].

anEvent currentTarget smoothScrollBy: (anEvent vector * BlInfiniteMouseScrollListener scrollingVelocity ) negated.
anEvent consume
]

0 comments on commit ab077af

Please sign in to comment.