pharo-graphics / Bloc

Low-level UI infrastructure & framework for Pharo
MIT License
80 stars 40 forks source link

Are min/maxWidth/Height Layout Constraints correctly implemented ? #581

Open Enzo-Demeulenaere opened 1 month ago

Enzo-Demeulenaere commented 1 month ago

Hello,

I noticed the minWidth method in BlLayoutCommonConstraints class and I wondered how it worked, so can I use this to define a minimum width that would be applied to a parent with a fitContent constraint ?

I wrote this snippet that doesn't seem to work as intended at all (as it makes everything disappear) :

parent := BlElement new background: Color lightBlue; size: 200 asPoint.

child := BlElement new background: Color lightRed.

parent addChild: child.

parent openInSpace.

parent constraintsDo: [ :c |
    c minWidth: 75. ].

parent constraintsDo: [ :c |
    c horizontal fitContent ].

Although I tested it with a FrameLayout on the parent and it seemed to work so I guess it's the behavior of the BasicLayout that doesn't take the minWidth constraint.

Capture d’écran 2024-08-20 à 12 00 57

I Also tried it with a maxWidth on the child like this :

parent := BlElement new background: Color lightBlue; size: 200 asPoint.

child := BlElement new background: Color lightRed.

parent addChild: child.

parent openInSpace.

child constraintsDo: [ :c |
    c maxWidth: 75. ].

child constraintsDo: [ :c |
    c horizontal matchParent ].
Capture d’écran 2024-08-20 à 12 02 02

Once again it didn't work and even with a FrameLayout the child doesn't respect the maxWidth constraint. We can now wonder why the minWidth constraints works with a FrameLayout but not the maxWidth one.

Are those methods/constraints designed for only a few layouts ?

I'd be glad to learn more about these

Regards, Enzo

tinchodias commented 2 weeks ago

Good point, related to other recent question. The layout of both the parent and child element are who take constraints into account... or ignore them. The default layout, BlBasicLayout, ignores the minWidth and minHeight. It ignores other attributes as well as margin.

I didn't do an exhaustive test. We can explore more on this. But I wrote this small example:

s := BlSpace new.
s root addChild: (a := BlElement new
         background: Color green;
         constraintsDo: [ :c |
             c horizontal matchParent.
             c vertical fitContent.
             c minHeight: 100 ];
         yourself).
s extent: 200 asPoint.
s show.

shows:

Screenshot 2024-08-30 at 19 29 30

and if you evaluate a layout: BlFrameLayout new, the window changes to:

Screenshot 2024-08-30 at 19 29 41

because the BlFrameLayout took into account minHeight.