[Cuis-dev] Column type layout morph anomaly

Szabolcs Komáromi cuis at mnqpr.com
Sat Aug 5 13:06:23 PDT 2023


I'm right now trying to understand every LayoutMorph example from the LayoutMorph's class side and making the math with pen and paper to create an accurate model. (Using the power of the scientific method. :-)) The examples contain proportional sizing examples for all three cases where proportions add up to less than one, to one and more than one.

This code is from the exampe1b
> row := LayoutMorph newRow name: #Row1.
> row
> color: Color red;
> addMorph: (BoxedMorph new color: (Color h: 60 s: 0.6 v: 0.6); name: #A)
> layoutSpec: (LayoutSpec fixedWidth: 10); 
> addMorph: (ImageMorph new name: #B);
> addMorph: (BoxedMorph new color: (Color h: 30 s: 0.6 v: 0.6); name: #C)
> layoutSpec: (LayoutSpec proportionalWidth: 0.4);
> addMorph: (BoxedMorph new color: (Color h: 30 s: 0.6 v: 0.6); name: #D)
> layoutSpec: (LayoutSpec proportionalWidth: 0.15);
> addMorph: (BoxedMorph new color: (Color h: 60 s: 0.6 v: 0.6); name: #E)
> layoutSpec: (LayoutSpec fixedWidth: 20 fixedHeight: 20).
> pane addMorph: row layoutSpec: LayoutSpec useAll.
I think what is happening is this in the X direction:
 • The outer LayoutMorph extent is defined later in the code as 400 at 300
 • The outer LayoutMorph has 5 point separation, so the inner LayoutMorph (Row1) has 390 point to lay itself out in the X direction
 • The dynamically allocated proportions are: 0.4 for C, 0.15 for D in the X direction
 • The statically allocated X values are: 10 points for A, 85 pints for B and 20 for E
 • So the dynamically allocatable area is: 390-10-85-20 = 275
 • C's X dimenson is 275x0.4 = 110 and 275x0.15=41.25 is D's. And inspecting the two morphs' sizes supports my model. Because the proportionally allocated area's ratio in total is less than one we get empty space. This is why in the first row is only partially filled up. In the second row of this example the proportions add up to 1 so the row is filed up. 
 • In the example1 method's first Row1 LayoutMorph's ratios add up to 1.35 so in this case the proportions in percent will be: 59,2% (0.8/1.35) for B,  29,6% (0.4/1.35) and 11,1% (0.15/1.35) for C. And these proportions looks correct doing the math and comparing to the inspector.

But the most simple disproof about the proportions should be 1 in total is the initialize method of LayoutSpec. It will set the proportional ratios 1.0. So if we have 2 submorphs initialized this way we will have the combined ratios of 2 in total.  And the submorphs will have 50% (1/2) of the total area. 

Maybe there is some kine of cognitive bias when we see numbers between 0 and 1 to interpret them directly as percentage. Because my first instinct also was that they need to add up to 1. But I tested with e.g. 500 as proportional ratio and it also works. Almost certainly there is normalization regarding the proportional ratios.

Regards,
Szabolcs


On Sat, Aug 5, 2023, at 20:05, Hilaire Fernandes via Cuis-dev wrote:
> Your proportional should add up to 1, otherwise the system will make a choice for you. Here it chooses to have no void, and reallocate the free space proportionally.
> 
> It is my interpretation.
> 
> Nevertheless, you should not meet a situation when you do not add up to 1. Why have unused space in a layout? Space screen is expensive.
> 
> If you want to trick the system you can add transparent morph:
> 
> |l b1 b2 t |
> l := *LayoutMorph* *newColumn* .
> b1 := *BoxedMorph* new *layoutSpec:* (*LayoutSpec* *proportionalHeight:* *0.1*) :: *color:* *Color* *green*.
> b2 := *BoxedMorph* new *layoutSpec:* (*LayoutSpec* *proportionalHeight:* *0.1*) :: *color:* *Color* *red*.
> t := *BoxedMorph* new *layoutSpec:* (*LayoutSpec* *proportionalHeight:* *0.8*) :: *color:* *Color* *transparent* .
> l *addMorph:* b1.
> l *addMorph:* t.
> l *addMorph:* b2.
> l *openInWorld*. 
> 
> 
> 
> 
> 
> Le 05/08/2023 à 17:31, Szabolcs Komáromi via Cuis-dev a écrit :
>> Hi,
>> 
>> Shouldn't this code produce a morph with a green and red box inside the gray box at the gray box's top edge? And the red and green box should have a height 10% of the gray box's height? Every other direction works that way.
>> 
>> Or I don't understand something fundamental about laying out morphs. The furthermost Workspace's morph looks wrong to me.
> -- 
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230805/3f6f4b5b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 25790 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230805/3f6f4b5b/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 125743 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230805/3f6f4b5b/attachment-0003.png>


More information about the Cuis-dev mailing list