Morphs with Spec2

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

Morphs with Spec2

Sebastian Jordan
Hi everyone,

I Want to use a StringMorph as a title of a UI created with Spec2. For that, I am using a SpMorhPresenter inside a SpPresenter. But the text inside the morph loses its format as it is shown in the attached image.
Does anyone knows how to solve this? What I am doing wrong?
It would be very appreciated. Thanks for your time.

Here is the code of the example:

defaultSpec
  ^ SpBoxLayout newVertical
    add: #morphLabel;
    add: #button1;
    add: #button2;
    yourself

initializePresenters
    morphLabel := self obtainSpMorphPresenterwithAStringMorph.
    button1 := self newButton.
    button1 label: 'Button one'.
    button2 := self newButton.
    button2 label: 'Button two'.
    self focusOrder
        add: morphLabel;
        add: button1;
        add: button2

obtainSpMorphPresenterwithAStringMorph
    | morph |
    morph := StringMorph
    contents: 'A String Morph'
    font:
        (LogicalFont
            familyName: Smalltalk ui theme labelFont familyName
            pointSize: Smalltalk ui theme labelFont pointSize + 10).
    ^ SpMorphPresenter new
    morph: morph;
    yourself

example.jpg (41K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Morphs with Spec2

EstebanLM
Hi,

1. Spec styles define a “default” font applied to all components (morphs in this case) that understand font, and if you want to change it you need to define your own style.
2. A string morph cannot center the string (this is a morphic stuff)

You can solve your problem by adding a PanelMorph instead a string:

obtainSpMorphPresenterwithAStringMorph
    | morph |
    morph := StringMorph
    contents: 'A String Morph'
    font:
        (LogicalFont
            familyName: Smalltalk ui theme labelFont familyName
            pointSize: Smalltalk ui theme labelFont pointSize + 10).
    ^ SpMorphPresenter new
    morph: (PanelMorph new 
addMorphBack: morph;
yourself);
    yourself


This will produce this morph: 



And since I hate morphic, I will let you to fight with morph to center your sub morph ;)

Esteban

On 18 Mar 2020, at 17:41, Sebastian Jordan <[hidden email]> wrote:


    button1 := self newButton.

Reply | Threaded
Open this post in threaded view
|

Re: Morphs with Spec2

Sven Van Caekenberghe-2
But I think he wants to know how he can use Spec2 to add a centred title.
That should be possible without falling back to older stuff, right ?

> On 19 Mar 2020, at 10:25, Esteban Lorenzano <[hidden email]> wrote:
>
> Hi,
>
> 1. Spec styles define a “default” font applied to all components (morphs in this case) that understand font, and if you want to change it you need to define your own style.
> 2. A string morph cannot center the string (this is a morphic stuff)
>
> You can solve your problem by adding a PanelMorph instead a string:
>
> obtainSpMorphPresenterwithAStringMorph
>     | morph |
>     morph := StringMorph
>     contents: 'A String Morph'
>     font:
>         (LogicalFont
>             familyName: Smalltalk ui theme labelFont familyName
>             pointSize: Smalltalk ui theme labelFont pointSize + 10).
>     ^ SpMorphPresenter new
>     morph: (PanelMorph new
> addMorphBack: morph;
> yourself);
>     yourself
>
>
> This will produce this morph:
>
> <Screenshot 2020-03-19 at 10.24.01.png>
>
>
> And since I hate morphic, I will let you to fight with morph to center your sub morph ;)
>
> Esteban
>
>> On 18 Mar 2020, at 17:41, Sebastian Jordan <[hidden email]> wrote:
>>
>>
>>     button1 := self newButton.
>


Reply | Threaded
Open this post in threaded view
|

Re: Morphs with Spec2

Sebastian Jordan
In reply to this post by EstebanLM
Hi,

It worked. For center the morph I do it in the naive way. I called the method position: of the morph.
Thanks,
Sebastian Jordan

De: Pharo-users <[hidden email]> en nombre de Esteban Lorenzano <[hidden email]>
Enviado: jueves, 19 de marzo de 2020 05:25
Para: Any question about pharo is welcome <[hidden email]>
Asunto: Re: [Pharo-users] Morphs with Spec2
 
Hi,

1. Spec styles define a “default” font applied to all components (morphs in this case) that understand font, and if you want to change it you need to define your own style.
2. A string morph cannot center the string (this is a morphic stuff)

You can solve your problem by adding a PanelMorph instead a string:

obtainSpMorphPresenterwithAStringMorph
    | morph |
    morph := StringMorph
    contents: 'A String Morph'
    font:
        (LogicalFont
            familyName: Smalltalk ui theme labelFont familyName
            pointSize: Smalltalk ui theme labelFont pointSize + 10).
    ^ SpMorphPresenter new
    morph: (PanelMorph new 
addMorphBack: morph;
yourself);
    yourself


This will produce this morph: 



And since I hate morphic, I will let you to fight with morph to center your sub morph ;)

Esteban

On 18 Mar 2020, at 17:41, Sebastian Jordan <[hidden email]> wrote:


    button1 := self newButton.