[Cuis-dev] adding functionality to morphs

Mark Volkmann r.mark.volkmann at gmail.com
Wed Aug 21 18:08:54 PDT 2024


For the todo app I built as a learning exercise I ended up defining two
classes that are subclasses of morph subclasses. I'm wondering if the
approach I took is a recommended approach.

I defined the class PluggableScroll2Pane which is a subclass of
PluggableScrollPane because I wanted to register a block to be evaluated
every time its extent changes. It only adds the instance variable
onExtentChanged and these instance methods:

onExtentChanged: aBlock
    onExtentChanged := aBlock

extentChanged: oldExtent
    super extentChanged: oldExtent.
    onExtentChanged ifNotNil: [ onExtentChanged value: self morphExtent ].

I defined the class TextEntry2Morph which is a subclass of TextEntryMorph
because I wanted to register a block to be evaluated every time it has
focus and the user presses the escape key. It only adds the instance
variable escapeAction and these instance methods:

escapeAction: aBlock
    escapeAction := aBlock

escapeAction
    ^ escapeAction

keyStroke: aKeyboardEvent
    (aKeyboardEvent isEsc and: (escapeAction isNil not))
        ifTrue: [ escapeAction value ]
        ifFalse: [ super keyStroke: aKeyboardEvent ]

Is there a way I could have achieved the same goals without creating new
subclasses?
I welcome any critique of this code.

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


More information about the Cuis-dev mailing list