0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
View subclass:#Label
|
|
14 |
instanceVariableNames:'logo
|
59
|
15 |
labelWidth labelHeight
|
|
16 |
labelOriginX labelOriginY
|
|
17 |
adjust hSpace vSpace
|
|
18 |
bgColor fgColor fixSize'
|
|
19 |
classVariableNames:'DefaultFont
|
|
20 |
DefaultForegroundColor DefaultBackgroundColor'
|
0
|
21 |
poolDictionaries:''
|
|
22 |
category:'Views-Layout'
|
|
23 |
!
|
|
24 |
|
|
25 |
Label comment:'
|
5
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
27 |
All Rights Reserved
|
0
|
28 |
|
97
|
29 |
$Header: /cvs/stx/stx/libwidg/Label.st,v 1.17 1995-03-06 19:28:54 claus Exp $
|
0
|
30 |
'!
|
|
31 |
|
3
|
32 |
!Label class methodsFor:'documentation'!
|
|
33 |
|
38
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
37 |
All Rights Reserved
|
38
|
38 |
|
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
version
|
|
49 |
"
|
97
|
50 |
$Header: /cvs/stx/stx/libwidg/Label.st,v 1.17 1995-03-06 19:28:54 claus Exp $
|
38
|
51 |
"
|
|
52 |
!
|
|
53 |
|
3
|
54 |
documentation
|
|
55 |
"
|
38
|
56 |
This class implements labels, which are views to display a string or image.
|
|
57 |
The Label will try to do its best to make its contents fit into the
|
|
58 |
view. The contents can be a String, a collection of Strings (i.e.
|
63
|
59 |
Text) or a Form/Image.
|
|
60 |
|
|
61 |
The contents is drawn in fgColor/bgColor, which can be changed using:
|
|
62 |
|
59
|
63 |
aLabel foregroundColor:aColor
|
|
64 |
aLabel backgroundColor:aColor
|
3
|
65 |
|
38
|
66 |
When a label is assigned a contents, it will resize itself to fit
|
|
67 |
the required size. This resizing can be suppressed by setting the
|
|
68 |
fixsize attribute to true using:
|
63
|
69 |
|
59
|
70 |
aLabel sizeFixed:true
|
3
|
71 |
|
38
|
72 |
This can be used, if resizing of the label is not wanted.
|
63
|
73 |
However, in this case you have to make certain that the size is big enough
|
|
74 |
to hold changed logos later.
|
38
|
75 |
|
|
76 |
The placement of the contents within the label is controlled by
|
63
|
77 |
the adjust attribute, it can be set with:
|
|
78 |
|
59
|
79 |
aLabel adjust:how
|
3
|
80 |
|
63
|
81 |
where how is one of the symbols left, #right, #center, #centerLeft or
|
|
82 |
#centerRight (see the comment in Label>>adjust:). The default is #center.
|
3
|
83 |
|
38
|
84 |
Instance variables:
|
3
|
85 |
|
59
|
86 |
logo <Object> the logo, can be a Form, String or Text
|
|
87 |
labelWidth <Integer> the width of the logo in device units
|
|
88 |
labelHeight <Integer> the height of the logo in device units
|
|
89 |
labelOriginX <Integer> the x-position of the logo withing the Label
|
|
90 |
labelOriginY <Integer> the y-position of the logo withing the Label
|
|
91 |
adjust <Symbol> controls how the logo is positioned within the
|
|
92 |
label. Can be one of:#left,#right,#center,
|
|
93 |
#centerLeft or #centerRight (see comment in adjust:)
|
|
94 |
hSpace <Integer> number of horizontal pixels around logo
|
|
95 |
vSpace <Integer> number of vertical pixels around logo
|
3
|
96 |
|
59
|
97 |
bgColor <Color> background color
|
|
98 |
fgColor <Color> foreground color
|
38
|
99 |
|
59
|
100 |
fixSize <Boolean> if true, a change of the logo change will not
|
|
101 |
resize the label; otherwise, its size is adjusted.
|
|
102 |
default:false.
|
50
|
103 |
|
|
104 |
Model-View behavior:
|
59
|
105 |
label model:aModel.
|
|
106 |
label aspect:aspectSymbol.
|
50
|
107 |
|
59
|
108 |
model sends #changed:aspectSymbol
|
|
109 |
---> label will redraw its label from value of model>>aspectSymbol
|
3
|
110 |
"
|
63
|
111 |
!
|
|
112 |
|
|
113 |
examples
|
|
114 |
"
|
|
115 |
Notice, that Buttons and others inherit from Label;
|
|
116 |
therefore, the following geometry examples apply to all subclasses too.
|
|
117 |
|
|
118 |
|
|
119 |
simple:
|
|
120 |
|top l|
|
|
121 |
|
|
122 |
top := StandardSystemView new.
|
|
123 |
top extent:(200 @ 200).
|
|
124 |
|
|
125 |
l := Label in:top.
|
|
126 |
l label:'hello world'.
|
|
127 |
|
|
128 |
top open
|
|
129 |
|
|
130 |
placement:
|
|
131 |
|top l|
|
|
132 |
|
|
133 |
top := StandardSystemView new.
|
|
134 |
top extent:(200 @ 200).
|
|
135 |
|
|
136 |
l := Label in:top.
|
|
137 |
l label:'hello world'.
|
|
138 |
l origin:50@100.
|
|
139 |
|
|
140 |
top open
|
|
141 |
|
|
142 |
level:
|
|
143 |
|top l|
|
|
144 |
|
|
145 |
top := StandardSystemView new.
|
|
146 |
top extent:(200 @ 200).
|
|
147 |
|
|
148 |
l := Label in:top.
|
|
149 |
l level:5.
|
|
150 |
l label:'hello world'.
|
|
151 |
l origin:50@100.
|
|
152 |
|
|
153 |
top open
|
|
154 |
|
|
155 |
another level:
|
|
156 |
|top l|
|
|
157 |
|
|
158 |
top := StandardSystemView new.
|
|
159 |
top extent:(200 @ 200).
|
|
160 |
|
|
161 |
l := Label in:top.
|
|
162 |
l level:-1.
|
|
163 |
l label:'hello world'.
|
|
164 |
l origin:50@100.
|
|
165 |
|
|
166 |
top open
|
|
167 |
|
|
168 |
border & colors:
|
|
169 |
|top l|
|
|
170 |
|
|
171 |
top := StandardSystemView new.
|
|
172 |
top extent:(200 @ 200).
|
|
173 |
|
|
174 |
l := Label in:top.
|
|
175 |
l level:0.
|
|
176 |
l borderWidth:1.
|
|
177 |
l borderColor:Color red.
|
|
178 |
l foregroundColor:Color green darkened.
|
|
179 |
l backgroundColor:Color green lightened.
|
|
180 |
l label:'hello world'.
|
|
181 |
l origin:50@100.
|
|
182 |
|
|
183 |
top open
|
|
184 |
|
|
185 |
adjust (resize to see):
|
|
186 |
|top l|
|
|
187 |
|
|
188 |
top := StandardSystemView new.
|
|
189 |
top extent:(200 @ 200).
|
|
190 |
|
|
191 |
l := Label in:top.
|
|
192 |
l borderWidth:1.
|
|
193 |
l label:'default - centered'.
|
|
194 |
l origin:0.0@70.
|
|
195 |
l width:1.0.
|
|
196 |
|
|
197 |
l := Label in:top.
|
|
198 |
l borderWidth:1.
|
|
199 |
l adjust:#left.
|
|
200 |
l label:'left adjust'.
|
|
201 |
l origin:0.0@100.
|
|
202 |
l width:1.0.
|
|
203 |
|
|
204 |
l := Label in:top.
|
|
205 |
l borderWidth:1.
|
|
206 |
l adjust:#right.
|
|
207 |
l label:'right adjust'.
|
|
208 |
l origin:0.0@130.
|
|
209 |
l width:1.0.
|
|
210 |
|
|
211 |
top open
|
|
212 |
|
|
213 |
just a reminder, that instead of doing placement manually
|
|
214 |
as in:
|
|
215 |
|top l|
|
|
216 |
|
|
217 |
top := StandardSystemView new.
|
|
218 |
top extent:(200 @ 200).
|
|
219 |
|
|
220 |
l := Label in:top.
|
|
221 |
l borderWidth:1.
|
|
222 |
l label:'default - centered'.
|
|
223 |
l origin:0.1@70.
|
|
224 |
l width:0.8.
|
|
225 |
|
|
226 |
l := Label in:top.
|
|
227 |
l borderWidth:1.
|
|
228 |
l adjust:#left.
|
|
229 |
l label:'left adjust'.
|
|
230 |
l origin:0.1@100.
|
|
231 |
l width:0.8.
|
|
232 |
|
|
233 |
l := Label in:top.
|
|
234 |
l borderWidth:1.
|
|
235 |
l adjust:#right.
|
|
236 |
l label:'right adjust'.
|
|
237 |
l origin:0.1@130.
|
|
238 |
l width:0.8.
|
|
239 |
|
|
240 |
top open
|
|
241 |
|
|
242 |
it is much easier, to use a geometry handler, such as
|
|
243 |
a VerticalPanel. Try:
|
|
244 |
|top panel l|
|
|
245 |
|
|
246 |
top := StandardSystemView new.
|
|
247 |
top extent:(200 @ 200).
|
|
248 |
|
|
249 |
panel := VerticalPanelView
|
|
250 |
origin:0.0 @ 0.0
|
|
251 |
corner:1.0 @ 1.0
|
|
252 |
in:top.
|
|
253 |
|
|
254 |
panel horizontalLayout:#fit.
|
|
255 |
panel verticalLayout:#center.
|
|
256 |
|
|
257 |
l := Label in:panel.
|
|
258 |
l borderWidth:1.
|
|
259 |
l label:'default - centered'.
|
|
260 |
|
|
261 |
l := Label in:panel.
|
|
262 |
l borderWidth:1.
|
|
263 |
l adjust:#left.
|
|
264 |
l label:'left adjust'.
|
|
265 |
|
|
266 |
l := Label in:panel.
|
|
267 |
l borderWidth:1.
|
|
268 |
l adjust:#right.
|
|
269 |
l label:'right adjust'.
|
|
270 |
|
|
271 |
top open
|
|
272 |
|
|
273 |
labels with bitmaps or images:
|
|
274 |
|
|
275 |
|top l|
|
|
276 |
|
|
277 |
top := StandardSystemView new.
|
|
278 |
top extent:(200 @ 200).
|
|
279 |
|
|
280 |
l := Label in:top.
|
|
281 |
l level:-1.
|
|
282 |
l form:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.2 @ 0.2).
|
|
283 |
l origin:50@100.
|
|
284 |
|
|
285 |
top open
|
|
286 |
"
|
3
|
287 |
! !
|
|
288 |
|
0
|
289 |
!Label class methodsFor:'defaults'!
|
|
290 |
|
|
291 |
defaultExtent
|
3
|
292 |
"return default extent"
|
0
|
293 |
|
|
294 |
^ 16 @ 16
|
59
|
295 |
!
|
|
296 |
|
|
297 |
updateStyleCache
|
77
|
298 |
DefaultForegroundColor := StyleSheet colorAt:'labelForegroundColor'.
|
|
299 |
DefaultForegroundColor isNil ifTrue:[
|
|
300 |
DefaultForegroundColor := StyleSheet colorAt:'foregroundColor' default:Black.
|
|
301 |
].
|
60
|
302 |
DefaultBackgroundColor := StyleSheet colorAt:'labelBackgroundColor'.
|
77
|
303 |
DefaultBackgroundColor isNil ifTrue:[
|
|
304 |
DefaultForegroundColor := StyleSheet colorAt:'backgroundColor'.
|
|
305 |
].
|
60
|
306 |
DefaultFont := StyleSheet fontAt:'labelFont'.
|
|
307 |
|
|
308 |
"
|
|
309 |
self updateStyleCache
|
|
310 |
"
|
0
|
311 |
! !
|
|
312 |
|
|
313 |
!Label class methodsFor:'instance creation'!
|
|
314 |
|
|
315 |
form:aForm
|
3
|
316 |
"return a new Label showing a form"
|
0
|
317 |
|
|
318 |
^ (self on:Display) form:aForm
|
|
319 |
!
|
|
320 |
|
|
321 |
form:aForm in:aView
|
3
|
322 |
"return a new Label showing a form"
|
0
|
323 |
|
|
324 |
^ (self in:aView) form:aForm
|
|
325 |
! !
|
|
326 |
|
|
327 |
!Label methodsFor:'initialization'!
|
|
328 |
|
|
329 |
initialize
|
|
330 |
super initialize.
|
|
331 |
|
|
332 |
font := font on:device.
|
|
333 |
self height:(font height + font descent).
|
|
334 |
adjust := #center.
|
|
335 |
labelOriginX := 0.
|
|
336 |
labelOriginY := 0.
|
|
337 |
labelWidth := 0.
|
|
338 |
labelHeight := 0.
|
|
339 |
logo := nil.
|
|
340 |
fixSize := false.
|
|
341 |
hSpace := (self horizontalPixelPerMillimeter:0.5) rounded.
|
|
342 |
vSpace := (self verticalPixelPerMillimeter:0.5) rounded
|
|
343 |
!
|
|
344 |
|
|
345 |
initStyle
|
|
346 |
super initStyle.
|
|
347 |
|
59
|
348 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device].
|
|
349 |
DefaultBackgroundColor notNil ifTrue:[
|
|
350 |
bgColor := DefaultBackgroundColor on:device
|
38
|
351 |
] ifFalse:[
|
59
|
352 |
bgColor := viewBackground on:device.
|
|
353 |
].
|
|
354 |
DefaultForegroundColor notNil ifTrue:[
|
|
355 |
fgColor := DefaultForegroundColor on:device
|
|
356 |
] ifFalse:[
|
|
357 |
fgColor := Black on:device.
|
38
|
358 |
]
|
0
|
359 |
!
|
|
360 |
|
|
361 |
realize
|
|
362 |
super realize.
|
|
363 |
fgColor := fgColor on:device.
|
|
364 |
bgColor := bgColor on:device.
|
|
365 |
!
|
|
366 |
|
|
367 |
recreate
|
|
368 |
"after snapin, labels dimensions may have changed due to
|
|
369 |
different font parameters"
|
|
370 |
|
|
371 |
super recreate.
|
3
|
372 |
font := font on:device.
|
0
|
373 |
self computeLabelSize.
|
|
374 |
self computeLabelOrigin
|
|
375 |
! !
|
|
376 |
|
|
377 |
!Label methodsFor:'accessing'!
|
|
378 |
|
|
379 |
foregroundColor
|
|
380 |
"return the foreground color"
|
|
381 |
|
|
382 |
^ fgColor
|
|
383 |
!
|
|
384 |
|
|
385 |
foregroundColor:aColor
|
|
386 |
"set the foreground color"
|
|
387 |
|
|
388 |
fgColor := aColor on:device.
|
|
389 |
self redraw
|
|
390 |
!
|
|
391 |
|
|
392 |
backgroundColor
|
|
393 |
"return the background color"
|
|
394 |
|
|
395 |
^ bgColor
|
|
396 |
!
|
|
397 |
|
|
398 |
backgroundColor:aColor
|
|
399 |
"set the background color"
|
|
400 |
|
|
401 |
bgColor := aColor on:device.
|
|
402 |
self redraw
|
|
403 |
!
|
|
404 |
|
|
405 |
foregroundColor:fg backgroundColor:bg
|
|
406 |
"set the colors to be used for drawing"
|
|
407 |
|
|
408 |
fgColor := fg on:device.
|
|
409 |
bgColor := bg on:device.
|
|
410 |
self redraw
|
|
411 |
!
|
|
412 |
|
|
413 |
sizeFixed:aBoolean
|
|
414 |
"set/clear the fix-size attribute (will not change size on label-change)"
|
|
415 |
|
|
416 |
fixSize := aBoolean
|
|
417 |
!
|
|
418 |
|
38
|
419 |
sizeFixed
|
|
420 |
"return the fix-size attribute"
|
|
421 |
|
|
422 |
^ fixSize
|
|
423 |
!
|
|
424 |
|
0
|
425 |
label:aString
|
|
426 |
"set the label-string; adjust extent if not already realized"
|
|
427 |
|
|
428 |
(logo = aString) ifFalse:[
|
59
|
429 |
logo := aString.
|
|
430 |
self newLayout
|
0
|
431 |
]
|
|
432 |
!
|
|
433 |
|
|
434 |
label
|
3
|
435 |
"return the labels string"
|
0
|
436 |
|
|
437 |
^ logo
|
|
438 |
!
|
|
439 |
|
|
440 |
labelWidth
|
3
|
441 |
"return the logos width in pixels"
|
0
|
442 |
|
|
443 |
^ labelWidth
|
|
444 |
!
|
|
445 |
|
|
446 |
font:aFont
|
|
447 |
"set the font - if I'm not realized, adjust my size"
|
|
448 |
|
|
449 |
(aFont ~~ font) ifTrue:[
|
59
|
450 |
super font:(aFont on:device).
|
|
451 |
self newLayout
|
0
|
452 |
]
|
|
453 |
!
|
|
454 |
|
|
455 |
adjust:how
|
|
456 |
"set the adjust, how which must be one of
|
|
457 |
|
|
458 |
#left -> left adjust logo
|
|
459 |
#right -> right adjust logo
|
|
460 |
#center -> center logo
|
|
461 |
#centerLeft -> center logo; if it does not fit, left adjust it
|
|
462 |
#centerRight -> center logo; if no fit, right adjust
|
|
463 |
"
|
|
464 |
(adjust ~~ how) ifTrue:[
|
59
|
465 |
adjust := how.
|
|
466 |
self newLayout
|
0
|
467 |
]
|
|
468 |
!
|
|
469 |
|
|
470 |
form:aForm
|
|
471 |
"set the labels form; adjust extent if not already realized"
|
|
472 |
|
87
|
473 |
(aForm notNil and:[aForm ~~ logo]) ifTrue:[
|
|
474 |
logo notNil ifTrue:[
|
|
475 |
logo isImageOrForm ifTrue:[
|
59
|
476 |
logo extent = aForm extent ifTrue:[
|
|
477 |
logo := aForm.
|
|
478 |
^ self
|
|
479 |
]
|
87
|
480 |
]
|
|
481 |
].
|
|
482 |
logo := aForm.
|
|
483 |
self newLayout
|
59
|
484 |
]
|
|
485 |
!
|
|
486 |
|
|
487 |
logo:something
|
|
488 |
"set the labels form or string"
|
|
489 |
|
87
|
490 |
logo isImageOrForm ifTrue:[
|
59
|
491 |
self form:something
|
87
|
492 |
] ifFalse:[
|
59
|
493 |
self label:something
|
0
|
494 |
]
|
|
495 |
! !
|
|
496 |
|
50
|
497 |
!Label methodsFor:'change & update'!
|
|
498 |
|
|
499 |
update:something
|
|
500 |
"the MVC way of changing the label ..."
|
|
501 |
|
97
|
502 |
(aspectSymbol notNil
|
|
503 |
and:[something == aspectSymbol]) ifTrue:[
|
59
|
504 |
model notNil ifTrue:[
|
|
505 |
self label:(model perform: aspectSymbol) printString.
|
|
506 |
].
|
|
507 |
^ self.
|
50
|
508 |
].
|
|
509 |
super update:something
|
|
510 |
! !
|
|
511 |
|
38
|
512 |
!Label methodsFor:'queries'!
|
|
513 |
|
59
|
514 |
preferedExtent
|
|
515 |
"return my prefered extent - this is the minimum size I would like to have"
|
38
|
516 |
|
|
517 |
|extra|
|
|
518 |
|
|
519 |
logo notNil ifTrue:[
|
59
|
520 |
extra := margin * 2.
|
|
521 |
^ (labelWidth + extra) @ (labelHeight + extra)
|
38
|
522 |
].
|
|
523 |
|
59
|
524 |
^ super preferedExtent
|
38
|
525 |
! !
|
|
526 |
|
0
|
527 |
!Label methodsFor:'private'!
|
|
528 |
|
|
529 |
newLayout
|
|
530 |
"recompute position/size after a change
|
|
531 |
- helper for form:/font: etc."
|
|
532 |
|
|
533 |
self computeLabelSize.
|
|
534 |
fixSize ifFalse:[
|
59
|
535 |
self resize
|
0
|
536 |
] ifTrue:[
|
59
|
537 |
self computeLabelOrigin
|
0
|
538 |
].
|
3
|
539 |
shown ifTrue:[
|
59
|
540 |
self redraw
|
3
|
541 |
]
|
0
|
542 |
!
|
|
543 |
|
|
544 |
resize
|
69
|
545 |
"resize myself to make text fit into myself.
|
|
546 |
but only do so, if I have not been given a relative extent
|
|
547 |
or an extend computation block."
|
0
|
548 |
|
|
549 |
|extra|
|
|
550 |
|
3
|
551 |
logo notNil ifTrue:[
|
59
|
552 |
(relativeExtent isNil and:[extentRule isNil]) ifTrue:[
|
69
|
553 |
(relativeCorner isNil and:[cornerRule isNil]) ifTrue:[
|
|
554 |
extra := margin * 2.
|
|
555 |
self extent:(labelWidth + extra) @ (labelHeight + extra)
|
|
556 |
].
|
59
|
557 |
].
|
|
558 |
self computeLabelOrigin
|
0
|
559 |
]
|
|
560 |
!
|
|
561 |
|
|
562 |
computeLabelSize
|
|
563 |
"compute the extent needed to hold the label; aForm or aString"
|
|
564 |
|
|
565 |
|numberOfLines textHeight textWidth|
|
|
566 |
|
87
|
567 |
logo isNil ifTrue:[^ self].
|
|
568 |
|
|
569 |
logo isImageOrForm ifTrue:[
|
|
570 |
labelWidth := logo width.
|
|
571 |
labelHeight := logo height.
|
59
|
572 |
^ self
|
0
|
573 |
].
|
|
574 |
|
87
|
575 |
"must be a String or collection of strings"
|
|
576 |
logo isString ifTrue:[
|
59
|
577 |
numberOfLines := 1 + (logo occurrencesOf:(Character cr)).
|
|
578 |
(numberOfLines ~~ 1) ifTrue:[
|
81
|
579 |
logo := logo asStringCollection
|
59
|
580 |
]
|
0
|
581 |
] ifFalse:[
|
59
|
582 |
numberOfLines := logo size.
|
|
583 |
(numberOfLines == 1) ifTrue:[
|
|
584 |
logo := logo asString
|
|
585 |
]
|
0
|
586 |
].
|
|
587 |
|
|
588 |
textHeight := font height * numberOfLines + font descent.
|
|
589 |
textWidth := font widthOf:logo.
|
25
|
590 |
labelWidth := textWidth + (hSpace * 2) .
|
|
591 |
labelHeight := textHeight + (vSpace * 2)
|
0
|
592 |
!
|
|
593 |
|
|
594 |
computeLabelOrigin
|
|
595 |
"(re)compute the origin of the label whenever label or font changes"
|
|
596 |
|
|
597 |
|x y|
|
|
598 |
|
|
599 |
labelHeight isNil ifTrue:[^ self].
|
|
600 |
|
63
|
601 |
"if it does not fit, should we make the origin visible,
|
|
602 |
or the center (for text, the center seems better. For images,
|
|
603 |
I dont really know ehich is better ...
|
|
604 |
The commented code below makes the origin visible
|
|
605 |
"
|
|
606 |
"/ (labelHeight < height) ifTrue:[
|
|
607 |
"/ y := (height - labelHeight) // 2
|
|
608 |
"/ ] ifFalse:[
|
|
609 |
"/ y := 0
|
|
610 |
"/ ].
|
|
611 |
|
|
612 |
"always center vertically"
|
|
613 |
y := (height - labelHeight) // 2.
|
|
614 |
|
0
|
615 |
labelOriginY := y.
|
|
616 |
|
|
617 |
(((adjust == #center)
|
|
618 |
or:[adjust == #centerRight])
|
|
619 |
or:[adjust == #centerLeft]) ifTrue:[
|
59
|
620 |
" center text/form in button "
|
|
621 |
x := (width - labelWidth) // 2.
|
|
622 |
(width < labelWidth) ifTrue:[
|
|
623 |
"no fit"
|
|
624 |
(adjust == #centerLeft) ifTrue:[
|
|
625 |
x := margin
|
|
626 |
] ifFalse:[
|
|
627 |
(adjust == #centerRight) ifTrue:[
|
|
628 |
x := width - labelWidth - margin
|
|
629 |
]
|
|
630 |
]
|
|
631 |
]
|
0
|
632 |
] ifFalse:[
|
59
|
633 |
(adjust == #left) ifTrue:[
|
|
634 |
x := margin
|
|
635 |
] ifFalse:[
|
|
636 |
x := width - labelWidth - margin
|
|
637 |
]
|
0
|
638 |
].
|
|
639 |
labelOriginX := x
|
|
640 |
! !
|
|
641 |
|
70
|
642 |
!Label methodsFor:'event handling'!
|
0
|
643 |
|
|
644 |
sizeChanged:how
|
3
|
645 |
"sent whenever size is changed by someone else - recompute the
|
|
646 |
logos position within the View."
|
0
|
647 |
|
77
|
648 |
|prevPosition|
|
|
649 |
|
|
650 |
prevPosition := labelOriginX.
|
0
|
651 |
self computeLabelOrigin
|
77
|
652 |
shown ifTrue:[
|
|
653 |
labelOriginX ~~ prevPosition ifTrue:[
|
|
654 |
self redraw
|
|
655 |
]
|
|
656 |
]
|
0
|
657 |
! !
|
|
658 |
|
|
659 |
!Label methodsFor:'redrawing'!
|
|
660 |
|
77
|
661 |
clearInsideWith:bg
|
|
662 |
|cutOff mustClear|
|
0
|
663 |
|
|
664 |
cutOff := margin * 2.
|
|
665 |
|
3
|
666 |
mustClear := true.
|
|
667 |
|
87
|
668 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[
|
59
|
669 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[
|
|
670 |
logo width >= (width - cutOff) ifTrue:[
|
|
671 |
logo height >= (height - cutOff) ifTrue:[
|
|
672 |
"no need to clear before - avoid flicker"
|
|
673 |
mustClear := false
|
|
674 |
]
|
|
675 |
]
|
|
676 |
].
|
3
|
677 |
].
|
|
678 |
|
|
679 |
mustClear ifTrue:[
|
59
|
680 |
self paint:bg.
|
|
681 |
self fillRectangleX:margin y:margin
|
|
682 |
width:(width - cutOff)
|
|
683 |
height:(height - cutOff).
|
3
|
684 |
].
|
77
|
685 |
!
|
|
686 |
|
|
687 |
drawWith:fg and:bg
|
|
688 |
"redraw my label with fg/bg - this generic method is also used by subclasses
|
|
689 |
(especially Button) to redraw the logo in different colors."
|
|
690 |
|
|
691 |
|x y|
|
|
692 |
|
|
693 |
self clearInsideWith:bg.
|
0
|
694 |
|
|
695 |
logo notNil ifTrue:[
|
59
|
696 |
self paint:fg on:bg.
|
87
|
697 |
logo isImageOrForm ifTrue:[
|
|
698 |
logo := logo on:device.
|
59
|
699 |
"/ self background:bg.
|
|
700 |
self displayOpaqueForm:logo x:labelOriginX y:labelOriginY
|
|
701 |
] ifFalse:[
|
|
702 |
x := labelOriginX + hSpace.
|
|
703 |
y := labelOriginY + (font ascent) + vSpace.
|
0
|
704 |
|
87
|
705 |
logo isString ifTrue:[
|
59
|
706 |
self displayString:logo x:x y:y
|
|
707 |
] ifFalse:[
|
|
708 |
logo do:[ :line |
|
|
709 |
self displayString:(line printString) x:x y:y.
|
|
710 |
y := y + (font height)
|
|
711 |
]
|
|
712 |
]
|
|
713 |
]
|
0
|
714 |
]
|
|
715 |
!
|
|
716 |
|
|
717 |
redraw
|
|
718 |
"redraw my label"
|
|
719 |
|
|
720 |
shown ifTrue:[
|
59
|
721 |
self drawWith:fgColor and:bgColor
|
0
|
722 |
]
|
|
723 |
! !
|