Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scroll to index to Lists #1586

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/Spec2-Adapters-Morphic-Tests/SpMorphicListAdapterTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Class {
#name : 'SpMorphicListAdapterTest',
#superclass : 'TestCase',
#instVars : [
'presenter'
],
#category : 'Spec2-Adapters-Morphic-Tests',
#package : 'Spec2-Adapters-Morphic-Tests'
}

{ #category : 'private' }
SpMorphicListAdapterTest >> configureList: aNumber [

presenter := SpListPresenter new
items: (1 to: aNumber);
yourself.

]

{ #category : 'running' }
SpMorphicListAdapterTest >> tearDown [

presenter delete.
super tearDown.
]

{ #category : 'tests' }
SpMorphicListAdapterTest >> testScrollToIndexInvisibleScrollbars [

self configureList: 5.
presenter open.
presenter scrollToIndex: 100.
self
assert: presenter scrollIndex
equals: 1.
]

{ #category : 'tests' }
SpMorphicListAdapterTest >> testScrollToIndexVisibleScrollbars [

self configureList: 100.
presenter open.
self
assert: presenter scrollIndex
equals: 1.

presenter scrollToIndex: 50.

self
assert: presenter scrollIndex
equals: 39.

presenter scrollToIndex: 100.

self
assert: presenter scrollIndex
equals: 89.
]
9 changes: 9 additions & 0 deletions src/Spec2-Core/SpAbstractListPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ SpAbstractListPresenter >> doubleClickAtIndex: anIndex [
self doActivateAtIndex: anIndex
]

{ #category : 'api' }
SpAbstractListPresenter >> indexOf: anItem ifAbsent: aBlock [
"Answer the index of the first occurrence of anElement within the receiver. If the receiver does not contain anElement, answer the result of evaluating the argument, exceptionBlock."

^ self model
indexOf: anItem
ifAbsent: aBlock
]

{ #category : 'initialization' }
SpAbstractListPresenter >> initialize [

Expand Down
14 changes: 14 additions & 0 deletions src/Spec2-Core/SpListPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ SpListPresenter >> resetListSelection [
self selectIndex: 0
]

{ #category : 'scrolling' }
SpListPresenter >> scrollIndex [
"Answer a <Number> representing the receiver's element scroll index"

^ self adapter widget showIndex.
]

{ #category : 'scrolling' }
SpListPresenter >> scrollToIndex: anIndex [
"Scroll the receiver to the element whose index is anIndex."

self adapter widget scrollToIndex: anIndex
]

{ #category : 'api' }
SpListPresenter >> updateList [
"Update the list re taking the list defined in `SpAbstractListPresenter>>#model` and filling the list with
Expand Down
Loading