Skip to content

Commit

Permalink
Merge pull request #768 from pharo-spec/fix-grid-layout-tests
Browse files Browse the repository at this point in the history
fix-grid-layout-tests
  • Loading branch information
estebanlm committed Sep 10, 2019
2 parents 5f7d07c + 55ce0c8 commit 019eedb
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 60 deletions.
12 changes: 7 additions & 5 deletions src/Spec2-Adapters-Morphic/SpMorphicGridLayout.class.st
Expand Up @@ -55,20 +55,22 @@ SpMorphicGridLayout >> calculateExtentFor: aMorph constraint: constraint computa
{ #category : #private }
SpMorphicGridLayout >> calculateHeightFor: aMorph base: aNumber [

self isRowHomogeneous ifTrue: [ ^ aNumber ].
"self isRowHomogeneous ifTrue: [ ^ aNumber ].
aMorph vResizing = #spaceFill ifTrue: [ ^ aNumber ].
^ aMorph height
^ aMorph height"
^ aNumber
]

{ #category : #private }
SpMorphicGridLayout >> calculateWidthFor: aMorph base: aNumber [

self isColumnHomogeneous ifTrue: [ ^ aNumber ].
"self isColumnHomogeneous ifTrue: [ ^ aNumber ].
aMorph hResizing = #spaceFill ifTrue: [ ^ aNumber ].
^ aMorph width
^ aMorph width"
^ aNumber
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
SpMorphicGridLayout >> columnConstraintsAt: aNumber [

^ layout columnConstraintsAt: aNumber
Expand Down
35 changes: 27 additions & 8 deletions src/Spec2-Adapters-Morphic/SpMorphicGridLayoutComputation.class.st
Expand Up @@ -79,7 +79,7 @@ SpMorphicGridLayoutComputation >> calculateHomogeneousColumnWidths [

columnWidth := 0.
morphs do: [ :each |
columnWidth := columnWidth max: (self styleOf: each) width ].
columnWidth := columnWidth max: (self minWidthOf: each) ].

^ Array new: numColumns withAll: (self baseColumnWidth max: columnWidth)
]
Expand All @@ -95,7 +95,7 @@ SpMorphicGridLayoutComputation >> calculateHomogeneousRowHeights [

rowHeight := 0.
morphs do: [ :each |
rowHeight := rowHeight max: (self styleOf: each) height ].
rowHeight := rowHeight max: (self minHeightOf: each) ].

^ Array new: numRows withAll: (self baseRowHeight max: rowHeight)
]
Expand All @@ -113,7 +113,7 @@ SpMorphicGridLayoutComputation >> calculateNotHomogeneousColumnWidths [
"Assign non expandable values"
morphs do: [ :each | | column |
column := (each valueOfProperty: #gridConstraints) column.
(self isColumnExpandable: column) ifTrue: [
(self isColumnExpandable: column) ifFalse: [
newColumnWidths
at: column
put: ((newColumnWidths at: column) max: ((self styleOf: each) width)) ] ].
Expand All @@ -135,12 +135,11 @@ SpMorphicGridLayoutComputation >> calculateNotHomogeneousColumnWidths [
]

{ #category : #'private computation' }
SpMorphicGridLayoutComputation >> calculateRowHeights [
SpMorphicGridLayoutComputation >> calculateNotHomogeneousRowHeights [
"column heights are
- the max height of cells of that row"
| newRowHeights |

layout isRowHomogeneous
ifTrue: [ ^ self calculateHomogeneousRowHeights ].


newRowHeights := Array new: numRows withAll: 0.
morphs do: [ :each | | row |
row := (each valueOfProperty: #gridConstraints) row.
Expand All @@ -151,6 +150,14 @@ SpMorphicGridLayoutComputation >> calculateRowHeights [
^ newRowHeights
]

{ #category : #'private computation' }
SpMorphicGridLayoutComputation >> calculateRowHeights [

^ layout isRowHomogeneous
ifTrue: [ self calculateHomogeneousRowHeights ]
ifFalse: [ self calculateNotHomogeneousRowHeights ]
]

{ #category : #accessing }
SpMorphicGridLayoutComputation >> cellExtentAt: aPoint [

Expand Down Expand Up @@ -290,6 +297,18 @@ SpMorphicGridLayoutComputation >> maxWidthOf: aCollection [
^ (aCollection collect: [ :each | (each valueOfProperty: #style) width ]) max
]

{ #category : #'private computation' }
SpMorphicGridLayoutComputation >> minHeightOf: aMorph [

^ (self styleOf: aMorph) minHeight ifNil: [ 0 ]
]

{ #category : #'private computation' }
SpMorphicGridLayoutComputation >> minWidthOf: aMorph [

^ (self styleOf: aMorph) minWidth ifNil: [ 0 ]
]

{ #category : #private }
SpMorphicGridLayoutComputation >> numColumns [

Expand Down
36 changes: 36 additions & 0 deletions src/Spec2-Adapters-Morphic/SpStyleGeometry.class.st
Expand Up @@ -107,18 +107,36 @@ SpStyleGeometry >> maxExtent: anObject [
maxExtent := anObject
]

{ #category : #private }
SpStyleGeometry >> maxExtentOrDefault [

^ maxExtent ifNil: [ 0@0 ]
]

{ #category : #accessing }
SpStyleGeometry >> maxHeight [

^ self maxExtent ifNotNil: [ :aPoint | aPoint y ]
]

{ #category : #accessing }
SpStyleGeometry >> maxHeight: aNumber [

self maxExtent: (self maxExtentOrDefault x@aNumber)
]

{ #category : #accessing }
SpStyleGeometry >> maxWidth [

^ self maxExtent ifNotNil: [ :aPoint | aPoint x ]
]

{ #category : #accessing }
SpStyleGeometry >> maxWidth: aNumber [

self maxExtent: (aNumber @ self maxExtentOrDefault y)
]

{ #category : #accessing }
SpStyleGeometry >> minExtent [
^ minExtent
Expand All @@ -129,18 +147,36 @@ SpStyleGeometry >> minExtent: anObject [
minExtent := anObject
]

{ #category : #private }
SpStyleGeometry >> minExtentOrDefault [

^ minExtent ifNil: [ 0@0 ]
]

{ #category : #accessing }
SpStyleGeometry >> minHeight [

^ self minExtent ifNotNil: [ :aPoint | aPoint y ]
]

{ #category : #accessing }
SpStyleGeometry >> minHeight: aNumber [

self minExtent: (self minExtentOrDefault x@aNumber)
]

{ #category : #accessing }
SpStyleGeometry >> minWidth [

^ self minExtent ifNotNil: [ :aPoint | aPoint x ]
]

{ #category : #accessing }
SpStyleGeometry >> minWidth: aNumber [

self minExtent: (aNumber @ self minExtentOrDefault y)
]

{ #category : #private }
SpStyleGeometry >> resizingStringFor: expand [

Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-Core/SpPresenter.class.st
Expand Up @@ -489,7 +489,7 @@ SpPresenter >> giveFocusToPreviousFrom: aModel [
{ #category : #'api-focus' }
SpPresenter >> gtInspectorPreviewIn: composite [
<gtInspectorPresentationOrder: 30>
self widget ifNotNil: [ :w | w gtInspectorPreviewIn: composite ]
self adapter ifNotNil: [ :w | w gtInspectorPreviewIn: composite ]
]

{ #category : #'api-focus' }
Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-Examples/SpInputTextDropList.extension.st
@@ -1,7 +1,7 @@
Extension { #name : #SpInputTextDropList }

{ #category : #'*Spec2-Examples' }
SpInputTextDropList class >> example [
SpInputTextDropList classSide >> example [
<sampleInstance>
| example |
example := self new
Expand Down
96 changes: 71 additions & 25 deletions src/Spec2-Morphic-Backend-Tests/SpMorphicGridLayoutTest.class.st
Expand Up @@ -76,6 +76,17 @@ SpMorphicGridLayoutTest >> styleExtent: aPoint [
^ SpMorphStyle newStyles: rootStyle flattenClasses
]

{ #category : #private }
SpMorphicGridLayoutTest >> styleMinExtent: aPoint [
| rootStyle |

rootStyle := (SpStyleSTONReader fromString: ('
.application [ Geometry \{ #minWidth: {1}, #minHeight: {2} \} ]'
format: { aPoint x. aPoint y })).

^ SpMorphStyle newStyles: rootStyle flattenClasses
]

{ #category : #tests }
SpMorphicGridLayoutTest >> testBasicLayout [
"
Expand All @@ -102,15 +113,47 @@ SpMorphicGridLayoutTest >> testBasicLayout [
]

{ #category : #tests }
SpMorphicGridLayoutTest >> testBorderWidth [
SpMorphicGridLayoutTest >> testBorderWidthHomogeneous [
"
---------------
+---+----+----+---+
| 5 | 5 | 5 | 5 |
+---+----+----+---+
| 5 | 45 | 45 | 5 |
+---+----+----+---+
| 5 | 45 | 45 | 5 |
+---+----+----+---+
| 5 | 5 | 5 | 5 |
+---+----+----+---+
"
| layout |

self place: label1 at: 1@1.
self place: morph1 at: 2@1.
self place: label2 at: 1@2.
self place: morph2 at: 2@2.

(layout := self newLayout) layout
beColumnHomogeneous;
beRowHomogeneous;
borderWidth: 5.
layout layout: panel in: (0@0 corner: 100@100).

self assert: label1 bounds equals: (5@5 corner: 50@50).
self assert: morph1 bounds equals: (50@5 corner: 95@50).
self assert: label2 bounds equals: (5@50 corner: 50@95).
self assert: morph2 bounds equals: (50@50 corner: 95@95)
]

{ #category : #tests }
SpMorphicGridLayoutTest >> testBorderWidthNotHomogeneous [
"
+---+----+----+
| 5 | 5 | 5 |
---------------
| 5 | 50 | 50 |
---------------
+---+----+----+
| 5 | 50 | 50 |
---------------
+---+----+----+
| 5 | 50 | 50 |
+---+----+----+
"
| layout |

Expand All @@ -119,7 +162,10 @@ SpMorphicGridLayoutTest >> testBorderWidth [
self place: label2 at: 1@2.
self place: morph2 at: 2@2.

(layout := self newLayout) layout borderWidth: 5.
(layout := self newLayout) layout
beRowNotHomogeneous;
beColumnNotHomogeneous;
borderWidth: 5.
layout layout: panel in: (0@0 corner: 100@100).

self assert: label1 bounds equals: (5@5 corner: 55@25).
Expand Down Expand Up @@ -150,9 +196,9 @@ SpMorphicGridLayoutTest >> testColumnHomogeneousDiferentRowsAndColumns [
self place: morph2 at: 4@4.

layout := self newLayout.
layout layout columnHomogeneous: true.
"make one column width to 100 (it should force all columns to 100, instead 50)"
(self styleExtent: 100@20) applyTo: label2.
layout layout beColumnHomogeneous.
"make one column width to 100 (it should force all columns to 100, instead 25)"
(self styleMinExtent: 100@20) applyTo: label2.

layout layout: panel in: (0@0 corner: 100@100).

Expand Down Expand Up @@ -185,12 +231,12 @@ SpMorphicGridLayoutTest >> testColumnNotHomogeneousDiferentRowsAndColumns [
self place: morph2 at: 4@4.

layout := self newLayout.
layout layout columnHomogeneous: false.
layout layout beColumnNotHomogeneous.
"make columns differ, to make each column different"
label1 width: 30.
morph1 width: 40.
label2 width: 50.
morph2 width: 60.
(self styleExtent: 30@20) applyTo: label1.
(self styleExtent: 40@20) applyTo: morph1.
(self styleExtent: 50@20) applyTo: label2.
(self styleExtent: 60@20) applyTo: morph2.

layout layout: panel in: (0@0 corner: 100@100).

Expand All @@ -203,7 +249,7 @@ SpMorphicGridLayoutTest >> testColumnNotHomogeneousDiferentRowsAndColumns [

{ #category : #tests }
SpMorphicGridLayoutTest >> testColumnNotHomogeneousPairedRowsAndColumns [
"Paired elements in a rows and columns
"Paired elements in rows and columns
-----------
| 50 | 60 |
Expand All @@ -220,19 +266,19 @@ SpMorphicGridLayoutTest >> testColumnNotHomogeneousPairedRowsAndColumns [
self place: morph2 at: 2@2.

layout := self newLayout.
layout layout columnHomogeneous: false.
layout layout beColumnNotHomogeneous.
"make columns differ, to make each column different"
label1 width: 30.
morph1 width: 40.
label2 width: 50.
morph2 width: 60.
(self styleExtent: 30@20) applyTo: label1.
(self styleExtent: 50@20) applyTo: morph1.
(self styleExtent: 40@20) applyTo: label2.
(self styleExtent: 60@20) applyTo: morph2.

layout layout: panel in: (0@0 corner: 100@100).

self assert: label1 bounds equals: (0@0 corner: 50@20).
self assert: morph1 bounds equals: (50@0 corner: 110@20).
self assert: label2 bounds equals: (0@20 corner: 50@40).
self assert: morph2 bounds equals: (50@20 corner: 110@40)
self assert: label1 bounds equals: (0@0 corner: 40@20).
self assert: morph1 bounds equals: (40@0 corner: 100@20).
self assert: label2 bounds equals: (0@20 corner: 40@40).
self assert: morph2 bounds equals: (40@20 corner: 100@40)

]

Expand Down

0 comments on commit 019eedb

Please sign in to comment.