/
SpToolBarButtonMorph.class.st
126 lines (104 loc) · 2.77 KB
/
SpToolBarButtonMorph.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"
A button morph typically used on a toolbar. The button can have a badge.
"
Class {
#name : #SpToolBarButtonMorph,
#superclass : #PluggableButtonMorph,
#instVars : [
'badgeFont',
'badgeSelector'
],
#category : #'Spec2-Core-Widgets'
}
{ #category : #accessing }
SpToolBarButtonMorph >> badge [
badgeSelector ifNil: [ ^ nil ].
^ self model perform: badgeSelector
]
{ #category : #accessing }
SpToolBarButtonMorph >> badgeColor [
^ self theme badgeColor
]
{ #category : #accessing }
SpToolBarButtonMorph >> badgeFont [
^ badgeFont ifNil: [ badgeFont := self newBadgeFont ]
]
{ #category : #accessing }
SpToolBarButtonMorph >> badgeSelector: aSymbol [
badgeSelector := aSymbol
]
{ #category : #accessing }
SpToolBarButtonMorph >> badgeTextColor [
^ self theme badgeTextColor
]
{ #category : #configuring }
SpToolBarButtonMorph >> configureWith: displayModel item: itemPresenter [
displayModel configureButton: self item: itemPresenter
]
{ #category : #accessing }
SpToolBarButtonMorph >> drawBadgeOn: aCanvas [
| badgeString badgeBounds textBounds textWidth textHeight width |
badgeString := self badge asString.
textWidth := self badgeFont widthOfString: badgeString.
textHeight := self badgeFont height.
width := 14 max: textWidth + 2.
badgeBounds := ((bounds right - width - 2)@(bounds top + 2) extent: width@14).
aCanvas
fillOval: badgeBounds
fillStyle: self badgeColor.
textBounds :=
(badgeBounds center - ((textWidth@textHeight) / 2.0)) + (1@0)
extent: textWidth@textHeight.
aCanvas
drawString: badgeString
in: textBounds
font: self badgeFont
color: self badgeTextColor
]
{ #category : #accessing }
SpToolBarButtonMorph >> drawOn: aCanvas [
super drawOn: aCanvas.
self hasBadge
ifTrue: [ self drawBadgeOn: aCanvas ]
]
{ #category : #accessing }
SpToolBarButtonMorph >> getIconSelector [
^ getIconSelector
]
{ #category : #accessing }
SpToolBarButtonMorph >> getIconSelector: aSelector [
getIconSelector := aSelector.
self update: getIconSelector
]
{ #category : #accessing }
SpToolBarButtonMorph >> getLabelSelector [
^ getLabelSelector
]
{ #category : #accessing }
SpToolBarButtonMorph >> getLabelSelector: aSelector [
getLabelSelector := aSelector.
self update: getLabelSelector
]
{ #category : #accessing }
SpToolBarButtonMorph >> hasBadge [
^ self badge notNil
]
{ #category : #accessing }
SpToolBarButtonMorph >> newBadgeFont [
| baseBadgeFont |
baseBadgeFont := StandardFonts codeFont.
^ (LogicalFont
familyName: baseBadgeFont familyName
pointSize: baseBadgeFont pointSize - 3)
weightValue: 700
]
{ #category : #accessing }
SpToolBarButtonMorph >> normalBorderStyle [
^ BorderStyle simple
width: 0;
baseColor: Color transparent
]
{ #category : #accessing }
SpToolBarButtonMorph >> normalFillStyle [
^ Color transparent
]