Search code examples
smalltalkpharo

Pharo Smalltalk UITheme builder label


I am building a GUI app using Smalltalk Pharo version 4.0. I am using the following UITheme builder code to create labels since Morphic TextMorphs/LabelMorphs do not implement Observer pattern to update them dynamically on GUI when their value changes through program logic:

UITheme builder
    newLabelFor: self
    getLabel: #labelValue
    getEnabled: nil

I need to change the fonts and text color for the above label. I tried using the following and other similar options but it does not work for me:

newLabelGroup: labelsAndControls font: aFont labelColor: aColor

Is there any way to achieve this?


Solution

  • You can send the messages #color: and #font: to the object returned by #newLabelFor:getLabel:getEnabled. For example the code below creates a big red text:

    (UITheme builder
        newLabelFor: 'Text'
        getLabel: #asString
        getEnabled: nil)
           color: Color red;
           font: (LogicalFont familyName: 'Source Sans Pro' pointSize: 30);
           openInWorld
    

    Depending on your image and setup this will not work with all fonts.