[squeak-dev] Morphic layout

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

[squeak-dev] Morphic layout

Mark Volkmann
I'm trying to learn basic Morphic.  Can someone tell me why the following code
results in buttons labelled 1 through 4 from right to left instead of left to
right?  Any comments about this code are welcomed!

        | panel |

        panel := Morph new.
        panel
                layoutPolicy: TableLayout new;
                listDirection: #leftToRight;
                hResizing: #shrinkWrap;
                vResizing: #shrinkWrap;
                layoutInset: 30;
                cellInset: 10.

        "Why are buttons added in reverse order?"
        (1 to: 4) do: [:i |
                | button |
                button := PluggableButtonMorph
                        on: [Transcript show: 'pressed'; cr]
                        getState: nil
                        action: #value.
                "Why is the color ignored?"
                button color: Color yellow; label: 'Button #', i asString.
                panel addMorph: button
        ].

        panel openInWindowLabeled: 'Mark''s Morphic Demo'

--
R. Mark Volkmann
Object Computing, Inc.

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Morphic layout

Antony Blakey-3
Use addMorphBack: rather than addMorph:

On 17/10/2008, at 12:38 PM, R. Mark Volkmann wrote:

> I'm trying to learn basic Morphic.  Can someone tell me why the  
> following code
> results in buttons labelled 1 through 4 from right to left instead  
> of left to
> right?  Any comments about this code are welcomed!
>
> | panel |
>
> panel := Morph new.
> panel
> layoutPolicy: TableLayout new;
> listDirection: #leftToRight;
> hResizing: #shrinkWrap;
> vResizing: #shrinkWrap;
> layoutInset: 30;
> cellInset: 10.
>
> "Why are buttons added in reverse order?"
> (1 to: 4) do: [:i |
> | button |
> button := PluggableButtonMorph
> on: [Transcript show: 'pressed'; cr]
> getState: nil
> action: #value.
> "Why is the color ignored?"
> button color: Color yellow; label: 'Button #', i asString.
> panel addMorph: button
> ].
>
> panel openInWindowLabeled: 'Mark''s Morphic Demo'

Antony Blakey
-------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787

Some defeats are instalments to victory.
   -- Jacob Riis



Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Morphic layout

Andreas.Raab
In reply to this post by Mark Volkmann
R. Mark Volkmann wrote:
> I'm trying to learn basic Morphic.  Can someone tell me why the following code
> results in buttons labelled 1 through 4 from right to left instead of left to
> right?  Any comments about this code are welcomed!

The buttons are right to left because by default morphs are added to the
front (first) and the layout computes left-to-right. As a consequence,
you need to use #addMorphBack: to include the morph to the right.

Cheers,
   - Andreas


> | panel |
>
> panel := Morph new.
> panel
> layoutPolicy: TableLayout new;
> listDirection: #leftToRight;
> hResizing: #shrinkWrap;
> vResizing: #shrinkWrap;
> layoutInset: 30;
> cellInset: 10.
>
> "Why are buttons added in reverse order?"
> (1 to: 4) do: [:i |
> | button |
> button := PluggableButtonMorph
> on: [Transcript show: 'pressed'; cr]
> getState: nil
> action: #value.
> "Why is the color ignored?"
> button color: Color yellow; label: 'Button #', i asString.
> panel addMorph: button
> ].
>
> panel openInWindowLabeled: 'Mark''s Morphic Demo'
>