TextMorph takes to much space in layout

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

TextMorph takes to much space in layout

r2ruyu-nana
Hello squeaker!

A TextMorph takes to much space in a table layout:

        parent := Morph new color: Color yellow.
        parent
                changeTableLayout;
                vResizing: #shrinkWrap;
                hResizing: #spaceFill;
                extent: 400@300.
       
        w := TextMorph new contentsWrapped: 'Some very very very very long
string...'.
        w
                "width: 300;"
                backgroundColor: Color veryLightGray;
                hResizing: #spaceFill.

        parent
                addMorphBack: (Morph new color: Color red);
                addMorphBack: w;
                addMorphBack: (Morph new color: Color blue).
        parent openInWorld.

        "w layoutChanged."

But doing 'w layoutChanged' afterwards everything is fine again. It has
something to do with the default extent of the TextMorph. If you're
uncommenting the width-line there will be less space below the TextMorph.
Also, everything if fine without the hReszing:#spaceFill of the TextMorph...

How to get it right from the beginning on? Without doing explicitly 'w
layoutChanged'.

Best regards,
   r2ruyu

Reply | Threaded
Open this post in threaded view
|

Re: TextMorph takes to much space in layout

Sean P. DeNigris
Administrator
r2ruyu-nana wrote
How to get it right from the beginning on? Without doing explicitly 'w layoutChanged'.
Welcome! And welcome to the esoteric arts of Morphic layout. I find this to be by far the most mind-boggling area of the image. You actually got away easy with the layoutChanged trick.

r2ruyu-nana wrote
                "width: 300;"
                backgroundColor: Color veryLightGray;
                hResizing: #spaceFill.
The last line is your problem. You're specifically telling the TextMorph to fill the horizontal space. However, if you change it to #rigid, you will not be any happier because the text will be all scrunched up vertically. However, if you pair #rigid with #contents: instead of contentsWrapped:

                TextMorph new contents: 'Some very very very very long string...'.

you will have the same size as after layoutChanged without the explicit width: setting.

HTH,
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: TextMorph takes to much space in layout

r2ruyu-nana
Thank you for your answer!

You addressed the layoutChanged problem, but isn't there a way to make
TextMorph behave like an ordinary Morph concerning hResizing:#spaceFill? I
don't want a fixed width.

In case there is no such way, what would be a nice method to encapsulate the
layoutChanged call? I've a complex morph with many submorphs arranged, and now
I would need to 'openInWorld' that big widget and get a reference to all
TextMorphs to call layoutChanged for them in order to adapt the parent
widgets...that's not nice :(

Another possible, but ugly solution which came into my mind: calling
aTextMorph #contents:#wrappedTo: in the step method of the TextMorph (or my
subclass of it) using the width of the parent (if parent is not nil).

Sincerely,
   r2ruyu

On Sunday 14 August 2011 13:59:05 Sean P. DeNigris wrote:

> r2ruyu-nana wrote:
> > How to get it right from the beginning on? Without doing explicitly 'w
> > layoutChanged'.
>
> Welcome! And welcome to the esoteric arts of Morphic layout. I find this to
> be by far the most mind-boggling area of the image. You actually got away
> easy with the layoutChanged trick.
>
> r2ruyu-nana wrote:
> > "width: 300;"
> > backgroundColor: Color veryLightGray;
> > hResizing: #spaceFill.
>
> The last line is your problem. You're specifically telling the TextMorph to
> fill the horizontal space. However, if you change it to #rigid, you will
> not be any happier because the text will be all scrunched up vertically.
> However, if you pair #rigid with #contents: instead of contentsWrapped:
>
> TextMorph new contents: 'Some very very very very long string...'.
>
> you will have the same size as after layoutChanged without the explicit
> width: setting.
>
> HTH,
> Sean
>
> --
> View this message in context:
> http://forum.world.st/TextMorph-takes-to-much-space-in-layout-tp3741528p37
> 42760.html Sent from the Squeak - Dev mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: TextMorph takes to much space in layout

Sean P. DeNigris
Administrator
r2ruyu-nana wrote
isn't there a way to make TextMorph behave like an ordinary Morph concerning hResizing:#spaceFill?
That's what your first try was doing. The TextMorph was exhibiting the regular #spaceFill behavior, namely filling the entire horizontal space.

I'm not sure what you're asking, but if you mean "how do I get a margin between the outer edge of the parent morph and the TextMorph?" there are two options I can think of:
1) The easy one: add "layoutInset: 20" to the cascade after "extent: 400@300", which will put a margin around all the submorphs (not just the TextMorph)
2) More involved, but more flexible: put the TextMorph inside a morph with hResizing: #spaceFill and layoutPolicy: ProportionalLayout new. Then you can have fine-grained control over the space on all sides of the TextMorph e.g. margin only on the right, etc.

There are some good examples that you can execute on the Swiki. Google "how to layout submorphs".

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: TextMorph takes to much space in layout

r2ruyu-nana
Hello again!

To my mind we're talking at cross-purposes. Sorry for the misconception!

On Sunday 14 August 2011 21:57:02 Sean P. DeNigris wrote:
> r2ruyu-nana wrote:
> > isn't there a way to make TextMorph behave like an ordinary Morph
> > concerning hResizing:#spaceFill?
>
> That's what your first try was doing. The TextMorph was exhibiting the
> regular #spaceFill behavior, namely filling the entire horizontal space.

Indeed, the TextMorph fills the entire horizontal space, *but* it also takes
more vertical space than needed. Only after calling #layoutChanged (direct by
the call, or indirect by typing sth. in the widgets) the vertical space
problem gets corrected and everything is fine.

Is there a way to fix the vertical space problem without calling
#layoutChanged?

Have a nice day!
   r2ruyu :)