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
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 <sebastianjmt@hotmail.com> wrote:
button1 := self newButton.
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 <estebanlm@gmail.com> 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 <sebastianjmt@hotmail.com> wrote:
button1 := self newButton.
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 <pharo-users-bounces@lists.pharo.org> en nombre de Esteban Lorenzano <estebanlm@gmail.com> Enviado: jueves, 19 de marzo de 2020 05:25 Para: Any question about pharo is welcome <pharo-users@lists.pharo.org> 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: [cid:4B595F37-F62E-4AD8-9D0E-515284AC24C4] 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 <sebastianjmt@hotmail.com<mailto:sebastianjmt@hotmail.com>> wrote: button1 := self newButton.
participants (3)
-
Esteban Lorenzano -
Sebastian Jordan -
Sven Van Caekenberghe