[Cuis-dev] Morphic button clicks

Mark Volkmann r.mark.volkmann at gmail.com
Thu Jun 6 16:35:58 PDT 2024


Thanks so much! It seems like I should want a simpler way to create basic
buttons. I added this class method to `PluggableButtonMorph` which is
working fine. Is there anything bad about this approach or does a method
similar to this already exist?

label: aString onClick: aBlock
    ^PluggableButtonMorph model: aBlock action: #value label: aString.

I can use this as follows:

b := PluggableButtonMorph label: 'Test' onClick: ['got click' print].
b openInWorld.

What is the significance of a morph being "pluggable"?

I can change the background color of a button, but I haven't figured out
how to change the text color.

On Thu, Jun 6, 2024 at 5:04 PM Juan Vuletich <juan at cuis.st> wrote:

> 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 Vuletichcuis.stgithub.com/jvuletichresearchgate.net/profile/Juan-Vuletichindependent.academia.edu/JuanVuletichpatents.justia.com/inventor/juan-manuel-vuletichlinkedin.com/in/juan-vuletich-75611b3twitter.com/JuanVuletich
>
>

-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240606/a11ccbaf/attachment.htm>


More information about the Cuis-dev mailing list