1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2025-01-15 17:18:23 +01:00
Diya-API/Diya/DiyaLabel.class.st

58 lines
1.1 KiB
Smalltalk
Raw Normal View History

Class {
#name : #DiyaLabel,
#superclass : #DiyaWidget,
2022-03-21 22:39:52 +01:00
#instVars : [
'txt',
'icon'
],
#category : #'Diya-Widgets'
}
2022-03-21 22:39:52 +01:00
{ #category : #accessing }
DiyaLabel >> icon [
^ icon
]
{ #category : #accessing }
DiyaLabel >> icon: anObject [
icon := nil.
2022-03-23 00:52:15 +01:00
anObject isNumber ifTrue: [ icon := self addNode: (DiyaFontIcon data: anObject) ].
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.
]
{ #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.
2022-03-23 00:52:15 +01:00
"style := DiyaDefaultStyle uniqueInstance."
2022-03-21 22:39:52 +01:00
]
{ #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.
isize := style get: #fontSize.
icon ifNotNil: [
offset := isize + (isize >> 1).
icon position: 0 @ (extent y - isize)
].
txt extent: (extent x - offset) @ (extent y).
txt position: offset @ (extent y)
]