[Cuis-dev] custom morph confusion
Juan Vuletich
juan at cuis.st
Thu Jul 11 15:51:23 PDT 2024
On 7/11/2024 4:39 PM, Mark Volkmann via Cuis-dev wrote:
> When creating a custom morph it's not clear to me whether I should
> subclass PlacedMorph or BoxedMorph.
>
> I see that PlacedMorph doesn't hold the size of the morph, but
> BoxedMorph does. BoxedMorph has the instance variable extent and the
> accessors morphExtent and morphExtent:. I want to be able to set the
> extent of my custom morph instances and utilize that size
> information in my drawOn: method.
>
> However, the drawOn: method in PlaceMorph uses a VectorCanvas and
> BoxedMorph uses a HybridCanvas. HybridCanvas doesn't have the
> strokeWidth:color:fillColor:do: method and I want to use that.
>
> I could add my own extent instance variable to my PlacedMorph
> subclass, but that feels wrong.
>
> I need some advice on this.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
BoxedMorph are a Hierarchy for morphs that are rectangle like, and that
occupy an area that can be specified as a Rectangle. This means that,
besides being of rectangular shape, sides are aligned with local
coordinate axes. Including rectangles with rounded corners and such. The
idea is that the 'extent' ivar is all that's needed to establish our
dimensions and shape.
They are used, for example, for common widgets.
If your morph is not in the shape of a rectangle, it is better to make
it a PlacedMorph. See `PlacedMorph subclasses`, and play with instances
of them in your Morphic World to see some of the things that can be done.
See #requiresVectorCanvas and #knowsOwnLocalBounds. You can redefine
#requiresVectorCanvas in a subclass of BoxedMorph if desired. But see,
in the other subclasses of PlacedMorph, the kind of freedom you get when
you can make #knowsOwnLocalBounds answer false.
Finally, you can add whatever instance variable you need to any of your
classes. You're the master. Why would adding 'extent' to your own
PlacedMorph feel wrong, if that happens to be what you need / want?
Don't be shy. You're just playing.
Happy explorations!
--
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/20240711/a3b4811f/attachment.htm>
More information about the Cuis-dev
mailing list