[Newbies] Morphic layout: Proportional centering of cells

Nicola Mingotti nmingotti at gmail.com
Sun Sep 8 09:33:08 UTC 2019


ook, this is what i did to solve your problem.

I defined a class CenteringMorph. It is simply a rectangle which has a 
'son' element, it  keeps the 'son' always in its center.

Then, you put  CenteringMorph instances in the TableLayout, and let them 
expand to eat all the available space.

The class CenteringMorph is defined in this Package:
http://www.squeaksource.com/MorphicAddendum.html

Look in the CenteringMorph class documentation to see how to run the 
example.

bye
Nicola






On 9/7/19 12:35 AM, Thiede, Christoph wrote:
>
> Thank you for your answer.
>
>
> Actually, I chose TextMorphs as an example for a non-scalable morph. 
> It is interesting to hear that SimpleButtons center themselves, but 
> how could I achieve the same for, let me say, two ImageMorphs?
>
>
>
>
> Best,
>
> Christoph
>
> ------------------------------------------------------------------------
> *Von:* Nicola Mingotti <nmingotti at gmail.com>
> *Gesendet:* Samstag, 7. September 2019 00:24:16
> *An:* A friendly place to get answers to even the most basic questions 
> about Squeak.; Thiede, Christoph
> *Betreff:* Re: [Newbies] Morphic layout: Proportional centering of cells
>
> I guess you are looking from something like this:
>
> note: the ButtonMorph is the only one that by default put the
> text in center of its geometry. StringM and TextM do not.
>
> ========================
>
> m := RectangleMorph new.
> m openInWorld.
> m extent: 300 at 300; position: 100 at 100.
>
> m layoutPolicy: TableLayout new.
> m listDirection: #topToBottom.   "default, place elements as rows in a 
> table."
> m listCentering: #topLeft.
> m layoutInset: 5.   "space to container morph."
> m cellInset: 5 at 5. "Space between table cells."
> m hResizing: #spaceFill.
> m vResizing: #spaceFill.
> m color: (Color yellow darker darker darker).
>
> t1 := SimpleButtonMorph new.
> t1 openInWorld.
> t1 color: ((Color green) lighter lighter lighter) .
> t1 borderColor: (Color black).
> t1 borderWidth: 2.
> t1 hResizing: #spaceFill.
> t1 vResizing: #spaceFill.
> m addMorphBack: t1.
>
> t2 := SimpleButtonMorph new.
> t2 openInWorld.
> t2 color: ((Color yellow) lighter lighter lighter) .
> t2 borderColor: (Color black).
> t2 borderWidth: 2.
> t2 hResizing: #spaceFill.
> t2 vResizing: #spaceFill.
> m addMorphBack: t2.
>
> ========================
>
>
> On 9/6/19 6:22 AM, Thiede, Christoph wrote:
>>
>> Hi,
>>
>>
>> I am probably not seeing the wood for the trees: How can I achieve 
>> the following situation? When the layout changes, both texts should 
>> keep their center relative to their owner's bounds:
>>
>>
>>
>>
>> If I use a ProportionalLayout, I can position the TextMorphs at the 
>> offsets 0.5 at 0.25 and 0.5 at 0.75, but only with their upper left corner, 
>> so they will not really be centered.
>>
>> If I use a TableLayout, I can center the TextMorphs at the top and 
>> the bottom using #listCentering:. However, I cannot center each 
>> morph relative to one vertical halft of the owner.
>>
>> How can I stretch both cells to half the height of the morph? I also 
>> experimented with #cellSpacing: but still did not achieve the desired 
>> layout. (Also, I did not found any senders of the property in the image.)
>>
>>
>> Of course, I could use two auxiliary morphs which are arranged using 
>> a ProportionalLayout and each contain one text as a centered cell 
>> (with #listCentering: and #wrapCentering:). But for me, this feels a 
>> quite heavy solution for such a simple problem. Or is this the only 
>> way to go?
>>
>>
>> Thanks in advance,
>>
>> Christoph
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/beginners/attachments/20190908/5fa54702/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 3785 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/beginners/attachments/20190908/5fa54702/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 5762 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/beginners/attachments/20190908/5fa54702/attachment-0003.png>


More information about the Beginners mailing list