How to center a submorph in its owner morph?

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

How to center a submorph in its owner morph?

Hannes Hirzel
Hello

I want to add an instance of ImageMorph to an instance of  Morph and
center it there?

How do I do that?

I have done experiments with newRow and newColumn layout, see
  https://github.com/hhzl/Cuis-Add-Ons

But I do not have examples yet of centering.

Thank you for the answer in advance.

Hannes

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Juan Vuletich-4
Hi Hannes,

Something like:

| row |
row := LayoutMorph newRow.
row
     color: Color green;
     addMorph: (BorderedRectMorph new color: (Color h: 60 s: 0.6 v: 0.6)).
row padding: #center.
row openInWorld.
row morphPosition: 150@130

If you use a Column and not a Row, you don't even need to specify the
#padding:, as it defaults to #center.

Cheers,
Juan Vuletich

On 2/7/2013 12:32 PM, H. Hirzel wrote:

> Hello
>
> I want to add an instance of ImageMorph to an instance of  Morph and
> center it there?
>
> How do I do that?
>
> I have done experiments with newRow and newColumn layout, see
>    https://github.com/hhzl/Cuis-Add-Ons
>
> But I do not have examples yet of centering.
>
> Thank you for the answer in advance.
>
> Hannes
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>
>
> -----
> Se certifico que el correo no contiene virus.
> Comprobada por AVG - www.avg.es
> Version: 2013.0.2897 / Base de datos de virus: 2639/6087 - Fecha de la version: 07/02/2013
>
>


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Hannes Hirzel
Works fine, thank you, Juan

--Hannes

On 2/8/13, Juan Vuletich <[hidden email]> wrote:

> Hi Hannes,
>
> Something like:
>
> | row |
> row := LayoutMorph newRow.
> row
>      color: Color green;
>      addMorph: (BorderedRectMorph new color: (Color h: 60 s: 0.6 v: 0.6)).
> row padding: #center.
> row openInWorld.
> row morphPosition: 150@130
>
> If you use a Column and not a Row, you don't even need to specify the
> #padding:, as it defaults to #center.
>
> Cheers,
> Juan Vuletich
>
> On 2/7/2013 12:32 PM, H. Hirzel wrote:
>> Hello
>>
>> I want to add an instance of ImageMorph to an instance of  Morph and
>> center it there?
>>
>> How do I do that?
>>
>> I have done experiments with newRow and newColumn layout, see
>>    https://github.com/hhzl/Cuis-Add-Ons
>>
>> But I do not have examples yet of centering.
>>
>> Thank you for the answer in advance.
>>
>> Hannes
>>
>> _______________________________________________
>> Cuis mailing list
>> [hidden email]
>> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>>
>>
>> -----
>> Se certifico que el correo no contiene virus.
>> Comprobada por AVG - www.avg.es
>> Version: 2013.0.2897 / Base de datos de virus: 2639/6087 - Fecha de la
>> version: 07/02/2013
>>
>>
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Juan Vuletich-4
In reply to this post by Hannes Hirzel
Hi Hannes,

Played a bit with your layout examples. This is great stuff! Very nice
demos, showing what can be done with so little code. This is great for
those who are afraid of doing GUIs!

Just a comment. In LayoutDemo3c, send #actualContents: and not
#contents:. In addition, for proper display update, in
TextModelMorph>>#update:, in the #actualContents branch, before exiting,
do 'self redrawNeeded.'. I'll add this patch tonight.

Cheers,
Juan Vuletich

On 2/7/2013 12:32 PM, H. Hirzel wrote:

> Hello
>
> I want to add an instance of ImageMorph to an instance of  Morph and
> center it there?
>
> How do I do that?
>
> I have done experiments with newRow and newColumn layout, see
>    https://github.com/hhzl/Cuis-Add-Ons
>
> But I do not have examples yet of centering.
>
> Thank you for the answer in advance.
>
> Hannes
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>
>
> -----
> Se certifico que el correo no contiene virus.
> Comprobada por AVG - www.avg.es
> Version: 2013.0.2897 / Base de datos de virus: 2639/6087 - Fecha de la version: 07/02/2013
>
>


_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Hannes Hirzel
Hello Juan

Thank you for the code snippet which shows how to center a submorph,
It works fine, see attached screen shot.

The code is in
https://github.com/hhzl/Cuis-Add-Ons
but it needs the examples from
https://github.com/hhzl/ContentPack (loads slowly as it contains 26 pictures)

