'From Cuis 5.0 [latest update: #4413] on 16 October 2020 at 4:13:26 pm'!

!LabelMorph commentStamp: 'jmv 10/12/2020 21:03:15' prior: 0!
LabelMorph is a "lightweight" Morph to display a String. It supports only a single font, color, and emphasis combination. For multiple text styles, use TextModelMorph.

Structure:
instance var    	Type              Description 
font 			StrikeFont 		(normally nil; then the accessor #font gives back  a Font or nil #defaultFont) 
emphasis 		SmallInteger	bitmask determining character attributes (underline, bold, 	italics, struckThrough) 
contents 		String 			The text that will be displayed. 
!


!LabelMorph methodsFor: 'geometry' stamp: 'KenD 10/16/2020 14:44:31'!
morphExtent: aPoint 
	"Set the receiver's extent to value provided. Honor my minimumExtent."

	super morphExtent: (aPoint max: self minimumExtent)! !

!LabelMorph methodsFor: 'geometry' stamp: 'KenD 10/16/2020 14:45:03'!
naturalHeight

	^ (self minimumExtent y) + 4! !


!LabelMorph methodsFor: 'accessing'!
contents

	^ contents! !

!LabelMorph methodsFor: 'accessing' stamp: 'jmv 1/4/2013 13:24'!
contents: newContents
	contents _ (newContents is: #Text)
		ifTrue: [
			emphasis _ newContents emphasisAt: 1.
			 newContents string ]
		ifFalse: [
			contents = newContents ifTrue: [ ^self ].	"no substantive change"
			newContents].
	self fitContents.
	self redrawNeeded! !

!LabelMorph methodsFor: 'accessing' stamp: 'KenD 10/16/2020 14:55:53'!
emphasis: emphasisCode

	emphasis _ emphasisCode.
	self fitContents.
	self redrawNeeded
"
in inspector say,
	 self font: StrikeFont default emphasis: 1
"! !

!LabelMorph methodsFor: 'accessing' stamp: 'ar 1/31/2001 19:33'!
font
	"who came up with #fontToUse rather than font?!!"
	^self fontToUse! !

!LabelMorph methodsFor: 'accessing' stamp: 'KenD 10/16/2020 14:56:21'!
font: aFont

	font _ aFont.
	self fitContents.
	self redrawNeeded
"
in inspector say,
	 self font: StrikeFont default emphasis: 1
"! !

!LabelMorph methodsFor: 'accessing' stamp: 'jmv 6/6/2014 10:58'!
font: aFont emphasis: emphasisCode
	font _ aFont.
	emphasis _ emphasisCode.
	self fitContents.
	self redrawNeeded
"
in inspector say,
	 self font: StrikeFont default emphasis: 1
"! !

!LabelMorph methodsFor: 'accessing' stamp: 'jmv 6/11/2020 10:03:16'!
fontToUse
	| fontToUse |
	fontToUse := font ifNil: [FontFamily defaultFamilyAndPointSize].
	^(emphasis isNil or: [emphasis = 0]) 
		ifTrue: [ fontToUse]
		ifFalse: [ fontToUse emphasized: emphasis]! !

!LabelMorph methodsFor: 'drawing' stamp: 'pb 3/17/2020 13:52:32'!
drawOn: aCanvas
	aCanvas
		drawString: (contents ifNil: [ '' ])
		at: self morphTopLeft 
		font: self fontToUse
		color: color! !

!LabelMorph methodsFor: 'halos and balloon help' stamp: 'sw 6/15/1998 15:34'!
addOptionalHandlesTo: aHalo box: box
	self flag: #deferred.

	"Eventually...
	self addFontHandlesTo: aHalo box: box"! !

!LabelMorph methodsFor: 'initialization' stamp: 'jmv 10/12/2020 21:06:00'!
defaultBorderWidth
	"answer the default border width for the receiver"
	^ 0! !

!LabelMorph methodsFor: 'initialization' stamp: 'cbr 12/3/2010 23:28'!
defaultColor
	"answer the default color/fill style for the receiver"
	^ Theme current menuText! !

!LabelMorph methodsFor: 'initialization' stamp: 'KenD 10/16/2020 14:47:35'!
initWithContents: aString font: aFont emphasis: emphasisCode 
	self initialize.
	
	aFont ifNotNil: [ font := aFont ] ifNil: [ font := FontFamily defaultFamilyAndPointSize ].
	emphasis := emphasisCode.
	self contents: aString! !

!LabelMorph methodsFor: 'initialization' stamp: 'KenD 10/16/2020 14:48:58'!
initialize

	super initialize.
	self
		font: FontFamily defaultFamilyAndPointSize;
		color: Color transparent;
		emphasis: AbstractFont normalCode;
		layoutSpec: (LayoutSpec keepMorphExtent);
		contents: 'String Morph'.! !

!LabelMorph methodsFor: 'menu' stamp: 'jmv 2/22/2011 22:51'!
addCustomMenuItems: aCustomMenu hand: aHandMorph

	super addCustomMenuItems: aCustomMenu hand: aHandMorph.
	aCustomMenu add: 'change font' action: #changeFont.
	aCustomMenu add: 'change emphasis' action: #changeEmphasis.
! !

!LabelMorph methodsFor: 'menu' stamp: 'jmv 12/12/2014 15:53'!
changeEmphasis

	| reply aList |
	aList _ #(normal bold italic underlined struckThrough).
	reply _ (SelectionMenu labelList: aList selections: aList) startUpMenu.
	reply ifNotNil:[
		self emphasis: (TextEmphasis perform: reply) emphasisCode.
	].
! !

!LabelMorph methodsFor: 'menu' stamp: 'jmv 4/15/2014 09:25'!
changeFont
	| newFont |
	newFont _ AbstractFont fromUser: self fontToUse.
	newFont ifNotNil:[self font: newFont].! !

!LabelMorph methodsFor: 'printing' stamp: 'jm 11/3/97 16:52'!
printOn: aStream

	super printOn: aStream.
	aStream print: contents.
! !

!LabelMorph methodsFor: 'geometry' stamp: 'jmv 3/12/2018 15:56:36'!
fitContents
	"Measures contents later at #minimumExtent"
	self morphExtent: `0@0`! !

!LabelMorph methodsFor: 'geometry' stamp: 'jmv 4/24/2019 20:45:28'!
measureContents
	| f |
	f _ self fontToUse.
	^((f widthOfString: contents) max: 3)  @ f lineSpacing! !

!LabelMorph methodsFor: 'geometry' stamp: 'KenD 10/16/2020 14:43:51'!
minimumExtent

	^ self measureContents + (2 * self borderWidth)! !


!LabelMorph class methodsFor: 'instance creation' stamp: 'jmv 10/12/2020 21:04:02'!
contents: aString

	^ self contents: aString font: nil! !

!LabelMorph class methodsFor: 'instance creation' stamp: 'di 4/1/1999 17:15'!
contents: aString font: aFont
	^ self basicNew initWithContents: aString font: aFont emphasis: 0! !

!LabelMorph class methodsFor: 'instance creation' stamp: 'di 4/1/1999 17:15'!
contents: aString font: aFont emphasis: emphasisCode
	^ self basicNew initWithContents: aString font: aFont emphasis: emphasisCode! !

!LabelMorph class methodsFor: 'new-morph participation' stamp: 'pb 6/8/2017 23:55:41'!
categoryInNewMorphMenu
	^ 'Basic'! !


!LabelMorph reorganize!
('accessing' contents contents: emphasis: font font: font:emphasis: fontToUse)
('drawing' drawOn:)
('font')
('halos and balloon help' addOptionalHandlesTo:box:)
('initialization' defaultBorderWidth defaultColor initWithContents:font:emphasis: initialize)
('menu' addCustomMenuItems:hand: changeEmphasis changeFont)
('printing' printOn:)
('geometry' fitContents measureContents minimumExtent morphExtent: naturalHeight)
!

