Skip to content
Permalink
Browse files

Merge pull request #769 from pharo-spec/fix-grid-layout-tests

fix padding in box layout
  • Loading branch information...
estebanlm committed Sep 11, 2019
2 parents 748bc59 + a03fa0c commit 85719bcd016f58273fbbad778293762c15c4b1e3
@@ -1,5 +1,11 @@
Extension { #name : #SpLayoutDirection }

{ #category : #'*Spec2-Adapters-Morphic' }
SpLayoutDirection >> addPadding: aNumber toMorph: aMorph into: anAdapter [

^ self subclassResponsibility
]

{ #category : #'*Spec2-Adapters-Morphic' }
SpLayoutDirection >> newSplitter [
^ self subclassResponsibility
@@ -1,5 +1,13 @@
Extension { #name : #SpLayoutDirectionHorizontal }

{ #category : #'*Spec2-Adapters-Morphic' }
SpLayoutDirectionHorizontal >> addPadding: aNumber toMorph: aMorph into: anAdapter [

^ anAdapter
addHorizontalPadding: aNumber
toMorph: aMorph
]

{ #category : #'*Spec2-Adapters-Morphic' }
SpLayoutDirectionHorizontal >> newSplitter [
^ SpPanedResizerMorph newHorizontal
@@ -1,5 +1,13 @@
Extension { #name : #SpLayoutDirectionVertical }

{ #category : #'*Spec2-Adapters-Morphic' }
SpLayoutDirectionVertical >> addPadding: aNumber toMorph: aMorph into: anAdapter [

^ anAdapter
addVerticalPadding: aNumber
toMorph: aMorph
]

{ #category : #'*Spec2-Adapters-Morphic' }
SpLayoutDirectionVertical >> newSplitter [
^ SpPanedResizerMorph newVertical
@@ -22,7 +22,7 @@ SpMorphicBoxAdapter >> addConstraits: constraints toChild: childMorph [
"adds constraits by child"
| theMorph |

theMorph := childMorph.
theMorph := self addPadding: constraints padding toMorph: childMorph.
constraints isExpand
ifTrue: [
"if is not 'fill', in fact I need to pad it with another (since it 'expands',
@@ -43,11 +43,57 @@ SpMorphicBoxAdapter >> addConstraits: constraints toChild: childMorph [
layout direction setRigidityOfNonExpendedMorph: theMorph.
constraints width ifNotNil: [ :w | theMorph width: w ].
constraints height ifNotNil: [ :h | theMorph height: h ] ].
"constraints padding"

^ theMorph
]

{ #category : #private }
SpMorphicBoxAdapter >> addHorizontalPadding: aNumber toMorph: aMorph [

^ self newWrapMorph
hResizing: aMorph hResizing;
vResizing: aMorph vResizing;
width: aMorph width + (aNumber * 2);
height: aMorph height;
addMorph: (aMorph
hResizing: #spaceFill;
vResizing: #spaceFill;
yourself)
fullFrame: (LayoutFrame identity
leftOffset: aNumber;
rightOffset: aNumber negated);
yourself
]

{ #category : #private }
SpMorphicBoxAdapter >> addPadding: aNumber toMorph: aMorph [

aNumber = 0 ifTrue: [ ^ aMorph ].

^ layout direction
addPadding: aNumber
toMorph: aMorph
into: self
]

{ #category : #private }
SpMorphicBoxAdapter >> addVerticalPadding: aNumber toMorph: aMorph [

^ self newWrapMorph
hResizing: aMorph hResizing;
vResizing: aMorph vResizing;
width: aMorph width;
height: aMorph height + (aNumber * 2);
addMorph: (aMorph
hResizing: #spaceFill;
vResizing: #spaceFill;
yourself)
fullFrame: (LayoutFrame identity
topOffset: aNumber;
bottomOffset: aNumber negated);
yourself
]

{ #category : #private }
SpMorphicBoxAdapter >> basicAdd: aPresenter constraints: constraints to: aPanel [
| childMorph |
@@ -127,17 +173,48 @@ SpMorphicBoxAdapter >> newVertical [
yourself
]

{ #category : #private }
SpMorphicBoxAdapter >> newWrapMorph [

^ Morph new
layoutPolicy: ProportionalLayout new;
color: Color transparent;
borderColor: Color transparent
yourself
]

{ #category : #accessing }
SpMorphicBoxAdapter >> remove: aPresenter [

| morph |

morph := aPresenter adapter widget.
widget submorphs first removeMorph: morph.
widget submorphs second removeMorph: morph.
]

{ #category : #factory }
SpMorphicBoxAdapter >> removeSubWidgets [

widget submorphs first removeAllMorphs.
widget submorphs second removeAllMorphs
]

{ #category : #private }
SpMorphicBoxAdapter >> wrapMorphIfNeeded: aMorph padding: aNumber [

aNumber = 0 ifTrue: [ ^ aMorph ].
^ Morph new
layoutPolicy: TableLayout new;
color: Color transparent;
borderColor: Color transparent;
borderWidth: aNumber;
hResizing: aMorph hResizing;
vResizing: aMorph vResizing;
width: aMorph width + (aNumber * 2);
height: aMorph height + (aNumber * 2);
addMorph: (aMorph
hResizing: #spaceFill;
vResizing: #spaceFill;
yourself);
yourself
]
@@ -12,19 +12,19 @@ Class {
#category : #'Spec2-Layout-Box'
}

{ #category : #'as yet unclassified' }
{ #category : #defaults }
SpBoxConstraints class >> defaultExpand [

^ true
]

{ #category : #'as yet unclassified' }
{ #category : #defaults }
SpBoxConstraints class >> defaultFill [

^ true
]

{ #category : #'as yet unclassified' }
{ #category : #defaults }
SpBoxConstraints class >> defaultPadding [

^ 0
@@ -44,6 +44,16 @@ SpBoxLayout >> add: aName [

{ #category : #adding }
SpBoxLayout >> add: aName expand: shouldExpand fill: shouldFill padding: aNumber [
"
aName - the presenter to be added to box
expand - true if the new child is to be given extra space allocated to box .
The extra space will be divided evenly between all children that use this option
fill - true if space given to child by the expand option is actually allocated to child ,
rather than just padding it. This parameter has no effect if expand is set to false.
padding - extra space in pixels to put between this child and its neighbors, over and above
the global amount specified by “spacing” property. If child is a widget at one of
the reference ends of box , then padding pixels are also put between child and the
reference edge of box"

self
add: aName
@@ -22,6 +22,14 @@ SpBoxLayoutWithTableForTestPresenter class >> open [
self new openWithSpec
]

{ #category : #specs }
SpBoxLayoutWithTableForTestPresenter class >> specWithPadding [

^ SpBoxLayout newVertical
add: #table expand: false fill: false padding: 10;
yourself
]

{ #category : #initialization }
SpBoxLayoutWithTableForTestPresenter >> initializeWidgets [

@@ -15,6 +15,44 @@ SpMorphicBoxLayoutTest >> tearDown [
instance := nil ]
]

{ #category : #tests }
SpMorphicBoxLayoutTest >> testAddWithPaddingHorizontal [
| base presenter layout |

base := SpBoxLayoutWithTableForTestPresenter new.
presenter := SpLabelPresenter new.

layout := SpBoxLayout newHorizontal
add: presenter expand: false fill: false padding: 10;
yourself.

base buildAdapterWithSpecLayout: layout.

"validate the widget is within a parent that keeps the widget with a padding"
self
assert: presenter adapter widget extent
equals: (presenter adapter widget owner extent - (20@0))
]

{ #category : #tests }
SpMorphicBoxLayoutTest >> testAddWithPaddingVertical [
| base presenter layout |

base := SpBoxLayoutWithTableForTestPresenter new.
presenter := SpLabelPresenter new.

layout := SpBoxLayout newVertical
add: presenter expand: false fill: false padding: 10;
yourself.

base buildAdapterWithSpecLayout: layout.

"validate the widget is within a parent that keeps the widget with a padding"
self
assert: presenter adapter widget extent
equals: (presenter adapter widget owner extent - (0@20))
]

{ #category : #tests }
SpMorphicBoxLayoutTest >> testClassIsDisplayedWithCorrectAlignment [
| presenter table |

0 comments on commit 85719bc

Please sign in to comment.
You can’t perform that action at this time.