On 2/8/13, Juan Vuletich <[hidden email]> wrote:
> Hi Hannes,
>
> Played a bit with your layout examples. This is great stuff! Very nice
> demos, showing what can be done with so little code.

Thank you.

This is great for
> those who are afraid of doing GUIs!

Yes, indeed. I plan to extend it. The notebook morph might be better
done with a listbox taking the first line of the text as the title.

> Just a comment. In LayoutDemo3c, send #actualContents: and not
> #contents:. In addition, for proper display update, in
> TextModelMorph>>#update:, in the #actualContents branch, before exiting,
> do 'self redrawNeeded.'. I'll add this patch tonight.

Thank you for the code review, the analysis and the solution. It works
fine now with the recommended fix.
Amazing that you can do a tab type of GUI which holds editable texts
with just 5 instance methods.

Regards
Hannes


> Cheers,
> Juan Vuletich
>
> On 2/7/2013 12:32 PM, H. Hirzel wrote:
>> Hello
>>
>> I want to add an instance of ImageMorph to an instance of  Morph and
>> center it there?
>>
>> How do I do that?
>>
>> I have done experiments with newRow and newColumn layout, see
>>    https://github.com/hhzl/Cuis-Add-Ons
>>
>> But I do not have examples yet of centering.
>>
>> Thank you for the answer in advance.
>>
>> Hannes
>>
>> _______________________________________________
>> Cuis mailing list
>> [hidden email]
>> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>>
>>
>> -----
>> Se certifico que el correo no contiene virus.
>> Comprobada por AVG - www.avg.es
>> Version: 2013.0.2897 / Base de datos de virus: 2639/6087 - Fecha de la
>> version: 07/02/2013
>>
>>
>
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org

