Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make BlLinearLayout work ok with RTL direction #306

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Bloc-Layout-Tests/BlLinearLayoutVerticalTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BlLinearLayoutVerticalTest >> testElementWithChildMatchInExactParentPadding [
<sampleInstance>
| parent childA |
childA := self testChildElementMatchingParent.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal exact: 400.
parent constraints vertical exact: 600.
parent constraints padding: (BlInsets all: 20).
Expand All @@ -36,7 +36,7 @@ BlLinearLayoutVerticalTest >> testElementWithChildrenMatchInExactParentPadding [
| parent childA childB |
childA := self testChildElementMatchingParent.
childB := self testChildElementMatchingParent.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal exact: 600.
parent constraints vertical exact: 400.
parent constraints padding: (BlInsets all: 20).
Expand All @@ -61,7 +61,7 @@ BlLinearLayoutVerticalTest >> testElementWithExactChildrenInFitContent [
| parent childA childB |
childA := self childExact: 200 @ 100.
childB := self childExact: 100 @ 200.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal fitContent.
parent constraints vertical fitContent.
parent addChildren: {
Expand All @@ -86,7 +86,7 @@ BlLinearLayoutVerticalTest >> testElementWithMatchChildrenInExactParent [
childA := self testChildElementMatchingParent.
childB := self testChildElementMatchingParent.
childC := self testChildElementMatchingParent.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal exact: 200.
parent constraints vertical exact: 600.
parent addChildren: {
Expand Down Expand Up @@ -114,7 +114,7 @@ BlLinearLayoutVerticalTest >> testElementWithOneChildMatchOneExactInFitParent [
childA := self childExact: 200 @ 300.
childB := self childExactHeight: 200.
childB constraints horizontal matchParent.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal fitContent.
parent constraints vertical fitContent.
parent addChildren: {
Expand Down Expand Up @@ -142,7 +142,7 @@ BlLinearLayoutVerticalTest >> testElementWithOneExactChildInExactParentMargin [
right: 0
bottom: 0
left: 10).
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal exact: 50.
parent constraints vertical exact: 50.
parent addChildren: { childA }.
Expand All @@ -165,7 +165,7 @@ BlLinearLayoutVerticalTest >> testElementWithThreeExactChildrenAlignInExactParen
childA constraints linear horizontal alignLeft.
childB constraints linear horizontal alignCenter.
childC constraints linear horizontal alignRight.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent constraints horizontal exact: 500.
parent constraints vertical exact: 600.
parent addChildren: {
Expand Down Expand Up @@ -195,7 +195,7 @@ BlLinearLayoutVerticalTest >> testElementWithThreeExactChildrenAlignInExactParen
childA constraints linear horizontal alignLeft.
childB constraints linear horizontal alignCenter.
childC constraints linear horizontal alignRight.
parent := self testParentWithLinearHorizontalLayout.
parent := self testParentWithLinearVerticalLayout.
parent layout rightToLeft.
parent constraints horizontal exact: 500.
parent constraints vertical exact: 600.
Expand All @@ -205,11 +205,11 @@ BlLinearLayoutVerticalTest >> testElementWithThreeExactChildrenAlignInExactParen
childC }.
parent forceLayout.
self assert: childA extent equals: 100 @ 100.
self assert: childA position equals: 400 @ 0.
self assert: childA position equals: 400 @ 200.
self assert: childB extent equals: 200 @ 100.
self assert: childB position equals: 150 @ 100.
self assert: childC extent equals: 50 @ 100.
self assert: childC position equals: 0 @ 200.
self assert: childC position equals: 0 @ 0.
self assert: parent extent equals: 500 @ 600.
self assert: parent position equals: 0 @ 0.
^ parent
Expand Down Expand Up @@ -257,7 +257,7 @@ BlLinearLayoutVerticalTest >> testOneChildSetVisibilityGone [
]

{ #category : #tests }
BlLinearLayoutVerticalTest >> testParentWithLinearHorizontalLayout [
BlLinearLayoutVerticalTest >> testParentWithLinearVerticalLayout [

<sampleInstance>
| element |
Expand Down
13 changes: 9 additions & 4 deletions src/Bloc-Layout/BlLinearLayoutVerticalOrientation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BlLinearLayoutVerticalOrientation >> isVertical [

{ #category : #layout }
BlLinearLayoutVerticalOrientation >> layout: anElement in: aRectangle context: aBlElementBoundsUpdateContext [
|top right bottom left majorBounds elementInnerBounds turn |
|top right bottom left majorBounds elementInnerBounds turn theLayeredChildren |
"Layout subnodes vertically in column one by one
based on previously measured extent"

Expand All @@ -53,15 +53,19 @@ BlLinearLayoutVerticalOrientation >> layout: anElement in: aRectangle context: a
right := left.
bottom := top.

anElement children accountedByLayout do: [ :child |
theLayeredChildren := anElement children accountedByLayout.

self layout direction
with: theLayeredChildren
do: [ :child |
right := right max: child measuredWidth + (child outsets width max: 0.0).
bottom := bottom + child measuredHeight + (child outsets height max: 0.0) ].

majorBounds := (left@top corner: right@bottom).
elementInnerBounds := anElement padding inset: anElement boundsInLocal.
majorBounds = elementInnerBounds ifFalse: [
| translation |
translation := self layout verticalAlignment translationOf: majorBounds in: elementInnerBounds.
translation := (self layout verticalAlignment directed: self layout direction) translationOf: majorBounds in: elementInnerBounds.
majorBounds := majorBounds translateBy: translation ].

right := majorBounds right.
Expand All @@ -70,7 +74,8 @@ BlLinearLayoutVerticalOrientation >> layout: anElement in: aRectangle context: a
top := majorBounds top.

turn := 1.
anElement children accountedByLayout
self layout direction
with: anElement children accountedByLayout
inject: left @ top
into: [ :origin :child |
| childBounds childMarginBounds childConstraints interspacing |
Expand Down