Bloc icon indicating copy to clipboard operation
Bloc copied to clipboard

Expected size ?

Open ELePors opened this issue 1 year ago • 8 comments

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...

ELePors avatar May 30 '23 12:05 ELePors

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).

labordep avatar May 31 '23 15:05 labordep

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:

Screenshot 2023-06-01 at 20 12 52

I'm not the creator of the resizers, just starting to understand a bit them!

tinchodias avatar Jun 02 '23 00:06 tinchodias

if the resizer is FitContent for example, expectedSize could return a size after a computeLayout... but...

ELePors avatar Jun 06 '23 16:06 ELePors

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!

tinchodias avatar Jun 08 '23 21:06 tinchodias

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: Screenshot 2023-06-08 at 18 24 04

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...

tinchodias avatar Jun 08 '23 22:06 tinchodias

With @Enzo-Demeulenaere we realized that fitContent constraint is also ignored by default layout (BlBasicLayout).

Example:

Screenshot 2023-07-20 at 10 48 59

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.

tinchodias avatar Jul 20 '23 14:07 tinchodias

@ELePors @labordep Do we consider this issue fixed by https://github.com/pharo-graphics/Bloc/commit/38b69b682532b68f4ce9b8666bd6b11904f213ef ?

tinchodias avatar Aug 03 '23 22:08 tinchodias

@ELePors this is good for you ?

labordep avatar Dec 07 '23 11:12 labordep