[Cuis-dev] Started Morph Properties HowTo

ken.dickey at whidbey.com ken.dickey at whidbey.com
Mon May 26 15:13:43 PDT 2025


Just a sketch.  I plan to pour a bunch of tutorials/how2s into this..

Please review SillyMorph (link on README.md).

https://github.com/DrCuis/How-to-guides/blob/main/400-MorphProperties/README.md

Had a chance to review #layerNumber proposal? (again attached).  I would 
like to submit to Juan.

Thanks a bunch,
-KenD

-------------- next part --------------
'From Cuis7.3 [latest update: #7182] on 20 May 2025 at 1:49:32 pm'!

!Morph methodsFor: 'event handling' stamp: 'jmv 5/16/2024 09:54:33'!
mouseButton2Activity
	"Invoke the menu"
	self getMenu ifNotNil: [ :menu |
		menu popUpInWorld: self world.
		"menu invokeModal" ]! !

!Morph methodsFor: 'initialization' stamp: 'KenD 5/20/2025 12:49:58'!
openInWorld

	self runningWorld
		ifNil: [ UISupervisor whenUIinSafeState: [ self openInWorld ]]
		ifNotNil: [ :w | self openInWorld: w;  comeToFront ]! !

!Morph methodsFor: 'meta-actions' stamp: 'jmv 5/17/2009 23:42'!
buildHandleMenu: aHand
	"Build the morph menu for the given morph's halo's menu handle. This menu has two sections. The first section contains commands that are interpreted by the hand; the second contains commands provided by the target morph. This method allows the morph to decide which items should be included in the hand's section of the menu."

	| menu |
	menu := MenuMorph new defaultTarget: self.
	menu addStayUpIcons.
	menu addLine.
	self addStandardHaloMenuItemsTo: menu hand: aHand.
	menu defaultTarget: aHand.
	self addAddHandMenuItemsForHalo: menu  hand: aHand.
	menu defaultTarget: self.
	self addCustomHaloMenuItems: menu hand: aHand.
	menu defaultTarget: aHand.
	^ menu
! !

!Morph methodsFor: 'submorphs-add/remove' stamp: 'KenD 5/20/2025 13:32:58'!
addMorphFront: aMorph position: aPoint
	
	| oldFronLayerNumber |
	(submorphs size > 0)
		ifTrue: [
			 oldFronLayerNumber := (submorphs at: 1) layerNumber.
			aMorph setProperty: #layerNumber toValue: ((1 + oldFronLayerNumber) min: 10).
		].
	^self privateAddMorph: aMorph atIndex: 1 position: aPoint! !

!Morph methodsFor: 'private' stamp: 'KenD 5/20/2025 12:30:21'!
privateMoveBackMorph: aMorph

	| oldIndex oldBackLayerNumber myWorld index |
	myWorld := self world.
	"aMorph's position changes within in the submorph chain"
	"moving aMorph to front"
	oldIndex := submorphs indexOf: aMorph.
	"moving aMorph to back"
	index := submorphs size.
	oldBackLayerNumber := (submorphs at: index) layerNumber.
	aMorph setProperty: #layerNumber toValue: ((oldBackLayerNumber - 1) max: 100).
	submorphs replaceFrom: oldIndex to: index-1 with: submorphs startingAt: oldIndex+1.
	submorphs at: index put: aMorph.
	myWorld ifNotNil: [aMorph redrawNeeded].
	self privateFixLayerOrder.
	self someSubmorphPositionOrExtentChanged.! !

!Morph methodsFor: 'private' stamp: 'KenD 5/20/2025 12:23:42'!
privateMoveFrontMorph: aMorph

	| oldIndex oldFrontLayerNumber myWorld |
	myWorld := self world.
	"aMorph's position changes within in the submorph chain"
	"moving aMorph to front"
	oldIndex := submorphs indexOf: aMorph.
	oldFrontLayerNumber := (submorphs at: 1) layerNumber.
	aMorph setProperty: #layerNumber toValue: ((1 + oldFrontLayerNumber) min: 10).
	oldIndex-1 to: 1 by: -1 do: [ :i |
		submorphs at: i+1 put: (submorphs at: i)].
	submorphs at: 1 put: aMorph.
	myWorld ifNotNil: [aMorph redrawNeeded].
	self privateFixLayerOrder.
	self someSubmorphPositionOrExtentChanged.! !


!HaloMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 12:08:49'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	Please make them natural numbers.
	See implementors."

	^self valueOfProperty: #layerNumber ifAbsent: [ 10 ]! !

!HaloMorph methodsFor: 'event handling' stamp: 'jmv 8/25/2024 08:57:02'!
popUpFor: aMorph handPosition: handPosition hand: hand

	hand halo: self.
	hand world addMorphFront: self.
	self target: aMorph.
	positionOffset := handPosition - aMorph positionInWorld.! !


!HoverHelpMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 12:09:15'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be on top."

	^self valueOfProperty: #layerNumber ifAbsent: [ 10 ]! !


!StringRequestMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 12:09:34'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be above regular morphs."

	^self valueOfProperty: #layerNumber ifAbsent: [ 30 ]! !


!MenuMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 12:10:03'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be rather on top."

	stayUp ifTrue: [ ^super layerNumber ].
	^self valueOfProperty: #layerNumber ifAbsent: [ 20 ]! !

!MenuMorph methodsFor: 'control' stamp: 'KenD 5/20/2025 12:45:59'!
popUpInWorld
	"Present this menu in the current World"

	^self popUpInWorld: self runningWorld;
		  comeToFront;
		  yourself! !


!AutoCompleterMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 12:10:17'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be rather on top."

	^self valueOfProperty: #layerNumber ifAbsent: [ 20 ]! !


!WorldMorph methodsFor: 'submorphs-add/remove' stamp: 'KenD 5/20/2025 13:24:59'!
addMorph: aMorph centeredNear: aPoint
	"Add the given morph to this world, attempting to keep its center as close to the given point possible while also keeping the it entirely within the bounds of this world."

	self addMorph: aMorph.
	aMorph comeToFront.
	aMorph morphExtent
		ifNil: [ aMorph positionInWorld: aPoint ]
		ifNotNil:
			[ :e |
				| trialRect delta |
				trialRect := Rectangle center: aPoint extent: e.
				delta := trialRect amountToTranslateWithin: self displayBounds.
				aMorph positionInWorld: (trialRect origin + delta) rounded ].! !

-------------- next part --------------
'From Cuis7.3 [latest update: #7182] on 20 May 2025 at 2:00:14 pm'!

!AutoCompleterMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 12:10:17'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be rather on top."

	^self valueOfProperty: #layerNumber ifAbsent: [ 20 ]! !
-------------- next part --------------
'From Cuis7.3 [latest update: #7182] on 20 May 2025 at 2:00:18 pm'!

!CircularToolbarMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 13:37:05'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be above regular morphs."

	^self valueOfProperty: #layerNumber ifAbsent: [ 30 ]! !
-------------- next part --------------
'From Cuis7.3 [latest update: #7182] on 20 May 2025 at 2:00:24 pm'!

!Panel methodsFor: 'accessing' stamp: 'KenD 5/20/2025 13:36:45'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be above regular morphs."

	^self valueOfProperty: #layerNumber ifAbsent: [ 30 ]! !
-------------- next part --------------
'From Cuis7.3 [latest update: #7182] on 20 May 2025 at 1:51:36 pm'!

!PluggableDropDownListMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 13:36:24'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be above regular morphs."

	^self valueOfProperty: #layerNumber ifAbsent: [ 29 ]! !
-------------- next part --------------
'From Cuis7.3 [latest update: #7182] on 20 May 2025 at 1:51:12 pm'!

!PluggableDropDownListOfMorph methodsFor: 'accessing' stamp: 'KenD 5/20/2025 13:36:33'!
layerNumber
	"Morphs with smaller layer number will always cover those with larger ones.
	We want to be above regular morphs."

	^self valueOfProperty: #layerNumber ifAbsent: [ 29 ]! !


More information about the Cuis-dev mailing list