Skip to content

Commit

Permalink
Merge branch 'Pharo13' of github.com:pharo-spec/Spec into dev-3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanlm committed Oct 15, 2024
2 parents c6b92a5 + fed1607 commit d51b2be
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 162 deletions.
45 changes: 45 additions & 0 deletions src/Spec2-Adapters-Morphic-Tests/SpMorphicListAdapterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,48 @@ Class {
#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;
withWindowDo: [ : w | w resize: (200 @ 400) ].
self
assert: presenter scrollIndex
equals: 1.

presenter scrollToIndex: 50.

self
assert: presenter scrollIndex > 1
description: 'For now we only check if the scroller worked, the CI returns 39 but running the test interactively returns 38 without loading preferences'
]
4 changes: 2 additions & 2 deletions src/Spec2-Adapters-Morphic/SpFontStyle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ SpFontStyle >> calculateFontSize [
aVariable value ifNotNil: [
^ self scaledSize ] ].
self nameVariable isEnvironmentVariable ifTrue: [
^ self nameVariable pointSize * self displayScaleFactor ].
^ self nameVariable pointSize ].
self hasPredefinedFont ifTrue: [
^ self obtainPredefinedFont pointSize * self displayScaleFactor ].
^ self obtainPredefinedFont pointSize ].

^ nil
]
Expand Down
6 changes: 3 additions & 3 deletions src/Spec2-Adapters-Morphic/SpMorphicButtonBarAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Class {
{ #category : 'accessing' }
SpMorphicButtonBarAdapter class >> defaultHeight [

^ 30 scaledByDisplayScaleFactor
^ 30
]

{ #category : 'accessing' }
SpMorphicButtonBarAdapter class >> defaultItemSeparation [

^ (3@0) scaledByDisplayScaleFactor
^ (3@0)
]

{ #category : 'factory' }
Expand All @@ -27,7 +27,7 @@ SpMorphicButtonBarAdapter >> addModelTo: panelMorph [
self model items do: [ :each |
self model focusOrder add: each.
panelMorph addMorph: (each build
width: 100 scaledByDisplayScaleFactor;
width: 100;
hResizing: #rigid;
yourself) ]
]
Expand Down
120 changes: 55 additions & 65 deletions src/Spec2-Adapters-Morphic/SpMorphicSliderAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,90 +9,80 @@ Class {
#tag : 'Base'
}

{ #category : 'widget API' }
SpMorphicSliderAdapter >> absoluteValue [

^ self presenter absoluteValue
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> absoluteValue: aFloat [

^ self presenter absoluteValue: aFloat
]

{ #category : 'factory' }
SpMorphicSliderAdapter >> buildWidget [

| preWidget |
preWidget := PluggableSliderMorph new
model: self;
getValueSelector: #value;
setValueSelector: #value:;
value: self absoluteValue;
getLabelSelector: #label;
max: self max;
min: self min;
quantum: self quantum;
setBalloonText: self help;
vResizing: #spaceFill;
hResizing: #spaceFill;
yourself.
self presenter isHorizontal ifFalse: [
preWidget := TransformationMorph new asFlexOf: preWidget.
preWidget transform withAngle: 90 degreesToRadians negated ].

self presenter whenMinChangedDo: [ :newValue |
preWidget min: newValue ].
self presenter whenMaxChangedDo: [ :newValue |
preWidget max: newValue ].
self presenter whenQuantumChangedDo: [ :newValue |
preWidget quantum: newValue ].
self presenter whenValueChangedDo: [ :newValue |
preWidget value: newValue ].

^ preWidget
| aSliderMorph |
aSliderMorph :=
(PluggableSliderMorph
on: self
getValue: #presenterValue
setValue: #presenterValue:
min: self presenter min
max: self presenter max
quantum: self presenter quantum)
getLabelSelector: #presenterLabel;
setBalloonText: self help;
vResizing: #spaceFill;
hResizing: #spaceFill;
yourself.

self presenter whenMinChangedDo: [ :newValue |
aSliderMorph min: newValue ].
self presenter whenMaxChangedDo: [ :newValue |
aSliderMorph max: newValue ].
self presenter whenQuantumChangedDo: [ :newValue |
aSliderMorph quantum: newValue ].
self presenter whenLabelChangedDo: [ :newLabel |
aSliderMorph label: newLabel ].
self presenter whenAbsoluteValueChangedDo: [ :newValue |
aSliderMorph setValue: newValue ].

^ aSliderMorph
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> label [

{ #category : 'accessing' }
SpMorphicSliderAdapter >> presenterLabel [
^ self presenter label
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> max [
{ #category : 'accessing' }
SpMorphicSliderAdapter >> presenterValue [

^ self presenter max
^ self presenter value
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> min [
{ #category : 'accessing' }
SpMorphicSliderAdapter >> presenterValue: aValue [

^ self presenter min
self presenter value: aValue
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> quantum [
{ #category : 'debug' }
SpMorphicSliderAdapter >> widgetAbsoluteValue [

^ self model quantum
^ widget value asFloat
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> value [
^ self presenter value
{ #category : 'debug' }
SpMorphicSliderAdapter >> widgetLabel [

^ widget label
]

{ #category : 'widget API' }
SpMorphicSliderAdapter >> value: aValue [
{ #category : 'debug' }
SpMorphicSliderAdapter >> widgetValue [

^ widget scaledValue
]

| value |
value := aValue isNumber
ifTrue: [ aValue ]
ifFalse: [
(aValue includes: $/)
ifTrue: [ (NumberParser on: aValue) nextFraction ]
ifFalse: [ aValue asNumber ] ].
{ #category : 'debug' }
SpMorphicSliderAdapter >> widgetValue: aNumber [
"Emulate a change in the widget value, as if there was a scroll.
Note: We intentionally use #setValue: instead of #value: due to a bug in
the widget, that doesn't perform the setValue selector with the new value
when using #value:, and we need it."

^ self presenter value: value asFloat
widget setValue: (self presenter valueToAbsoluteValue: aNumber)
]
2 changes: 1 addition & 1 deletion src/Spec2-Adapters-Morphic/SpStyleVariable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SpStyleVariable >> preferredValueWith: anObject [
{ #category : 'evaluating' }
SpStyleVariable >> scaledValue [

^ self nonscaledValue * self currentWorld displayScaleFactor
^ self nonscaledValue
]

{ #category : 'private' }
Expand Down
39 changes: 0 additions & 39 deletions src/Spec2-Backend-Tests/SpBoxLayoutAdapterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,3 @@ SpBoxLayoutAdapterTest >> testReplaceElementAfterOpen [
replacement adapter widget.
p2 adapter widget }
]

{ #category : 'tests' }
SpBoxLayoutAdapterTest >> testReplaceElementAppliesStyle [
| p1 toReplace p2 replacement |

layout add: (p1 := SpLabelPresenter new).
layout add: (toReplace := SpLabelPresenter new).
layout add: (p2 := SpLabelPresenter new).
self openInstance.

replacement := SpLabelPresenter new.
replacement addStyle: 'code'. "code assigns code fonts"
layout replace: toReplace with: replacement.

self assert: self adapter children size equals: 3.
self
assert: replacement adapter widget font
equals: StandardFonts codeFont
]

{ #category : 'tests' }
SpBoxLayoutAdapterTest >> testReplaceElementBeforeOpenAppliesStyle [
| p1 toReplace p2 replacement |

layout add: (p1 := SpLabelPresenter new).
layout add: (toReplace := SpLabelPresenter new).
layout add: (p2 := SpLabelPresenter new).

replacement := SpLabelPresenter new.
replacement addStyle: 'code'. "code assigns code fonts"
layout replace: toReplace with: replacement.

self openInstance.

self assert: self adapter children size equals: 3.
self
assert: replacement adapter widget font
equals: StandardFonts codeFont
]
Loading

0 comments on commit d51b2be

Please sign in to comment.