Skip to content

Commit

Permalink
Merge pull request #1383 from pharo-spec/dev-1.0
Browse files Browse the repository at this point in the history
last changes
  • Loading branch information
estebanlm authored May 2, 2023
2 parents b4da423 + e15d28d commit a81e42f
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 26 deletions.
7 changes: 6 additions & 1 deletion src/Spec2-Adapters-Morphic/SpMorphicLabelAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ SpMorphicLabelAdapter >> applyDecorationsTo: aString [
SpMorphicLabelAdapter >> applyStyle: aMorph [

aMorph fitContents.
super applyStyle: aMorph
super applyStyle: aMorph.
"when changing a font and affecting his size, it may happen than the result font
height is smaller than current height of morph, we need to take care about this
even if this means we cannot have a label smaller than the font :("
aMorph height < aMorph font height
ifTrue: [ aMorph height: aMorph font height ]
]

{ #category : #factory }
Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-Adapters-Morphic/SpMorphicLayoutAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ SpMorphicLayoutAdapter >> layout: aLayout [
self applyVisibility.
self applyStyle.
self addKeyBindingsTo: self widget.
self addEventsTo: self widget.
self addEventsTo: self widget
]

{ #category : #factory }
Expand Down
23 changes: 18 additions & 5 deletions src/Spec2-Adapters-Morphic/SpMorphicPaginatorAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ Class {

{ #category : #factory }
SpMorphicPaginatorAdapter >> buildWidget [
| morph |
| morph page |

morph := SpPaginatorMorph new
addPages: self presenter pages;
selectPage: self presenter pages size;
yourself.

self presenter whenSelectedPageChangedDo: [ :aNumber |
self backendDetectCyclesDo: [
morph selectPage: aNumber ] ].
morph selectPage: aNumber ] ].
morph whenSelectedPageChangedDo: [ :aNumber |
self backendUpdatingDo: [
self presenter selectPage: aNumber ] ].


morph numberOfPagesShown: self presenter visiblePages.
self presenter whenVisiblePagesChangedDo: [ :aNumber |
self backendDetectCyclesDo: [
morph numberOfPagesShown: aNumber ] ].
morph whenNumberOfPagesShownChangedDo: [ :aNumber |
self backendUpdatingDo: [
self presenter visiblePages: aNumber ] ].

self presenter whenPageAddedDo: [ :anObject |
morph
addPage: anObject;
Expand All @@ -41,6 +41,13 @@ SpMorphicPaginatorAdapter >> buildWidget [
morph selectionMorph whenDraggingDo: [ :delta |
self presenter dragging: (delta * 100 / widget width) ].

"select last because the real selection may change with the visible pages"
page := (self presenter selectedPage
ifNil: [ self presenter pages size ]).
morph selectPage: page.
self backendUpdatingDo: [
self presenter selectPage: page ].

^ morph
]

Expand All @@ -59,3 +66,9 @@ SpMorphicPaginatorAdapter >> scrollByDeltaPercent: percent [
millerDelta := millerWidth * (percent / 100).
self widget scroller offset: (self widget scroller offset x + millerDelta)@0
]

{ #category : #paginator }
SpMorphicPaginatorAdapter >> withoutResizingEdges [

self widgetDo: [ :w | w removeResizingEdges ]
]
24 changes: 18 additions & 6 deletions src/Spec2-Adapters-Morphic/SpPaginatorMorph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ SpPaginatorMorph >> numberOfPagesShown [
SpPaginatorMorph >> numberOfPagesShown: aNumber [

numberOfPagesShown := aNumber.
selectionMorph updateSizePages: numberOfPagesShown pageWidth: self baseWidth
selectionMorph
updateSizePages: numberOfPagesShown
pageWidth: self baseWidth
]

{ #category : #accessing }
Expand All @@ -189,6 +191,12 @@ SpPaginatorMorph >> removePage: anObject [
detect: [ :each | each model = anObject ])
]

{ #category : #accessing }
SpPaginatorMorph >> removeResizingEdges [

selectionMorph removeResizingEdges
]

{ #category : #accessing }
SpPaginatorMorph >> selectLastPage [

Expand All @@ -197,13 +205,17 @@ SpPaginatorMorph >> selectLastPage [

{ #category : #accessing }
SpPaginatorMorph >> selectPage: aNumber [
| effectivePageNumber numPages |

selectedPage = aNumber ifTrue: [ ^ self ].
(aNumber + self numberOfPagesShown - 1 > pagesMorph submorphs size)
ifTrue: [ ^ self selectPage: aNumber - 1 ].

self moveSelectionToPage: aNumber.
self basicSelectPage: aNumber
numPages := pagesMorph submorphs size.

effectivePageNumber := aNumber > (numPages - self numberOfPagesShown)
ifTrue: [ numPages - self numberOfPagesShown + 1 ]
ifFalse: [ aNumber ].

self moveSelectionToPage: effectivePageNumber.
self basicSelectPage: effectivePageNumber
]

{ #category : #accessing }
Expand Down
8 changes: 8 additions & 0 deletions src/Spec2-Adapters-Morphic/SpPaginatorSelectionMorph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ SpPaginatorSelectionMorph >> mouseUp: anEvent [

]

{ #category : #accessing }
SpPaginatorSelectionMorph >> removeResizingEdges [
| edgeMorphs |

edgeMorphs := self submorphs select: [ :each | each class = SpPaginatorEdgeGripMorph ].
self removeAllMorphsIn: edgeMorphs
]

{ #category : #private }
SpPaginatorSelectionMorph >> resetPosition [

Expand Down
4 changes: 3 additions & 1 deletion src/Spec2-Adapters-Morphic/SpStyle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ SpStyle class >> defaultStyleSheetData [
.header [ Draw { #color: Color{ #rgb: 622413393 } } ],
.shortcut [ Draw { #color: Color{ #rgb: 622413393 } } ],
.fixed [ Geometry { #hResizing: false, #width: 100 } ],
.dim [ Draw { #color : Color{ #rgb: 708480675 } } ]
.dim [ Draw { #color : Color{ #rgb: 708480675 } } ],
.title [ Font { #name : EnvironmentFont(#default), #size : 14 } ],
.subtitle [ Font { #name : EnvironmentFont(#default), #size : 12 } ]
],
.notebookLabel [
Geometry { #minWidth: 90 }
Expand Down
38 changes: 38 additions & 0 deletions src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorProxy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"
Environment colors can change if we change the morphic theme, in that case we need to be able to react to `themeChanged` message, which will repaint the morphic components using the new values.
To be able to react this, when declaring the usage of an environment-based color (see `SpStyleEnvironmentColorVariable`), we actually set up a proxy to a color, that will access the real color from the theme when needed.
This is used exclusively in `SpStyleEnvironmentColorVariable>>#value`
"
Class {
#name : #SpStyleEnvironmentColorProxy,
#superclass : #ProtoObject,
#instVars : [
'colorSelector'
],
#category : #'Spec2-Adapters-Morphic-StyleSheet'
}

{ #category : #converting }
SpStyleEnvironmentColorProxy >> asStyleVariable [

^ SpStyleVariable newValue: self
]

{ #category : #accessing }
SpStyleEnvironmentColorProxy >> colorSelector: aSelector [

colorSelector := aSelector
]

{ #category : #'reflective operations' }
SpStyleEnvironmentColorProxy >> doesNotUnderstand: aMessage [

aMessage crTrace.
^ aMessage sendTo: (Smalltalk ui theme perform: colorSelector)
]

{ #category : #accessing }
SpStyleEnvironmentColorProxy >> yourself [
]
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ SpStyleEnvironmentColorVariable class >> stonName [
SpStyleEnvironmentColorVariable >> value [

self name ifNil: [ ^ nil ].
^ Smalltalk ui theme perform: (self name, 'Color') asSymbol
"because they can change when we change the theme"
^ SpStyleEnvironmentColorProxy new
colorSelector: (self name, 'Color') asSymbol;
yourself
]

{ #category : #evaluating }
Expand Down
1 change: 1 addition & 0 deletions src/Spec2-Core/SpAbstractAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ SpAbstractAdapter >> add: aWidget [
{ #category : #initialization }
SpAbstractAdapter >> addEventsTo: aWidget [

aWidget ifNil: [ ^ self ].
self presenter hasEventHandler ifFalse: [ ^ self ].
self presenter eventHandler
installAllEventsTo: self
Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-Core/SpMillerColumnPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Class {
{ #category : #api }
SpMillerColumnPresenter >> addPresenter: newSubPresenter [

newSubPresenter whenActivatedDo: [ :selection |
newSubPresenter whenActivatedDo: [ :selection |
self changeSelection: selection from: newSubPresenter ].
newSubPresenter owner: self.
layout add: newSubPresenter
Expand Down
28 changes: 27 additions & 1 deletion src/Spec2-Core/SpMillerPaginatorPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Class {
#category : #'Spec2-Core-Widgets-Advanced'
}

{ #category : #api }
SpMillerPaginatorPresenter >> addPresenter: aPresenter [

self millerListPresenter addPresenter: aPresenter
]

{ #category : #initialization }
SpMillerPaginatorPresenter >> initializePresenters [

Expand All @@ -23,7 +29,7 @@ SpMillerPaginatorPresenter >> initializePresenters [
yourself)
expand: false;
yourself).

millerList withoutHorizontalScrollBar.
millerList whenColumnsChangedDo: [ :page | self updatePaginator: page ].
self updatePaginator: 1
Expand Down Expand Up @@ -60,6 +66,18 @@ SpMillerPaginatorPresenter >> removeAllFrom: aPresenter [
self updatePaginator: ((millerList pages size - millerList visiblePages + 1) max: 1)
]

{ #category : #api }
SpMillerPaginatorPresenter >> selectPage: aNumber [

self millerListPresenter selectPage: aNumber
]

{ #category : #api }
SpMillerPaginatorPresenter >> spacing: aNumber [

self millerListPresenter spacing: aNumber
]

{ #category : #private }
SpMillerPaginatorPresenter >> updatePaginator: pageSelected [

Expand All @@ -68,6 +86,7 @@ SpMillerPaginatorPresenter >> updatePaginator: pageSelected [
"add a paginator, chained to the miller list"
paginator ifNil: [
paginator := self newPaginator.
paginator visiblePages: millerList visiblePages.
paginatorContainerLayout add: paginator expand: false.
paginator chainTo: millerList ].
paginator pages: millerList pages.
Expand All @@ -77,3 +96,10 @@ SpMillerPaginatorPresenter >> updatePaginator: pageSelected [
paginatorContainerLayout removeAll.
paginator := nil ]
]

{ #category : #api }
SpMillerPaginatorPresenter >> visiblePages: aNumber [

self millerListPresenter visiblePages: 1.
self paginatorPresenter ifNotNil: [ :aPaginator | aPaginator visiblePages: 1 ]
]
32 changes: 23 additions & 9 deletions src/Spec2-Morphic-Examples/SpPaginatorExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,42 @@ Class {
#category : #'Spec2-Morphic-Examples'
}

{ #category : #initialization }
SpPaginatorExample >> initializePresenters [
<script: 'self new openWithSpec'>
{ #category : #layout }
SpPaginatorExample >> defaultLayout [

layout := SpBoxLayout newTopToBottom
^ SpBoxLayout newTopToBottom
spacing: 5;
add: (millerList := self instantiate: SpMillerColumnPresenter);
add: millerList;
add: (SpBoxLayout newLeftToRight
hAlignCenter;
add: (paginator := self instantiate: SpPaginatorPresenter) expand: false;
add: paginator expand: false;
yourself)
expand: false;
yourself.

yourself
]

{ #category : #initialization }
SpPaginatorExample >> initializePresenters [
<script: 'self new open'>

millerList := self instantiate: SpMillerColumnPresenter.
millerList withoutHorizontalScrollBar.

paginator := self instantiate: SpPaginatorPresenter.
paginator chainTo: millerList.
paginator visiblePages: 2
]

{ #category : #initialization }
SpPaginatorExample >> updatePresenter [

1 to: 10 do: [ :index | | presenter |
presenter := SpListPresenter new
items: (1 to: index);
yourself.
millerList addPresenter: presenter.
paginator addPage: presenter ]
paginator addPage: presenter ].

paginator selectPage: 1.
millerList selectPage: 1
]
19 changes: 19 additions & 0 deletions src/Spec2-Morphic/SpPaginatorPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ SpPaginatorPresenter class >> adapterName [
^ #PaginatorAdapter
]

{ #category : #defaults }
SpPaginatorPresenter class >> defaultVisiblePages [

^ 2
]

{ #category : #documentation }
SpPaginatorPresenter class >> documentExamplesProtocol [

Expand Down Expand Up @@ -59,6 +65,7 @@ SpPaginatorPresenter >> initialize [

super initialize.
pagesHolder := OrderedCollection new asValueHolder.
visiblePages := self class defaultVisiblePages
]

{ #category : #api }
Expand All @@ -83,6 +90,12 @@ SpPaginatorPresenter >> selectPage: aNumber [
selectedPage := aNumber
]

{ #category : #accessing }
SpPaginatorPresenter >> selectedPage [

^ selectedPage
]

{ #category : #api }
SpPaginatorPresenter >> visiblePages [
"Answer the paginator visible pages (visible pages are the pages marked as selected)."
Expand Down Expand Up @@ -145,3 +158,9 @@ SpPaginatorPresenter >> whenVisiblePagesChangedDo: aBlock [

self property: #visiblePages whenChangedDo: aBlock
]

{ #category : #api }
SpPaginatorPresenter >> withoutResizingEdges [

self withAdapterPerformOrDefer: [ :anAdapter | anAdapter withoutResizingEdges ]
]

0 comments on commit a81e42f

Please sign in to comment.