Skip to content

Commit

Permalink
Merge pull request #1513 from koendehondt/bugfix/boxlayout-endpanel-m…
Browse files Browse the repository at this point in the history
…inwidth-minheight

Set the minWidth and the minHeight of the endPanel created for a box layout
  • Loading branch information
estebanlm authored Jan 26, 2024
2 parents c1c41bf + b7a44d5 commit f8c9b76
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
2 changes: 2 additions & 0 deletions src/Spec2-Adapters-Morphic/SpMorphicBoxAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ SpMorphicBoxAdapter >> newHorizontal [
listDirection: #leftToRight;
hResizing: #shrinkWrap;
width: 0;
minWidth: 0; "Otherwise an empty endPanel has a width of 2 pixels due to Morph>>#minWidth."
yourself);
yourself
]
Expand All @@ -236,6 +237,7 @@ SpMorphicBoxAdapter >> newVertical [
listDirection: #topToBottom;
vResizing: #shrinkWrap;
height: 0;
minHeight: 0; "Otherwise an empty endPanel has a height of 2 pixels due to Morph>>#minHeight."
yourself);
yourself
]
Expand Down
95 changes: 51 additions & 44 deletions src/Spec2-Morphic-Backend-Tests/SpMorphicBoxLayoutTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -64,105 +64,112 @@ SpMorphicBoxLayoutTest >> testAddWithPaddingVertical [
{ #category : #tests }
SpMorphicBoxLayoutTest >> testBeHomogeneous [

| presenter p1 p2 p3 |
"not working on CI :("
self skipOnPharoCITestingEnvironment.

| presenter p1 p2 p3 presenterWidth width1 width2 width3 |
presenter := SpPresenter new.
presenter layout: (SpBoxLayout newHorizontal
beHomogeneous;
add: (p1 := presenter newButton);
add: (p2 := presenter newLabel);
add: (p3 := presenter newList);
add: (p3 := presenter newButton);
yourself).

p1 label: 'Button'.
p2 label: 'Label'.
p3 items: #( one two three ).
p3 label: 'Button'.

[
presenter open.
backend waitUntilUIRedrawed ] ensure: [
[
"190 = 5 window border + 180 + 5 window border. 180 is a multiple of 3 (all presenters have the same width)."
presenter asWindow initialExtent: 190@150; open.
backend waitUntilUIRedrawed ] ensure: [
presenter withWindowDo: #close ].

self assert: presenter adapter widget width
>= (p1 adapter widget width + p2 adapter widget width
+ p3 adapter widget width).
self assert: p2 adapter widget width equals: p3 adapter widget width.
self assert: p1 adapter widget width equals: p2 adapter widget width
presenterWidth := presenter adapter widget width.
width1 := p1 adapter widget width.
width2 := p2 adapter widget width.
width3 := p3 adapter widget width.
self assert: presenterWidth equals: (width1 + width2 + width3).
self assert: width1 equals: width2.
self assert: width2 equals: width3
]

{ #category : #tests }
SpMorphicBoxLayoutTest >> testBeHomogeneousWorksWhenContractingWindow [

| presenter p1 p2 p3 windowWidth presenterWidth width1 width2 width3 |
"not working on CI :("
self skipOnPharoCITestingEnvironment.

| presenter p1 p2 p3 windowWidth presenterWidth width1 width2 width3 initialWindowWidth |
presenter := SpPresenter new.
presenter layout: (SpBoxLayout newHorizontal
beHomogeneous;
add: (p1 := presenter newButton);
add: (p2 := presenter newLabel);
add: (p3 := presenter newList);
add: (p3 := presenter newButton);
yourself).

p1 label: 'Button'.
p2 label: 'Label'.
p3 items: #( one two three ).
p3 label: 'Button'.

[
presenter open.
[
"190 = 5 window border + 180 + 5 window border. 180 is a multiple of 3 (all presenters have the same width)."
presenter asWindow initialExtent: 190@150; open.
backend waitUntilUIRedrawed.
presenter withWindowDo: [ :window |
window adapter widgetDo: [ :widget |
widget extent: widget extent - (50 @ 50) ] ].
backend waitUntilUIRedrawed ] ensure: [
initialWindowWidth := presenter window adapter widget width.
presenter withWindowDo: [ :window |
window adapter widgetDo: [ :widget |
"Keep the presenter's width a multiple of 3,
so that there are no rounding differences in the width of the nested presenters."
widget extent: widget extent - (30 @ 50) ] ].
backend waitUntilUIRedrawed ] ensure: [
presenter withWindowDo: #close ].

windowWidth := presenter window adapter widget width.
presenterWidth := presenter adapter widget width.
width1 := p1 adapter widget width.
width2 := p2 adapter widget width.
width3 := p3 adapter widget width.
self assert: presenterWidth >= (width1 + width2 + width3).
self assert: presenterWidth equals: (width1 + width2 + width3).
self assert: width1 equals: width2.
self assert: width2 equals: width3.
self assert: windowWidth >= presenterWidth
self assert: windowWidth equals: presenterWidth + 10 "5 + 5 of the window borders"
]

{ #category : #tests }
SpMorphicBoxLayoutTest >> testBeHomogeneousWorksWhenExpandingWindow [

| presenter p1 p2 p3 |
| presenter p1 p2 p3 windowWidth presenterWidth width1 width2 width3 initialWindowWidth |
presenter := SpPresenter new.
presenter layout: (SpBoxLayout newHorizontal
beHomogeneous;
add: (p1 := presenter newButton);
add: (p2 := presenter newLabel);
add: (p3 := presenter newList);
add: (p3 := presenter newButton);
yourself).

p1 label: 'Button'.
p2 label: 'Label'.
p3 items: #( one two three ).
p3 label: 'Button'.

[
presenter open.
[
"190 = 5 window border + 180 + 5 window border. 180 is a multiple of 3 (all presenters have the same width)."
presenter asWindow initialExtent: 190@150; open.
backend waitUntilUIRedrawed.
presenter withWindowDo: [ :window |
window adapter widgetDo: [ :widget |
widget extent: widget extent + (200 @ 10) ] ].
backend waitUntilUIRedrawed ] ensure: [
initialWindowWidth := presenter window adapter widget width.
presenter withWindowDo: [ :window |
window adapter widgetDo: [ :widget |
"Keep the presenter's width a multiple of 3,
so that there are no rounding differences in the width of the nested presenters."
widget extent: widget extent + (30 @ 10) ] ].
backend waitUntilUIRedrawed ] ensure: [
presenter withWindowDo: #close ].

self assert: presenter adapter widget width
>= (p1 adapter widget width + p2 adapter widget width
+ p3 adapter widget width).
self assert: p2 adapter widget width equals: p3 adapter widget width.
self assert: p1 adapter widget width equals: p2 adapter widget width.
self assert: presenter window adapter widget width
>= presenter adapter widget width
windowWidth := presenter window adapter widget width.
presenterWidth := presenter adapter widget width.
width1 := p1 adapter widget width.
width2 := p2 adapter widget width.
width3 := p3 adapter widget width.
self assert: presenterWidth equals: (width1 + width2 + width3).
self assert: width1 equals: width2.
self assert: width2 equals: width3.
self assert: windowWidth equals: presenterWidth + 10 "5 + 5 of the window borders"
]

{ #category : #tests }
Expand Down

0 comments on commit f8c9b76

Please sign in to comment.