Skip to content

Commit

Permalink
Merge pull request #1667 from Ducasse/1658-Deprecate-at-in-favor-for-…
Browse files Browse the repository at this point in the history
…atPoint-in-SpGridLayout

1658 deprecate at in favor for at point in sp grid layout
Ducasse authored Nov 25, 2024
2 parents 83fd72f + bd12578 commit b9156c7
Showing 5 changed files with 186 additions and 148 deletions.
195 changes: 101 additions & 94 deletions src/Spec2-Backend-Tests/SpGridLayoutAdapterTest.class.st
Original file line number Diff line number Diff line change
@@ -16,147 +16,150 @@ SpGridLayoutAdapterTest >> newLayout [
SpGridLayoutAdapterTest >> testAddAtSamePositionTwiceReplacesChild [

| first second |
layout add: (first := SpButtonPresenter new) at: 1@1.
layout add: (second := SpButtonPresenter new) at: 1@1.
self assert: self adapter children first equals: second adapter widget
layout add: (first := SpButtonPresenter new) atPoint: 1 @ 1.
layout add: (second := SpButtonPresenter new) atPoint: 1 @ 1.
self
assert: self adapter children first
equals: second adapter widget
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testAddAtSamePositionTwiceSetsChildrenSingleTime [

layout add: (SpButtonPresenter new) at: 1@1.
layout add: (SpButtonPresenter new) at: 1@1.
layout add: SpButtonPresenter new atPoint: 1 @ 1.
layout add: SpButtonPresenter new atPoint: 1 @ 1.
self assert: self adapter children size equals: 1
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testAddElementAddsToAdapter [

layout add: SpButtonPresenter new at: 1@1.
layout add: SpButtonPresenter new atPoint: 1 @ 1.
self deny: self adapter isEmpty
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testAddElementAfterOpenAddsToAdapter [

layout add: SpButtonPresenter new at: 1@1.
layout add: SpButtonPresenter new atPoint: 1 @ 1.
self openInstance.
layout add: SpButtonPresenter new at: 1@2.

layout add: SpButtonPresenter new atPoint: 1 @ 2.
self assert: self adapter children size equals: 2
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testBeColumnHomogeneous [

layout
layout
beColumnHomogeneous;
add: 'Test' at: 1@1;
add: 'Other label test' at: 2@1.
add: 'Test' atPoint: 1 @ 1;
add: 'Other label test' atPoint: 2 @ 1.

self openInstance.
self
assert: presenter adapter widget submorphs first width

self
assert: presenter adapter widget submorphs first width
equals: presenter adapter widget submorphs second width
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testBeColumnNotHomogeneous [

layout
layout
beColumnNotHomogeneous;
add: 'Test' at: 1@1;
add: 'Other label test' at: 2@1.
add: 'Test' atPoint: 1 @ 1;
add: 'Other label test' atPoint: 2 @ 1.

self openInstance.
self
deny: presenter adapter widget submorphs first width

self
deny: presenter adapter widget submorphs first width
equals: presenter adapter widget submorphs second width
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testBeRowHomogeneous [

layout
layout
beRowHomogeneous;
add: 'Test' at: 1@1;
add: (presenter newMorph morph: (Morph new extent: 40@40)) at: 1@2.

add: 'Test' atPoint: 1 @ 1;
add: (presenter newMorph morph: (Morph new extent: 40 @ 40))
atPoint: 1 @ 2.

self openInstance.
self
assert: presenter adapter widget submorphs first height

self
assert: presenter adapter widget submorphs first height
equals: presenter adapter widget submorphs second height
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testBeRowNotHomogeneous [

| testMorph |

testMorph := Morph new
vResizing: #rigid;
extent: 40@40;
yourself.
layout
vResizing: #rigid;
extent: 40 @ 40;
yourself.

layout
beRowNotHomogeneous;
add: 'Test' at: 1@1;
add: (presenter newMorph morph: testMorph) at: 1@2.
add: 'Test' atPoint: 1 @ 1;
add: (presenter newMorph morph: testMorph) atPoint: 1 @ 2.

self openInstance.
self
deny: presenter adapter widget submorphs first height

self
deny: presenter adapter widget submorphs first height
equals: presenter adapter widget submorphs second height
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testColumnSpanColumnHomogeneous [

layout
layout
beColumnHomogeneous;
add: 'Test' at: 1@1 span: 2@1;
add: 'Other label test' at: 1@2; add: 'span column'at: 2@2.

add: 'Test' atPoint: 1 @ 1 span: 2 @ 1;
add: 'Other label test' atPoint: 1 @ 2;
add: 'span column' at: 2 @ 2.

self openInstance.

self
assert: presenter adapter widget submorphs first width
equals: (
(presenter adapter widget submorphs second width)
+ (presenter adapter widget submorphs third width))

self
assert: presenter adapter widget submorphs first width
equals: presenter adapter widget submorphs second width
+ presenter adapter widget submorphs third width
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testColumnSpanColumnNotHomogeneous [

layout
layout
beColumnNotHomogeneous;
add: 'Test' at: 1@1 span: 2@1;
add: 'Other' at: 1@2; add: 'span column, larger'at: 2@2.

add: 'Test' atPoint: 1 @ 1 span: 2 @ 1;
add: 'Other' atPoint: 1 @ 2;
add: 'span column, larger' at: 2 @ 2.

self openInstance.

"the first column width is equal to the sum of two columns"
self
assert: presenter adapter widget submorphs first width
equals: (
(presenter adapter widget submorphs second width)
+ (presenter adapter widget submorphs third width)).
self
assert: presenter adapter widget submorphs first width
equals: presenter adapter widget submorphs second width
+ presenter adapter widget submorphs third width.
"the first column still needs to be smaller than the first"
self
assert: presenter adapter widget submorphs second width < (presenter adapter widget submorphs third width)
self assert: presenter adapter widget submorphs second width
< presenter adapter widget submorphs third width
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testRemoveElementAddedAfterOpenRemovesFromAdapter [

| element |
layout add: (element := SpButtonPresenter new) at: 1@1.
layout add: (element := SpButtonPresenter new) atPoint: 1 @ 1.
self openInstance.

layout remove: element.
self assert: self adapter isEmpty
]
@@ -165,52 +168,56 @@ SpGridLayoutAdapterTest >> testRemoveElementAddedAfterOpenRemovesFromAdapter [
SpGridLayoutAdapterTest >> testRemoveElementRemovesFromAdapter [

| element |
layout add: (element := SpButtonPresenter new) at: 1@1.
layout add: (element := SpButtonPresenter new) atPoint: 1 @ 1.
layout remove: element.
self assert: self adapter isEmpty
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testRowSpanRowHomogeneous [

| testMorph |

testMorph := Morph new
vResizing: #rigid;
extent: 40@40;
yourself.
layout
vResizing: #rigid;
extent: 40 @ 40;
yourself.

layout
beRowHomogeneous;
add: 'Test 1' at: 1@1; add: (presenter newMorph morph: testMorph) at: 2@1 span: 1@2;
add: 'Test 2' at: 1@2.

add: 'Test 1' atPoint: 1 @ 1;
add: (presenter newMorph morph: testMorph)
atPoint: 2 @ 1
span: 1 @ 2;
add: 'Test 2' at: 1 @ 2.

self openInstance.
self
assert: presenter adapter widget submorphs second height
equals:
presenter adapter widget submorphs first height
self
assert: presenter adapter widget submorphs second height
equals: presenter adapter widget submorphs first height
+ presenter adapter widget submorphs third height
]

{ #category : 'tests' }
SpGridLayoutAdapterTest >> testRowSpanRowNotHomogeneous [

| testMorph |

testMorph := Morph new
vResizing: #rigid;
extent: 40@40;
yourself.
layout
vResizing: #rigid;
extent: 40 @ 40;
yourself.

layout
beRowNotHomogeneous;
add: 'Test 1' at: 1@1; add: (presenter newMorph morph: testMorph) at: 2@1 span: 1@2;
add: 'Test 2' at: 1@2.

add: 'Test 1' atPoint: 1 @ 1;
add: (presenter newMorph morph: testMorph)
atPoint: 2 @ 1
span: 1 @ 2;
add: 'Test 2' at: 1 @ 2.

self openInstance.

self
assert: presenter adapter widget submorphs second height
equals:
presenter adapter widget submorphs first height

self
assert: presenter adapter widget submorphs second height
equals: presenter adapter widget submorphs first height
+ presenter adapter widget submorphs third height
]
4 changes: 2 additions & 2 deletions src/Spec2-Examples/SpDemoTextInputPresenter.class.st
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ SpDemoTextInputPresenter class >> example [
SpDemoTextInputPresenter >> defaultLayout [

^ SpGridLayout new
add: 'Normal:' at: 1 @ 1;
add: fieldNormal at: 2 @ 1 span: 2 @ 1;
add: 'Normal:' atPoint: 1 @ 1;
add: fieldNormal atPoint: 2 @ 1 span: 2 @ 1;
add: 'Disabled:' at: 1 @ 2;
add: fieldDisabled at: 2 @ 2 span: 2 @ 1;
add: 'Placeholder:' at: 1 @ 3;
64 changes: 55 additions & 9 deletions src/Spec2-Layout/SpGridLayout.class.st
Original file line number Diff line number Diff line change
@@ -108,18 +108,39 @@ SpGridLayout >> adapterName [
^ #GridAdapter
]

{ #category : 'api - adding' }
{ #category : 'deprecated' }
SpGridLayout >> add: aName at: aPoint [

^ self
add: aName
at: aPoint
span: 1@1
self deprecated: 'Use add:atPoint:'
on: '24/11/2024'
in: #Pharo13
transformWith: '`@receiver add: `@arg at: `@aPoint'
-> '`@receiver add: `@arg atPoint: `@aPoint'.

^ self add: aName atPoint: aPoint
]

{ #category : 'api - adding' }
{ #category : 'deprecated' }
SpGridLayout >> add: aName at: aPoint span: spanPoint [

self deprecated: 'Use add:atPoint:span:'
on: '24/11/2024'
in: #Pharo13
transformWith: '`@receiver add: `@arg at: `@aPoint span: `@span'
-> '`@receiver add: `@arg atPoint: `@aPoint span: `@span'.

^ self add: aName atPoint: aPoint span: spanPoint
]

{ #category : 'api - adding' }
SpGridLayout >> add: aName atPoint: aPoint [

^ self add: aName atPoint: aPoint span: 1 @ 1
]

{ #category : 'api - adding' }
SpGridLayout >> add: aName atPoint: aPoint span: spanPoint [

childrenByPosition at: aPoint ifPresent: [ :e |
"Remove element at the same position"
self remove: e ].
@@ -140,9 +161,21 @@ SpGridLayout >> add: aChild withConstraints: aBlock [
self announceChildAdded: aChild.
]

{ #category : 'accessing' }
{ #category : 'deprecated' }
SpGridLayout >> at: aPoint [

self deprecated: 'Use atPoint:'
on: '24/11/2024'
in: #Pharo13
transformWith: '`@receiver at: `@aPoint'
-> '`@receiver atPoint: `@aPoint'.

^ self atPoint: aPoint
]

{ #category : 'accessing' }
SpGridLayout >> atPoint: aPoint [

^ childrenByPosition at: aPoint
]

@@ -261,13 +294,26 @@ SpGridLayout >> isRowHomogeneous [
^ rowHomogeneous
]

{ #category : 'api - adding' }
{ #category : 'deprecated' }
SpGridLayout >> replaceAt: aPoint with: aPresenter [
"This is just a synonym of SpGridLayout>>#add:at:, added for clarity"

self deprecated: 'Use replaceAtPoint:with:'
on: '24/11/2024'
in: #Pharo13
transformWith: '`@receiver replaceAt:`@aPoint with: `@aPresenter'
-> '`@receiver replaceAtPoint: `@aPoint with: `@aPresenter'.

^ self replaceAtPoint: aPoint with: aPresenter
]

{ #category : 'api - adding' }
SpGridLayout >> replaceAtPoint: aPoint with: aPresenter [
"This is just a synonym of SpGridLayout>>#add:at:, added for clarity"

^ self
add: aPresenter
at: aPoint
atPoint: aPoint
]

{ #category : 'api' }
3 changes: 2 additions & 1 deletion src/Spec2-Layout/SpGridLayoutBuilder.class.st
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@ SpGridLayoutBuilder class >> on: aGridLayout [

{ #category : 'api' }
SpGridLayoutBuilder >> add: aChild [
layout add: aChild at: self nextColumn @ self currentRow.

layout add: aChild atPoint: self nextColumn @ self currentRow
]

{ #category : 'api' }
68 changes: 26 additions & 42 deletions src/Spec2-Tests/SpGridLayoutBuilderTest.class.st
Original file line number Diff line number Diff line change
@@ -16,56 +16,40 @@ SpGridLayoutBuilderTest >> newPresenters: nbPresesenters [

{ #category : 'tests' }
SpGridLayoutBuilderTest >> testBuilderAddsElementsOnRaw [

| layout presenters |

presenters := self newPresenters: 3.
layout := SpGridLayout build: [ :builder |
builder
add: presenters first;
add: presenters second;
add: presenters third ].

self
assert: (layout at: 1@1)
equals: presenters first.
self
assert: (layout at: 2@1)
equals: presenters second.
self
assert: (layout at: 3@1)
equals: presenters third.
layout := SpGridLayout build: [ :builder |
builder
add: presenters first;
add: presenters second;
add: presenters third ].

self assert: (layout atPoint: 1 @ 1) equals: presenters first.
self assert: (layout at: 2 @ 1) equals: presenters second.
self assert: (layout at: 3 @ 1) equals: presenters third
]

{ #category : 'tests' }
SpGridLayoutBuilderTest >> testBuilderCanAddElementsOnMultipleRaws [

| layout presenters |

presenters := self newPresenters: 5.
layout := SpGridLayout build: [ :builder |
builder
add: presenters first;
add: presenters second;
nextRow;
add: presenters third;
nextRow;
add: presenters fourth;
add: presenters fifth ].

self
assert: (layout at: 1@1)
equals: presenters first.
self
assert: (layout at: 2@1)
equals: presenters second.
self
assert: (layout at: 1@2)
equals: presenters third.
self
assert: (layout at: 1@3)
equals: presenters fourth.
self
assert: (layout at: 2@3)
equals: presenters fifth.
layout := SpGridLayout build: [ :builder |
builder
add: presenters first;
add: presenters second;
nextRow;
add: presenters third;
nextRow;
add: presenters fourth;
add: presenters fifth ].

self assert: (layout atPoint: 1 @ 1) equals: presenters first.
self assert: (layout at: 2 @ 1) equals: presenters second.
self assert: (layout at: 1 @ 2) equals: presenters third.
self assert: (layout at: 1 @ 3) equals: presenters fourth.
self assert: (layout at: 2 @ 3) equals: presenters fifth
]

{ #category : 'tests' }

0 comments on commit b9156c7

Please sign in to comment.