2022-03-16 18:37:51 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaLabel,
|
|
|
|
#superclass : #DiyaWidget,
|
2022-03-21 22:39:52 +01:00
|
|
|
#instVars : [
|
|
|
|
'txt',
|
|
|
|
'icon'
|
|
|
|
],
|
2022-03-16 18:37:51 +01:00
|
|
|
#category : #'Diya-Widgets'
|
|
|
|
}
|
2022-03-21 22:39:52 +01:00
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> fontSize [
|
|
|
|
^txt fontSize.
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-08-06 03:11:36 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> getHAlign: offset [
|
|
|
|
^ 0 max: (txt alignLine: ( txt maxLineWidth)).
|
|
|
|
]
|
|
|
|
|
2022-03-21 22:39:52 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> icon [
|
|
|
|
^ icon
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> icon: anObject [
|
|
|
|
icon := nil.
|
2022-03-24 22:48:41 +01:00
|
|
|
anObject isNumber ifTrue: [
|
2022-08-07 20:43:16 +02:00
|
|
|
icon := self addNode: (DiyaFontIcon data: anObject).].
|
2022-08-06 03:11:36 +02:00
|
|
|
anObject isString ifTrue: [
|
|
|
|
icon := self addNode: (DiyaImageIcon from: anObject).
|
|
|
|
].
|
2022-08-12 22:19:54 +02:00
|
|
|
icon ifNil: [ icon := self addNode: anObject ].
|
2022-08-07 20:43:16 +02:00
|
|
|
self setDirty
|
2022-03-21 22:39:52 +01:00
|
|
|
]
|
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> iconSize [
|
|
|
|
icon ifNil: [ ^0 ].
|
2022-08-06 03:11:36 +02:00
|
|
|
^ icon iconSize
|
2022-03-24 22:48:41 +01:00
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-03-21 22:39:52 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaLabel >> initialize [
|
|
|
|
super initialize.
|
2022-03-23 00:52:15 +01:00
|
|
|
txt := self addNode:(DiyaText data: '').
|
2022-03-21 22:39:52 +01:00
|
|
|
icon := nil.
|
|
|
|
self extent: 0@0.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2022-08-10 19:55:49 +02:00
|
|
|
DiyaLabel >> process [
|
2022-08-06 03:11:36 +02:00
|
|
|
|offset isize align|
|
2022-03-23 00:52:15 +01:00
|
|
|
offset := 0.
|
|
|
|
icon ifNotNil: [
|
2022-08-06 03:11:36 +02:00
|
|
|
isize := self iconSize.
|
|
|
|
offset := isize + (isize >> 2).
|
|
|
|
"icon extent:offset @ (extent y)."
|
2022-03-23 00:52:15 +01:00
|
|
|
].
|
|
|
|
txt extent: (extent x - offset) @ (extent y).
|
2022-08-06 03:11:36 +02:00
|
|
|
"lookahead update"
|
2022-08-10 19:55:49 +02:00
|
|
|
txt process.
|
2022-08-06 03:11:36 +02:00
|
|
|
align := self getHAlign: offset.
|
|
|
|
txt position: offset @ ( (self extent y - txt extent y ) >> 1).
|
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
icon ifNil: [ ^self ].
|
2022-08-06 03:11:36 +02:00
|
|
|
"{ offset. txt extent. txt maxLineWidth. align } inspect."
|
|
|
|
icon position: (align @( (self extent y - self iconSize ) >> 1)).
|
2022-08-07 18:15:57 +02:00
|
|
|
^ true
|
2022-03-23 00:52:15 +01:00
|
|
|
|
|
|
|
]
|
2022-08-10 19:55:49 +02:00
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> txt [
|
|
|
|
^ txt
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> txt: anObject [
|
|
|
|
txt data: anObject.
|
|
|
|
self setDirty
|
|
|
|
]
|