diff --git a/src/Spec2-Adapters-Morphic/SpMorphicLabelAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicLabelAdapter.class.st index c870ca720..efb109951 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicLabelAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicLabelAdapter.class.st @@ -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 } diff --git a/src/Spec2-Adapters-Morphic/SpMorphicLayoutAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicLayoutAdapter.class.st index b174de07d..f3bb3e14c 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicLayoutAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicLayoutAdapter.class.st @@ -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 } diff --git a/src/Spec2-Adapters-Morphic/SpMorphicPaginatorAdapter.class.st b/src/Spec2-Adapters-Morphic/SpMorphicPaginatorAdapter.class.st index 3e43daf69..cca08ad3f 100644 --- a/src/Spec2-Adapters-Morphic/SpMorphicPaginatorAdapter.class.st +++ b/src/Spec2-Adapters-Morphic/SpMorphicPaginatorAdapter.class.st @@ -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; @@ -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 ] @@ -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 ] +] diff --git a/src/Spec2-Adapters-Morphic/SpPaginatorMorph.class.st b/src/Spec2-Adapters-Morphic/SpPaginatorMorph.class.st index ba8f951bb..0497d9b88 100644 --- a/src/Spec2-Adapters-Morphic/SpPaginatorMorph.class.st +++ b/src/Spec2-Adapters-Morphic/SpPaginatorMorph.class.st @@ -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 } @@ -189,6 +191,12 @@ SpPaginatorMorph >> removePage: anObject [ detect: [ :each | each model = anObject ]) ] +{ #category : #accessing } +SpPaginatorMorph >> removeResizingEdges [ + + selectionMorph removeResizingEdges +] + { #category : #accessing } SpPaginatorMorph >> selectLastPage [ @@ -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 } diff --git a/src/Spec2-Adapters-Morphic/SpPaginatorSelectionMorph.class.st b/src/Spec2-Adapters-Morphic/SpPaginatorSelectionMorph.class.st index 51e65569d..b77f447c4 100644 --- a/src/Spec2-Adapters-Morphic/SpPaginatorSelectionMorph.class.st +++ b/src/Spec2-Adapters-Morphic/SpPaginatorSelectionMorph.class.st @@ -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 [ diff --git a/src/Spec2-Adapters-Morphic/SpStyle.class.st b/src/Spec2-Adapters-Morphic/SpStyle.class.st index 93c8be2be..3ddc6c738 100644 --- a/src/Spec2-Adapters-Morphic/SpStyle.class.st +++ b/src/Spec2-Adapters-Morphic/SpStyle.class.st @@ -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 } diff --git a/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorProxy.class.st b/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorProxy.class.st new file mode 100644 index 000000000..56ac2710b --- /dev/null +++ b/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorProxy.class.st @@ -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 [ +] diff --git a/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorVariable.class.st b/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorVariable.class.st index b115b8eb3..a580a0eb2 100644 --- a/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorVariable.class.st +++ b/src/Spec2-Adapters-Morphic/SpStyleEnvironmentColorVariable.class.st @@ -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 } diff --git a/src/Spec2-Core/SpAbstractAdapter.class.st b/src/Spec2-Core/SpAbstractAdapter.class.st index 9ad0433c0..bb7b27cb3 100644 --- a/src/Spec2-Core/SpAbstractAdapter.class.st +++ b/src/Spec2-Core/SpAbstractAdapter.class.st @@ -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 diff --git a/src/Spec2-Core/SpMillerColumnPresenter.class.st b/src/Spec2-Core/SpMillerColumnPresenter.class.st index 1d26a9e1d..dd7fa2c57 100644 --- a/src/Spec2-Core/SpMillerColumnPresenter.class.st +++ b/src/Spec2-Core/SpMillerColumnPresenter.class.st @@ -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 diff --git a/src/Spec2-Core/SpMillerPaginatorPresenter.class.st b/src/Spec2-Core/SpMillerPaginatorPresenter.class.st index 4b440dea0..741da7faa 100644 --- a/src/Spec2-Core/SpMillerPaginatorPresenter.class.st +++ b/src/Spec2-Core/SpMillerPaginatorPresenter.class.st @@ -13,6 +13,12 @@ Class { #category : #'Spec2-Core-Widgets-Advanced' } +{ #category : #api } +SpMillerPaginatorPresenter >> addPresenter: aPresenter [ + + self millerListPresenter addPresenter: aPresenter +] + { #category : #initialization } SpMillerPaginatorPresenter >> initializePresenters [ @@ -23,7 +29,7 @@ SpMillerPaginatorPresenter >> initializePresenters [ yourself) expand: false; yourself). - + millerList withoutHorizontalScrollBar. millerList whenColumnsChangedDo: [ :page | self updatePaginator: page ]. self updatePaginator: 1 @@ -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 [ @@ -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. @@ -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 ] +] diff --git a/src/Spec2-Morphic-Examples/SpPaginatorExample.class.st b/src/Spec2-Morphic-Examples/SpPaginatorExample.class.st index 704812208..c678b5beb 100644 --- a/src/Spec2-Morphic-Examples/SpPaginatorExample.class.st +++ b/src/Spec2-Morphic-Examples/SpPaginatorExample.class.st @@ -8,28 +8,42 @@ Class { #category : #'Spec2-Morphic-Examples' } -{ #category : #initialization } -SpPaginatorExample >> initializePresenters [ - +{ #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 [ + + + 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 ] diff --git a/src/Spec2-Morphic/SpPaginatorPresenter.class.st b/src/Spec2-Morphic/SpPaginatorPresenter.class.st index b78c107b7..ce6477fc0 100644 --- a/src/Spec2-Morphic/SpPaginatorPresenter.class.st +++ b/src/Spec2-Morphic/SpPaginatorPresenter.class.st @@ -20,6 +20,12 @@ SpPaginatorPresenter class >> adapterName [ ^ #PaginatorAdapter ] +{ #category : #defaults } +SpPaginatorPresenter class >> defaultVisiblePages [ + + ^ 2 +] + { #category : #documentation } SpPaginatorPresenter class >> documentExamplesProtocol [ @@ -59,6 +65,7 @@ SpPaginatorPresenter >> initialize [ super initialize. pagesHolder := OrderedCollection new asValueHolder. + visiblePages := self class defaultVisiblePages ] { #category : #api } @@ -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)." @@ -145,3 +158,9 @@ SpPaginatorPresenter >> whenVisiblePagesChangedDo: aBlock [ self property: #visiblePages whenChangedDo: aBlock ] + +{ #category : #api } +SpPaginatorPresenter >> withoutResizingEdges [ + + self withAdapterPerformOrDefer: [ :anAdapter | anAdapter withoutResizingEdges ] +]