AlignmentMorph and TextMorph

Andrew C. Greenberg werdna at gate.net
Sun Dec 27 05:01:11 UTC 1998


> I'm trying to create a row on a pane with a left justified name, some 
> space and a right justified
> number.
>
> I created the row as follows:
>
>     aRow := AlignmentMorph newRow color: aColor.
>     aRow
>         addMorph: (TextMorph new contents: aName);
>         addMorphBack: (AlignmentMorph newSpacer: Color transparent);
>         addMorphBack: (TextMorph new contents: aNumber printString).
>
> Everything displays correctly, but:
>
>     - Why is the first submorph left justified and the last one right 
> justified?
>     - Why does the first submorph allow editing and the last one doesn't?
>     - How can I prevent editing?  I want display only.  I tried to use 
> StringMorph's but
>         after much experimentation with wrapping in AlignmentMorphs, I 
> trimmed
>         the example down to this.
>
> Thanks - I'm finally trying to learn Morphic so I can teach a 14 year old...
> -david



Actually, I think you wanted to start with a StringMorph.

Forgive me if the following isn't the most elegant solution.  I'm a 
Smalltalk newbie, and have no Morphic documentation, with perhaps too-deep 
a background using TeX-style boxes.

I think you may be thinking about this somewhat sideways about the problem. 
It is difficult to meaningfully define the terms "left justification" or 
"right justification" without first specifying a fixed width in which the 
text is to appear.  All text in a variable length field is simultaneously 
left, center and right-justified.  Thus, you first need to create fixed 
length areas in which to have your text displayed.

So, start by thinking about putting a single StringMorph into an 
AlighnmentMorph, setting the AlignmentMorph's extents to your desired 
width, the orientation to vertical, the centering to #topLeft, #center, or 
#bottomRight as appropriate, and you have a nice field with the specified 
text appropriately justified in the sepcified width.

You would make two such combinations: One for the text and one for the 
number.  Then, you could combine them into a horizontally oriented 
AlignmentMorph to get the desired effect.  The result looks something like 
this:

+---- One external Horizontal AlignmentMorph --- . . .     . . .  ----+
|+------------------+ +---------------------+ +----------------------+|
||topLeft string    | | spacer              | |      bottomRight num ||
|+------------------+ +---------------------+ +----------------------+|
+---- , , , 			^			   . . .  ----+
				|
				+ 3 internal vertical AlignmentMorphs

This should do the trick -- messing around in a MorphWorld, while diddling 
the parameters in inspectors, this appeared to do just the trick.





More information about the Squeak-dev mailing list