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.
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> fontSize: value [
|
|
|
|
txt fontSize: value.
|
|
|
|
icon ifNotNil: [ icon fontSize: value ].
|
|
|
|
"dirty := true."
|
|
|
|
|
|
|
|
]
|
|
|
|
|
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: [
|
|
|
|
icon := self addNode: (DiyaFontIcon data: anObject).
|
|
|
|
icon align: #left].
|
2022-03-23 00:52:15 +01:00
|
|
|
anObject isString ifTrue: [ icon := self addNode: (DiyaImageView from: anObject)].
|
2022-03-21 22:39:52 +01:00
|
|
|
icon ifNil: [ ^ DiyaCoreAPIError signal: 'Invalid icon identification'].
|
|
|
|
dirty := true.
|
|
|
|
]
|
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> iconPosition: offset [
|
|
|
|
|xpos|
|
|
|
|
txt splitLines.
|
|
|
|
txt lines ifEmpty: [ ^0@0 ].
|
|
|
|
xpos := txt alignLine: txt lines first key.
|
|
|
|
^xpos@0
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> iconSize [
|
|
|
|
icon ifNil: [ ^0 ].
|
|
|
|
^icon fontSize.
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> iconSize: v [
|
|
|
|
icon ifNil: [ ^self ].
|
|
|
|
icon fontSize: v.
|
|
|
|
|
|
|
|
]
|
|
|
|
|
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 }
|
|
|
|
DiyaLabel >> txt [
|
|
|
|
^ txt
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> txt: anObject [
|
|
|
|
txt data: anObject.
|
|
|
|
dirty := true
|
|
|
|
]
|
2022-03-23 00:52:15 +01:00
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLabel >> updateLayout [
|
|
|
|
|offset isize|
|
|
|
|
offset := 0.
|
|
|
|
icon ifNotNil: [
|
2022-03-24 22:48:41 +01:00
|
|
|
isize := icon fontSize.
|
2022-03-23 00:52:15 +01:00
|
|
|
offset := isize + (isize >> 1).
|
2022-03-24 22:48:41 +01:00
|
|
|
icon extent:offset @ (extent y).
|
2022-03-23 00:52:15 +01:00
|
|
|
].
|
|
|
|
txt extent: (extent x - offset) @ (extent y).
|
2022-03-24 22:48:41 +01:00
|
|
|
txt position: offset @ 0.
|
|
|
|
icon ifNil: [ ^self ].
|
|
|
|
icon position: (self iconPosition: offset).
|
2022-03-23 00:52:15 +01:00
|
|
|
|
|
|
|
]
|