Bloc
Bloc copied to clipboard
Expected size ?
2 new methods which should be usefull for BlElements :
expectedSize
-> send the size asked by the developper when he sends the size:
method or the final one if computed.
expectedPosition
-> send the position asked by the developper when he sends the position:
even if the BlElement is not already drawn in a Space...
Sometimes we need to knows the expected size of an element (theorically) to place others elements and do some stuff like that. And this is during the building of the view (so before drawing).
I agree this is important. Until I have an opinion to give, I bring and analyze here the two key methods:
position: aPoint
self measuredBounds position = aPoint ifTrue: [ ^ self ].
self constraints position: aPoint.
self measuredBounds position: aPoint.
self requestParentLayout
So, for position of element e
, any of: e constraints position
or e measuredBounds position
returns the value. But not so simple for size:
size: aPoint
| aLayoutConstraints |
aLayoutConstraints := self constraints.
(aLayoutConstraints horizontal resizer isExact and: [
aLayoutConstraints horizontal resizer size = aPoint x
and: [ aLayoutConstraints vertical resizer isExact
and: [ aLayoutConstraints vertical resizer size = aPoint y ] ] ])
ifTrue: [ ^ self ].
self constraintsDo: [ :c |
c horizontal exact: aPoint x.
c vertical exact: aPoint y ]
If both "resizers" of an element e
are exact, then we have e constraints horizontal resizer size @ e constraints vertical resizer size.
. But the resizer can be of other kinds:
I'm not the creator of the resizers, just starting to understand a bit them!
if the resizer is FitContent for example, expectedSize could return a size after a computeLayout... but...
I'm realizing that the new proportional layout doesn't respect resizers, example:
e := BlElement new
background: Color random;
constraintsDo: [ :c |
c proportional horizontal
left: 0.1;
right: 0.9 ].
yourself.
aContainer := BlElement new
background: Color random;
layout: BlProportionalLayout new;
size: 100 @ 100;
addChild: e;
yourself.
aSpace := BlSpace new.
aSpace root addChild: aContainer.
aSpace show.
After show, the result of {e width. e constraints horizontal resizer. e constraints vertical resizer}
is an Array(80 Exact 50.0 Exact 50.0)
. So, querying the size as in previous comments would fail!
For the record, I tested then this example:
r := BlElement new
background: Color red;
layout: BlProportionalLayout new;
constraintsDo: [ :c |
c proportional horizontal left: 0.1 ];
yourself.
g := BlElement new
background: Color green;
layout: BlProportionalLayout new;
constraintsDo: [ :c |
c proportional horizontal right: 0.9 ];
addChild: r;
yourself.
b := BlElement new
background: Color blue;
layout: BlProportionalLayout new;
constraintsDo: [ :c |
c proportional vertical top: 0.1 ];
addChild: g;
yourself.
r2 := BlElement new
background: Color red muchDarker;
layout: BlProportionalLayout new;
constraintsDo: [ :c |
c proportional horizontal left: 0.1 ];
addChild: b;
yourself.
g2 := BlElement new
background: Color green muchDarker;
layout: BlProportionalLayout new;
constraintsDo: [ :c |
c proportional horizontal right: 0.9 ];
addChild: r2;
yourself.
b2 := BlElement new
background: Color blue muchDarker;
layout: BlProportionalLayout new;
constraintsDo: [ :c |
c proportional vertical top: 0.1 ];
addChild: g2;
yourself.
aSpace := BlSpace new.
aSpace root
layout: BlProportionalLayout new;
addChild: b2.
aSpace
extent: 100 @ 100;
show.
looks like:
I print:
aSpace root allChildrenDepthFirstDo: [ :e |
{ e width. e constraints horizontal resizer. e constraints vertical resizer } traceCr ]
before layout:
an Array(0.0 Exact 50.0 Exact 50.0)
an Array(0.0 Exact 50.0 Exact 50.0)
an Array(0.0 Exact 50.0 Exact 50.0)
an Array(0.0 Exact 50.0 Exact 50.0)
an Array(0.0 Exact 50.0 Exact 50.0)
an Array(0.0 Exact 50.0 Exact 50.0)
after layout:
an Array(66 Exact 50.0 Exact 50.0)
an Array(73 Exact 50.0 Exact 50.0)
an Array(81 Exact 50.0 Exact 50.0)
an Array(81 Exact 50.0 Exact 50.0)
an Array(90 Exact 50.0 Exact 50.0)
an Array(100 Exact 50.0 Exact 50.0)
Probably these resizers should be Exact 50.0...
With @Enzo-Demeulenaere we realized that fitContent
constraint is also ignored by default layout (BlBasicLayout).
Example:
The space is just blank with the following snippet unless you change the layout (commented line):
a := BlElement new
background: Color blue;
size: 100 asPoint;
yourself.
container := BlElement new
constraintsDo: [ :c |
c padding: (BlInsets all: 5).
c horizontal fitContent.
c vertical fitContent ];
addChild: a;
background: Color red;
yourself.
"container layout: BlLinearLayout horizontal."
container openInSpace.
@ELePors @labordep Do we consider this issue fixed by https://github.com/pharo-graphics/Bloc/commit/38b69b682532b68f4ce9b8666bd6b11904f213ef ?
@ELePors this is good for you ?