<commit_before>"
I am a popup that uses Morphic and can be visible outside of the RSCanvas.
"
Class {
	#name : #RSMorphicPopup,
	#superclass : #RSAbstractPopup,
	#instVars : [
		'morphBuilder'
	],
	#category : #'Roassal3-Interaction-Popup'
}

{ #category : #hooks }
RSMorphicPopup >> createPopupFor: aShape event: event [
	| popup vertices targetMorph world |
	targetMorph := self morphBuilder cull: aShape model.
	vertices := SimpleBalloonMorph getVertices: targetMorph bounds.
	popup := SimpleBalloonMorph new
		color: Color white;
		addMorph: targetMorph;
		setTarget: nil;
		setVertices: vertices.
	world := event canvas morph world.
	world ifNil: [ ^ popup ].
	world addMorphFront: popup.
	world activeHand balloonHelp: popup.
	^ popup
]

{ #category : #initialization }
RSMorphicPopup >> initialize [
	super initialize.
	self morphBuilder: [ :model | model asString asTextMorph ].
]

{ #category : #accessing }
RSMorphicPopup >> morphBuilder [
	^ morphBuilder
]

{ #category : #accessing }
RSMorphicPopup >> morphBuilder: aBlock [
	morphBuilder := aBlock
]

{ #category : #hooks }
RSMorphicPopup >> popupKey [
	^ #popupMorph
]

{ #category : #hooks }
RSMorphicPopup >> releasePopup: popup [
	popup delete
]

{ #category : #hooks }
RSMorphicPopup >> translatePopup: aMorph event: evt [ 
	| position xdelta ydelta cMorph world |
	cMorph := evt canvas morph.
	world := cMorph world.
	position := (evt camera fromSpaceToPixel: evt position) + cMorph position.
	xdelta := ydelta := 0.
	
	(position x + aMorph width) > world width 
		ifTrue: [ xdelta := aMorph width negated ].
	(position y + aMorph height) > world height 
		ifTrue: [ ydelta := aMorph height negated ].
	
	aMorph lock;
		fullBounds;
		setProperty: #morphicLayerNumber toValue: aMorph morphicLayerNumber.
	aMorph position: position + (xdelta@ydelta)
]<commit_msg>RSMorphicPopup: fix position when popup exceeds the World<commit_after>"
I am a popup that uses Morphic and can be visible outside of the RSCanvas.
"
Class {
	#name : #RSMorphicPopup,
	#superclass : #RSAbstractPopup,
	#instVars : [
		'morphBuilder'
	],
	#category : #'Roassal3-Interaction-Popup'
}

{ #category : #accessing }
RSMorphicPopup >> backgroundColor [
	^ Smalltalk ui theme backgroundColor
]

{ #category : #hooks }
RSMorphicPopup >> createPopupFor: aShape event: event [
	| popup vertices targetMorph world |
	targetMorph := self morphBuilder cull: aShape model.
	vertices := SimpleBalloonMorph getVertices: targetMorph bounds.
	popup := SimpleBalloonMorph new
		color: self backgroundColor;
		addMorph: targetMorph;
		setTarget: nil;
		setVertices: vertices.
	world := event canvas morph world.
	world ifNil: [ ^ popup ].
	world addMorphFront: popup.
	world activeHand balloonHelp: popup.
	^ popup
]

{ #category : #initialization }
RSMorphicPopup >> initialize [
	super initialize.
	self morphBuilder: [ :model | model asString asTextMorph ].
]

{ #category : #accessing }
RSMorphicPopup >> morphBuilder [
	^ morphBuilder
]

{ #category : #accessing }
RSMorphicPopup >> morphBuilder: aBlock [
	morphBuilder := aBlock
]

{ #category : #hooks }
RSMorphicPopup >> popupKey [
	^ #popupMorph
]

{ #category : #hooks }
RSMorphicPopup >> releasePopup: popup [
	popup delete
]

{ #category : #hooks }
RSMorphicPopup >> translatePopup: aMorph event: evt [ 
	| position xdelta ydelta cMorph world |
	cMorph := evt canvas morph.
	world := cMorph world.
	position := (evt camera fromSpaceToPixel: evt position) + cMorph position.
	xdelta := ydelta := 0.
	
	(position x + aMorph width) > world width 
		ifTrue: [ xdelta := aMorph width negated ].
	(position y + aMorph height) > world height 
		ifTrue: [ ydelta := aMorph height negated ].
	
	aMorph
		lock;
		fullBounds;
		setProperty: #morphicLayerNumber toValue: aMorph morphicLayerNumber.
	
	aMorph position: ((position x + xdelta) max: 0) @ ((position y + ydelta) max: 0)

]
{'fraction_non_alphanumeric': 0.1062451412282975, 'fraction_numerical': 0.0015548069448043534, 'mean_word_length': 4.361111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5155475', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1316, 'n_words': 373}