[Cuis-dev] Morphic button clicks

Juan Vuletich juan at cuis.st
Thu Jun 6 15:04:00 PDT 2024


On 6/6/2024 6:24 PM, Mark Volkmann via Cuis-dev wrote:
> I'm trying to learn how to create a button and have something happen 
> when the button is clicked. I've done a lot of Googling for this, but 
> haven't found the solution.
> Here is what I tried based on example code I found:
>
> s1 := Switch new.
> btn := PluggableButtonMorph model: s1 action: [Transcript show: 'got 
> click'] label: 'Click Me'.
> btn color: (Color blue); enableLabelColorWith: (Color yellow).
> btn openInWorld.
>
> Perhaps I don't really need to create a `Switch`. I hope I don't, but 
> it seems all the creation methods for `PluggableButtonMorph` require that.
> I'm not sure if `PluggableButtonMorph` is the class I should be using.
> This code does create and render a button, but it does not set the 
> label color to yellow and I get the following error when I click the 
> button:
>
> BlockClosure(Object)>>doesNotUnderstand: #asPlainString
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc.

Hi Mark,

You're almost there. This does work:

s1 := Switch new.
btn := PluggableButtonMorph model: [Transcript show: 'got click'] 
action: #value label: 'Click Me'.
btn color: (Color blue); enableLabelColorWith: (Color yellow).
btn openInWorld.

As you see, the action is a symbol, a message to be sent to some object. 
The model is the object that will get that message. Sending #value to a 
code block works.

Happy Hacking!

-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240606/d2d1147c/attachment-0001.htm>


More information about the Cuis-dev mailing list