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

98 lines
1.7 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 >> 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.
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.
]
{ #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: [
isize := icon fontSize.
2022-03-23 00:52:15 +01:00
offset := isize + (isize >> 1).
icon extent:offset @ (extent y).
2022-03-23 00:52:15 +01:00
].
txt extent: (extent x - offset) @ (extent y).
txt position: offset @ 0.
icon ifNil: [ ^self ].
icon position: (self iconPosition: offset).
2022-03-23 00:52:15 +01:00
]