1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-27 20:08:22 +01:00
Diya-API/Diya/DiyaLabel.class.st

86 lines
1.6 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 >> fontSize [
^txt fontSize.
]
{ #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.
anObject isNumber ifTrue: [
2022-08-07 20:43:16 +02:00
icon := self addNode: (DiyaFontIcon data: anObject).].
anObject isString ifTrue: [
icon := self addNode: (DiyaImageIcon from: anObject).
].
icon ifNil: [ icon := self addNode: anObject ].
2022-08-07 20:43:16 +02:00
self setDirty
2022-03-21 22:39:52 +01:00
]
{ #category : #accessing }
DiyaLabel >> iconSize [
icon ifNil: [ ^0 ].
^ icon iconSize
]
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 >> process [
|offset isize align|
2022-03-23 00:52:15 +01:00
offset := 0.
icon ifNotNil: [
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).
"lookahead update"
txt process.
align := self getHAlign: offset.
txt position: offset @ ( (self extent y - txt extent y ) >> 1).
icon ifNil: [ ^self ].
"{ 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
]
{ #category : #accessing }
DiyaLabel >> txt [
^ txt
]
{ #category : #accessing }
DiyaLabel >> txt: anObject [
txt data: anObject.
self setDirty
]