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
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.
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?
It isn't. Neither is "justified," as I noted in my previous message. What you saw was three "fields," fully filled without padding, and all abutted one to another to make up the aggregate morph. Text is always simultaneously left, center and right justified in a field that is exactly the width of the text. Running your code and inspecting the results with an inspector confirms this:
|aWorld | aWorld _ WorldMorph new initialize. aRow := AlignmentMorph newRow color: aColor. aRow addMorph: (TextMorph new contents: 'hellothere'); addMorphBack: (AlignmentMorph newSpacer: Color transparent); addMorphBack: (TextMorph new contents: (12323 printString)). aWorld addMorph: aRow. aWorld openWithTitle: 'test'.
bounds: 54@46 corner: 112@62 112@46 corner: 114@82 114@46 corner: 126@62 owner: an AlignmentMorph(1871) an AlignmentMorph(1871) an AlignmentMorph(1871) submorphs: () () () fullBounds: 54@46 corner: 112@62 112@46 corner: 114@82 114@46 corner: 126@62 color: (Color r: 0.0 g: 0.0 b: 0.0) (Color r: 0.0 g: 0.0 b: 0.0) (Color transparent) extension: nil nil nil textStyle: a TextStyle NewYork10 a TextStyle NewYork10 text: Text for 'hellothere' Text for '23'
Both TextStyles had alignment set to 0, "left justification".
The resulting morph looked like this:
+---------------------+ |+-----------++--++--+| ||hello there|| ||23|| |+-----------+| |+--+| | | | | | +--+ | +---------------------+
- Why does the first submorph allow editing and the last one doesn't?
I have no idea. I confirm that the second field is not editable, and defer to those who actually know how this stuff works to explain why this should be so.
squeak-dev@lists.squeakfoundation.org