[Cuis-dev] Greetings and a couple of questions from a newbie

David Gouge davidgouge at pm.me
Sun Feb 15 09:52:31 PST 2026


Greetings! I'm a complete Cuis Smalltalk newbie so please forgive my ignorance if I'm in error here.

I was going through the first examples in the "The Morph Book vol. I – Design Graphic User Interface" tutorial and quickly ran into an issue with the 1.2 Quick Start example (https://drcuis.github.io/DesignGUI/Quick-Start.html). *Please note that I'm using the rolling development image to walk through the tutorial.

In the code example, the greetingLabel instance is explicitly sent the 'color: Color: red' message after creation. However there appears to be a halting side-effect introduced during the execution of the PluggableButtonMorph's event handler block.

button := PluggableButtonMorph
model: [greetingLabel contents: 'Hello, ', input text, '!'] " <- Offending block"
action: #value.

At a quick glance, what appears to be happening is that the LableMorph >> #contents method is receiving a #Text object of newContents who's colorAt method is returning nil.

LableMorph >> contents: newContents
contents := (newContents is: #Text)
ifTrue: [
emphasis := newContents emphasisAt: 1.
color := newContents colorAt: 1. " <- color is being set to nil ?"
font := newContents fontAt: 1 default: font.
newContents string ]
ifFalse: [
contents = newContents ifTrue: [ ^self ]. "no substantive change"
newContents].
self fitContents.
self redrawNeeded

This in turn causes LabelMorph onDraw method to halt in the Debugger when it does a redraws because the LabelMorph's color instance variable is nil.

drawOn: aCanvas
| f delta |
contents ifNotNil: [
f := self fontToUse.
delta := contents isEmpty
ifFalse: [ (f boundsLeftOf: contents first) negated at 0 ]
ifTrue: [ 0 at 0 ].
aCanvas
drawString: contents
at: self interiorOrigin + delta
font: f
color: color ]. "<-- color is nil. halted in the Debugger"

I only bring this up because errors in tutorial documentation can cause new users like me to quickly give up and move on to something else. That would be a real shame for something as lovely as Cuis.

At the risk of taking up too much of your time, I'm wondering about the Cuis idiomatic way to fix this. My naive approach to get the example to work was to change the event handler block to return a String instead of a Text object. Ex.

"Create a button that when clicked executes
the associated block of code"
button := PluggableButtonMorph
model: [greetingLabel contents: 'Hello, ', input text asString, '!'] " <- Get a string instead of Text"
action: #value.
button label: 'Greet'.

However, it seems to me that the onDraw method still has that potential problematic side-effect. In C/C++ I might use an immediate if to test colorAt:'s return before assignment (pseudo example: color = newContents->colorAt(1) == nullptr ? this->color : newContents->colorAt(1); ). In this case (and in Smalltalk in general), would something like that be idiomatic and appropriate here?

Anyhow, I'm really enjoying my time with Cuis. After retiring from 3 1/2 decades of writing mostly system-level C/C++, I finally get play around with things that I've been curious about for years. I got a small taste of smalltalk back in the mid-90's and have been intrigued ever since. It's great to be able to finally satisfy my curiosity and Cuis is proving to be an absolute joy to do that with.
-Dave

Sent with [Proton Mail](https://proton.me/mail/home) secure email.

Sent with [Proton Mail](https://proton.me/mail/home) secure email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20260215/7d58b9ea/attachment.htm>


More information about the Cuis-dev mailing list