[Cuis-dev] LayoutMorph subclass instance #beColumn has not effect

Alexandre Rousseau yalexr at gmail.com
Mon Mar 13 17:47:24 PDT 2023


Hmmm. I thought I was. But this still results in a row alignment:

initialize
>   super initialize.
>   self
>     addMorph: (BoxedMorph new :: color: Color red);
>     addMorph: (BoxedMorph new :: color: Color green);
>     addMorph: (BoxedMorph new :: color: Color blue);
>     beColumn.


But indeed adding:

> MyLayoutMorphSubclass class>>new
>     ^ self newColumn

fixes everything.

Cheers
A.


On Mon, Mar 13, 2023 at 8:40 PM Alexandre Rousseau <yalexr at gmail.com> wrote:

> Thanks for that nuance Mariano. And I'm back in business. :)
>
> On Mon, Mar 13, 2023 at 7:38 PM Mariano Montone <marianomontone at gmail.com>
> wrote:
>
>> El 13/3/23 a las 20:29, Alexandre Rousseau escribió:
>>
>> Hi Hilaire and Mariano,
>>
>>  Most of the time, you don't need to subclass LayoutMorph, unless you
>>> want to define new sort of complex widget.
>>
>>
>> What distinguishes a complex widget from their counterparts? In my case,
>> here is a screenshot of work in progress... a sampling of widgets placed on
>> a PasteUpMorph instance. Each of those widgets extends LayoutMorph class. I
>> could have had them be a subclass of BoxedMorph (or placedMorph) but, given
>> that the widgets I want to use all lay out their components in vertical
>> order, I thought extending LayoutMorph made more sense. If not, then I
>> would have to embed a layout morph as top level submorph in each of them,
>> then embedding further submorphs inside of that.
>>
>> Yes that's fine way of doing it.
>>
>> About the #beColumn initialization, this is the implementation:
>>
>> beColumn
>>     "Establish the major layout axis, with default edge weight"
>>
>>     direction := #vertical.
>>     axisEdgeWeight ifNil: [self axisEdgeWeight: #center].
>>     self layoutSubmorphs.
>>
>>
>> It sets parameters and calls #layoutSubmorphs.
>>
>> So, the issue in your initialization method was that you were calling
>> #beColumn before adding the submorphs, and #layoutSubmorphs was not called
>> after that, so there's no effect in layout.
>>
>>
>>      Mariano
>>
>>
>>
>> So, if I gather correctly, the following would be more idiomatic. Please
>> correct me if I'm wrong (and thanks again!) :
>>
>>> initialize
>>> | lo |
>>>   super initialize.
>>>   lo LayoutMorph newColumn.
>>>   lo
>>>     addMorph: (BoxedMorph new color: Color red; yourself);
>>>     addMorph: (BoxedMorph new color: Color green; yourself);
>>>     addMorph: (BoxedMorph new color: Color blue; yourself).
>>>   self addMorph: lo.
>>>   self morphExtent: `40 at 120`.
>>
>>
>> A.
>> [image: Screenshot 2023-03-13 at 7.28.53 PM.png]
>>
>>
>> On Mon, Mar 13, 2023 at 6:53 PM Mariano Montone <marianomontone at gmail.com>
>> wrote:
>>
>>> I got it wrong. Seems that row layout layouts things horizontally, and
>>> column vertically.
>>>
>>> As Hilaire mentioned, unless you want to define your own layout
>>> algorithm, the idea is to use the layout morphs, not subclass from them.
>>>
>>> Layouts in a column (vertically):
>>>
>>> LayoutMorph newColumn ::
>>>         addMorph: (BoxedMorph new color: Color red; yourself);
>>>         addMorph: (BoxedMorph new color: Color green; yourself);
>>>         addMorph: (BoxedMorph new color: Color blue; yourself);
>>>         openInWorld.
>>>
>>> Layouts in a row (horizontally):
>>>  LayoutMorph newRow ::
>>>         addMorph: (BoxedMorph new color: Color red; yourself);
>>>         addMorph: (BoxedMorph new color: Color green; yourself);
>>>         addMorph: (BoxedMorph new color: Color blue; yourself);
>>>         openInWorld.
>>>
>>>     Mariano
>>>
>>> El 13/3/23 a las 18:30, Alexandre Rousseau escribió:
>>>
>>> You may want to try with #beRow if you want submorphs to align
>>>> vertically (in rows).
>>>
>>>
>>> Hmm... I'm not sure about this.
>>>
>>> I've attached the filed-out test class to this email, if you want to
>>> take a closer look.
>>>
>>> Basically it is a LayoutMorph subclass, initialized as:
>>>>
>>>> initialize
>>>> | b1 b2 b3 |
>>>
>>> super initialize.
>>>> self beRow.
>>>> b1 BoxedMorph new :: color: Color red.
>>>> b2 BoxedMorph new :: color: Color green.
>>>> b3 BoxedMorph new :: color: Color blue.
>>>> self addMorph: b1.
>>>> self addMorph: b2.
>>>> self addMorph: b3.
>>>> self morphExtent: self minimumExtent.
>>>
>>> and the instantiation of which results in this (attached image 1).
>>>
>>> [image: image1.png]
>>> [image: image 2.png]
>>> Changing line 4 to "self beColumn" does not lay the items out
>>> vertically. See attached image 2.
>>>
>>>
>>>
>>> On Mon, Mar 13, 2023 at 4:01 PM marianomontone--- via Cuis-dev <
>>> cuis-dev at lists.cuis.st> wrote:
>>>
>>>> On 13/3/23 13:36, Alexandre Rousseau via Cuis-dev <
>>>> cuis-dev at lists.cuis.st> wrote:
>>>> > Defining a class as subclass of LayoutMorph and initializing it thus:
>>>> >
>>>> >     initialize
>>>> >        super initialize.
>>>> >        self beColumn.
>>>> >
>>>> >
>>>> > morphs added to it still appear next to each other, horizontally, as
>>>> if
>>>> > #beColumn was ignored.
>>>> >
>>>> > Is this expected behaviour for a subclass of LayoutMorph?
>>>>
>>>> I think it is. You may want to try with #beRow if you want submorphs to
>>>> align vertically (in rows).
>>>>
>>>>       Mariano
>>>> --
>>>> 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/20230313/8eb4dbbe/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2023-03-13 at 7.28.53 PM.png
Type: image/png
Size: 66778 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230313/8eb4dbbe/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image1.png
Type: image/png
Size: 4032 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230313/8eb4dbbe/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image 2.png
Type: image/png
Size: 5004 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230313/8eb4dbbe/attachment-0005.png>


More information about the Cuis-dev mailing list