[Newbies] Constrained Morph dragging

Sebastian Nozzi sebnozzi at gmail.com
Sun Nov 18 11:53:08 UTC 2012

Hello Morphic experts,

I am learning / experimenting with Morphic and have the following question:

"How do I constrain the movement of a dragged Morph?"

As illustrated here:


(e.g. constrain within axis/container)

So far the "hack" I came up with was to aggresively re-position the
dragged Morph in its "drawOn:", if it is attached to a HandMorph:

drawOn: aCanvas
	self owner isHandMorph "is there a better way to ask: am I being dragged?"
		ifTrue: [ self position: (self position x) @ 400 ].
	super drawOn: aCanvas.

I am sure this solution is pretty bad... I also get visual artifacts
when I move the mouse up/down.

Are there better ways/hooks for this?

Generally: is there a method that is called on submorphs whenever the
parent Morph was re-positioned/re-sized?

Thanks in advance!


More information about the Beginners mailing list