ABCbook.png (317K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Hannes Hirzel
In reply to this post by Juan Vuletich-4
Hello

I currently encounter some problems with Morph layout and I would like
to ask for help.

The code [1]  works fine in Cuis 4.1.

A slightly adapted version (just below) in Cuis 4.1 gives the morph as
shown in file
Cuis4.1-green-LayoutMorph-with-red-BorderedMorph

| row b |
row := LayoutMorph newRow.
b := BorderedRectMorph new color: Color red.
b morphExtent: 120@120.
row
    color: Color green;
    addMorph: b.
row padding: #center.
row morphExtent:  200 @ 200.
row morphPosition: 150@130.
row openInWorld.
b inspect

However the extent of morph b is wrong. After setting it manually in
the inspector it looks as shown in picture 'Cuis4.1-green-red120.png'.
This means setting the extent works here.

In Cuis 4.2 the result of the same code looks as shown in the picture
'Cuis4.2-initial.jpeg'.

And it refuses to resize the morph b even if done manually.

Any suggestions to help to fix these bugs are welcome.

Regards
Hannes



[1]
On 2/8/13, Juan Vuletich <[hidden email]> wrote:

> Hi Hannes,
>
> Something like:
>
> | row |
> row := LayoutMorph newRow.
> row
>      color: Color green;
>      addMorph: (BorderedRectMorph new color: (Color h: 60 s: 0.6 v: 0.6)).
> row padding: #center.
> row openInWorld.
> row morphPosition: 150@130
>
> If you use a Column and not a Row, you don't even need to specify the
> #padding:, as it defaults to #center.
>
> Cheers,
> Juan Vuletich
>
> On 2/7/2013 12:32 PM, H. Hirzel wrote:
>> Hello
>>
>> I want to add an instance of ImageMorph to an instance of  Morph and
>> center it there?
>>
>> How do I do that?
>>
>> I have done experiments with newRow and newColumn layout, see
>>    https://github.com/hhzl/Cuis-Add-Ons
>>
>> But I do not have examples yet of centering.
>>
>> Thank you for the answer in advance.
>>
>> Hannes

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org

Cuis4.1-green-LayoutMorph-with-red-BorderedMorph (1K) Download Attachment
Cuis4.1-green-red120.png (1K) Download Attachment
Cuis4.2-initial.jpeg (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Hannes Hirzel
The solution:

LayoutMorph>>addMorph:

attaches as default LayoutSpec a

   LayoutSpec new

which uses all the available space.

LayoutSpec>>initialize

initialize
        "Just some reasonable defaults, use all available space"
        minorDirectionPadding _ 0.5.
        fixedWidth _ 0.
        fixedHeight _ 0.
        proportionalWidth _ 1.0.
        proportionalHeight _ 1.0



So the fix is to go for

#addMorph:layoutSpec:

with a layoutSpec of

   LayoutSpec keepMorphExtent.


The whole script

| row |
row := LayoutMorph newRow.
row
    color: Color green;
    addMorph: (BorderedRectMorph new color: (Color red); morphExtent: 150@ 150)
    layoutSpec: LayoutSpec keepMorphExtent.
row padding: #center.
row morphExtent:  300 @ 300.
row openInWorld.
row morphPosition: 150@130



On 1/1/14, H. Hirzel <[hidden email]> wrote:

> Hello
>
> I currently encounter some problems with Morph layout and I would like
> to ask for help.
>
> The code [1]  works fine in Cuis 4.1.
>
> A slightly adapted version (just below) in Cuis 4.1 gives the morph as
> shown in file
> Cuis4.1-green-LayoutMorph-with-red-BorderedMorph
>
> | row b |
> row := LayoutMorph newRow.
> b := BorderedRectMorph new color: Color red.
> b morphExtent: 120@120.
> row
>     color: Color green;
>     addMorph: b.
> row padding: #center.
> row morphExtent:  200 @ 200.
> row morphPosition: 150@130.
> row openInWorld.
> b inspect
>
> However the extent of morph b is wrong. After setting it manually in
> the inspector it looks as shown in picture 'Cuis4.1-green-red120.png'.
> This means setting the extent works here.
>
> In Cuis 4.2 the result of the same code looks as shown in the picture
> 'Cuis4.2-initial.jpeg'.
>
> And it refuses to resize the morph b even if done manually.
>
> Any suggestions to help to fix these bugs are welcome.
>
> Regards
> Hannes
>
>
>
> [1]
> On 2/8/13, Juan Vuletich <[hidden email]> wrote:
>> Hi Hannes,
>>
>> Something like:
>>
>> | row |
>> row := LayoutMorph newRow.
>> row
>>      color: Color green;
>>      addMorph: (BorderedRectMorph new color: (Color h: 60 s: 0.6 v:
>> 0.6)).
>> row padding: #center.
>> row openInWorld.
>> row morphPosition: 150@130
>>
>> If you use a Column and not a Row, you don't even need to specify the
>> #padding:, as it defaults to #center.
>>
>> Cheers,
>> Juan Vuletich
>>
>> On 2/7/2013 12:32 PM, H. Hirzel wrote:
>>> Hello
>>>
>>> I want to add an instance of ImageMorph to an instance of  Morph and
>>> center it there?
>>>
>>> How do I do that?
>>>
>>> I have done experiments with newRow and newColumn layout, see
>>>    https://github.com/hhzl/Cuis-Add-Ons
>>>
>>> But I do not have examples yet of centering.
>>>
>>> Thank you for the answer in advance.
>>>
>>> Hannes
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

KenDickey
In reply to this post by Hannes Hirzel
Hannes,

Sorry, I don't have time to read the code right now. 8^(

But the following code might be of help..

Morph>>referencePosition
        "Return the current reference position of the receiver"
        "a rather ugly way to say #center . At least, we avoid false polymorphism"
        "remove some day"
        self flag: #jmvVer2.
        ^self morphExtentInWorld // 2 + self morphPositionInWorld

-KenD

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
-KenD
Reply | Threaded
Open this post in threaded view
|

Re: How to center a submorph in its owner morph?

Hannes Hirzel
Ken

you do not need to read the code anymore. I found the solution.

I have to use

#addMorph:layoutSpec:

with a layoutSpec of

   LayoutSpec keepMorphExtent.


--hjh

On 1/1/14, Ken Dickey <[hidden email]> wrote:

> Hannes,
>
> Sorry, I don't have time to read the code right now. 8^(
>
> But the following code might be of help..
>
> Morph>>referencePosition
> "Return the current reference position of the receiver"
> "a rather ugly way to say #center . At least, we avoid false polymorphism"
> "remove some day"
> self flag: #jmvVer2.
> ^self morphExtentInWorld // 2 + self morphPositionInWorld
>
> -KenD
>
> _______________________________________________
> Cuis mailing list
> [hidden email]
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>

_______________________________________________
Cuis mailing list
[hidden email]
http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org