author | Claus Gittinger <cg@exept.de> |
Sun, 17 Dec 1995 15:48:40 +0100 | |
changeset 263 | 74a282375195 |
parent 260 | 475aa7b7d0e9 |
child 275 | a7f95252cdc2 |
permissions | -rw-r--r-- |
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 |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
14 |
instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust |
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
15 |
hSpace vSpace bgColor fgColor fixSize labelMsg converter |
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
16 |
labelChannel foregroundChannel backgroundChannel' |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
17 |
classVariableNames:'DefaultFont DefaultForegroundColor DefaultBackgroundColor' |
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
18 |
poolDictionaries:'' |
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
19 |
category:'Views-Layout' |
0 | 20 |
! |
21 |
||
3 | 22 |
!Label class methodsFor:'documentation'! |
23 |
||
38 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 27 |
All Rights Reserved |
38 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
3 | 38 |
documentation |
39 |
" |
|
38 | 40 |
This class implements labels, which are views to display a string or image. |
41 |
The Label will try to do its best to make its contents fit into the |
|
42 |
view. The contents can be a String, a collection of Strings (i.e. |
|
118 | 43 |
a StringCollection) or a Form/Image. |
63 | 44 |
|
45 |
The contents is drawn in fgColor/bgColor, which can be changed using: |
|
46 |
||
59 | 47 |
aLabel foregroundColor:aColor |
48 |
aLabel backgroundColor:aColor |
|
3 | 49 |
|
38 | 50 |
When a label is assigned a contents, it will resize itself to fit |
51 |
the required size. This resizing can be suppressed by setting the |
|
52 |
fixsize attribute to true using: |
|
63 | 53 |
|
59 | 54 |
aLabel sizeFixed:true |
3 | 55 |
|
38 | 56 |
This can be used, if resizing of the label is not wanted. |
63 | 57 |
However, in this case you have to make certain that the size is big enough |
118 | 58 |
to hold any changed logos later. (usually, you create the label first with |
59 |
the longest string first to have it compute its size, then set the fixSize |
|
60 |
attribute to avoid resizing later). |
|
125 | 61 |
Be careful when placing self-resizing labels into panels - by default, |
62 |
panels do not react on the size change - leading to ugly looking geometry. |
|
63 |
(but you can tell the panel to watch for changes with #elementsCHangeSize:) |
|
38 | 64 |
|
65 |
The placement of the contents within the label is controlled by |
|
63 | 66 |
the adjust attribute, it can be set with: |
67 |
||
59 | 68 |
aLabel adjust:how |
3 | 69 |
|
63 | 70 |
where how is one of the symbols left, #right, #center, #centerLeft or |
71 |
#centerRight (see the comment in Label>>adjust:). The default is #center. |
|
3 | 72 |
|
145 | 73 |
model-less operation (ok for static labels): |
118 | 74 |
if no model is set, the labels contents is set with: |
75 |
||
76 |
aLabel label:aStringOrImage |
|
77 |
||
78 |
and stays constant unless changed by new calls to #label:. |
|
79 |
||
80 |
||
145 | 81 |
model operation (ST-80 style): |
118 | 82 |
labels with a model, aspectMsg and labelMsg react to |
83 |
changes of the aspect, and send a labelMsg-message |
|
84 |
to the model in order to aquire a new labelString or image. |
|
85 |
The model should send 'self changed:aspectMsg' if it thinks the label |
|
86 |
should change and return a string or image from the labelMsg-message. |
|
87 |
||
88 |
label model:aModel. |
|
89 |
label aspect:aspectSymbol. |
|
90 |
label labelMessage:labelSymbol. |
|
91 |
||
92 |
model sends #changed:aspectSymbol |
|
93 |
---> label will redraw its label from value of model perform:labelSymbol |
|
94 |
||
95 |
Having a labelSymbol different from the aspectSymbol allows for two labels |
|
96 |
to react on the same aspect-change, but use different messages when asking |
|
97 |
the model for a new label contents. By default, the labelMsg is nil, |
|
98 |
so the label does NOT update its shown contents. |
|
99 |
The aspectMsg defaults to #value. |
|
100 |
||
125 | 101 |
|
145 | 102 |
|
103 |
channel operation (new ST/X style): |
|
104 |
||
105 |
the label will react on changes of the token found in the |
|
106 |
channels: foregroundChannel, backgroundChannel and labelChannel. |
|
107 |
These are valueHolders and can be shared between labels. |
|
108 |
||
109 |
||
110 |
||
38 | 111 |
Instance variables: |
3 | 112 |
|
59 | 113 |
logo <Object> the logo, can be a Form, String or Text |
114 |
labelWidth <Integer> the width of the logo in device units |
|
115 |
labelHeight <Integer> the height of the logo in device units |
|
116 |
labelOriginX <Integer> the x-position of the logo withing the Label |
|
117 |
labelOriginY <Integer> the y-position of the logo withing the Label |
|
118 |
adjust <Symbol> controls how the logo is positioned within the |
|
119 |
label. Can be one of:#left,#right,#center, |
|
120 |
#centerLeft or #centerRight (see comment in adjust:) |
|
121 |
hSpace <Integer> number of horizontal pixels around logo |
|
122 |
vSpace <Integer> number of vertical pixels around logo |
|
3 | 123 |
|
59 | 124 |
bgColor <Color> background color |
125 |
fgColor <Color> foreground color |
|
38 | 126 |
|
59 | 127 |
fixSize <Boolean> if true, a change of the logo change will not |
128 |
resize the label; otherwise, its size is adjusted. |
|
129 |
default:false. |
|
50 | 130 |
|
118 | 131 |
labelMsg <Symbol> if non-nil, this is sent to the model to |
132 |
aquire the labelString or labelImage. |
|
133 |
If nil, the label stays as is |
|
113 | 134 |
|
118 | 135 |
styleSheet parameters: |
50 | 136 |
|
118 | 137 |
labelForegroundColor <Color> color to draw foreground pixels (i.e. the string) |
138 |
labelBackgroundColor <Color> color to draw background pixels |
|
139 |
labelFont <Font> font to use for textual labels |
|
3 | 140 |
" |
63 | 141 |
! |
142 |
||
143 |
examples |
|
144 |
" |
|
145 |
Notice, that Buttons and others inherit from Label; |
|
146 |
therefore, the following geometry examples apply to all subclasses too. |
|
147 |
||
148 |
||
113 | 149 |
simple (default position is 0@0): |
63 | 150 |
|top l| |
151 |
||
152 |
top := StandardSystemView new. |
|
153 |
top extent:(200 @ 200). |
|
154 |
||
155 |
l := Label in:top. |
|
156 |
l label:'hello world'. |
|
157 |
||
158 |
top open |
|
159 |
||
113 | 160 |
|
161 |
there is also a creation message which sets the label: |
|
162 |
|top l| |
|
163 |
||
164 |
top := StandardSystemView new. |
|
165 |
top extent:(200 @ 200). |
|
166 |
||
167 |
l := Label label:'hello world' in:top. |
|
168 |
||
169 |
top open |
|
170 |
||
171 |
||
63 | 172 |
placement: |
173 |
|top l| |
|
174 |
||
175 |
top := StandardSystemView new. |
|
176 |
top extent:(200 @ 200). |
|
177 |
||
178 |
l := Label in:top. |
|
179 |
l label:'hello world'. |
|
180 |
l origin:50@100. |
|
181 |
||
182 |
top open |
|
183 |
||
113 | 184 |
|
63 | 185 |
level: |
186 |
|top l| |
|
187 |
||
188 |
top := StandardSystemView new. |
|
189 |
top extent:(200 @ 200). |
|
190 |
||
191 |
l := Label in:top. |
|
192 |
l level:5. |
|
193 |
l label:'hello world'. |
|
194 |
l origin:50@100. |
|
195 |
||
196 |
top open |
|
197 |
||
113 | 198 |
|
63 | 199 |
another level: |
200 |
|top l| |
|
201 |
||
202 |
top := StandardSystemView new. |
|
203 |
top extent:(200 @ 200). |
|
204 |
||
205 |
l := Label in:top. |
|
206 |
l level:-1. |
|
207 |
l label:'hello world'. |
|
208 |
l origin:50@100. |
|
209 |
||
210 |
top open |
|
211 |
||
113 | 212 |
|
118 | 213 |
colors & font: |
214 |
|top l| |
|
215 |
||
216 |
top := StandardSystemView new. |
|
217 |
top extent:(200 @ 200). |
|
218 |
||
219 |
l := Label in:top. |
|
220 |
l level:-1. |
|
221 |
l font:(Font family:'Times' size:18). |
|
222 |
l foregroundColor:Color yellow. |
|
223 |
l backgroundColor:Color red. |
|
224 |
l label:'hello world'. |
|
225 |
l origin:50@100. |
|
226 |
||
227 |
top open |
|
228 |
||
229 |
||
63 | 230 |
border & colors: |
231 |
|top l| |
|
232 |
||
233 |
top := StandardSystemView new. |
|
234 |
top extent:(200 @ 200). |
|
235 |
||
236 |
l := Label in:top. |
|
237 |
l level:0. |
|
238 |
l borderWidth:1. |
|
239 |
l borderColor:Color red. |
|
240 |
l foregroundColor:Color green darkened. |
|
241 |
l backgroundColor:Color green lightened. |
|
242 |
l label:'hello world'. |
|
243 |
l origin:50@100. |
|
244 |
||
245 |
top open |
|
246 |
||
113 | 247 |
|
63 | 248 |
adjust (resize to see): |
249 |
|top l| |
|
250 |
||
251 |
top := StandardSystemView new. |
|
252 |
top extent:(200 @ 200). |
|
253 |
||
254 |
l := Label in:top. |
|
255 |
l borderWidth:1. |
|
256 |
l label:'default - centered'. |
|
118 | 257 |
l origin:0.0@40. |
63 | 258 |
l width:1.0. |
259 |
||
260 |
l := Label in:top. |
|
261 |
l borderWidth:1. |
|
262 |
l adjust:#left. |
|
263 |
l label:'left adjust'. |
|
118 | 264 |
l origin:0.0@70. |
265 |
l width:1.0. |
|
266 |
||
267 |
l := Label in:top. |
|
268 |
l borderWidth:1. |
|
269 |
l adjust:#centerLeft. |
|
270 |
l label:'centerLeft adjust and a bit too long'. |
|
63 | 271 |
l origin:0.0@100. |
272 |
l width:1.0. |
|
273 |
||
274 |
l := Label in:top. |
|
275 |
l borderWidth:1. |
|
276 |
l adjust:#right. |
|
277 |
l label:'right adjust'. |
|
278 |
l origin:0.0@130. |
|
279 |
l width:1.0. |
|
280 |
||
118 | 281 |
l := Label in:top. |
282 |
l borderWidth:1. |
|
283 |
l adjust:#centerRight. |
|
284 |
l label:'centerRight adjust and a bit too long'. |
|
285 |
l origin:0.0@160. |
|
286 |
l width:1.0. |
|
287 |
||
63 | 288 |
top open |
289 |
||
113 | 290 |
|
131 | 291 |
fitting-adjust (resize to see): |
292 |
Warning: #fit is experimental and should not be used. |
|
293 |
||
294 |
|top l| |
|
295 |
||
296 |
top := StandardSystemView new. |
|
297 |
top extent:(200 @ 200). |
|
298 |
||
299 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
|
300 |
l label:'stretch'. |
|
301 |
l level:-1. |
|
302 |
l adjust:#fit. |
|
303 |
||
304 |
top open |
|
305 |
||
306 |
or: |
|
307 |
Warning: #fit is experimental and should not be used. |
|
308 |
||
309 |
|top l| |
|
310 |
||
311 |
top := StandardSystemView new. |
|
312 |
top extent:(200 @ 200). |
|
313 |
||
314 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
|
315 |
l label:(Image fromFile:'bitmaps/SBrowser.xbm'). |
|
316 |
l level:-1. |
|
317 |
l adjust:#fit. |
|
318 |
||
319 |
top open |
|
320 |
||
321 |
||
63 | 322 |
just a reminder, that instead of doing placement manually |
113 | 323 |
as in ...: |
118 | 324 |
|
63 | 325 |
|top l| |
326 |
||
327 |
top := StandardSystemView new. |
|
328 |
top extent:(200 @ 200). |
|
329 |
||
330 |
l := Label in:top. |
|
331 |
l borderWidth:1. |
|
332 |
l label:'default - centered'. |
|
333 |
l origin:0.1@70. |
|
334 |
l width:0.8. |
|
335 |
||
336 |
l := Label in:top. |
|
337 |
l borderWidth:1. |
|
338 |
l adjust:#left. |
|
339 |
l label:'left adjust'. |
|
340 |
l origin:0.1@100. |
|
341 |
l width:0.8. |
|
342 |
||
343 |
l := Label in:top. |
|
344 |
l borderWidth:1. |
|
345 |
l adjust:#right. |
|
346 |
l label:'right adjust'. |
|
347 |
l origin:0.1@130. |
|
348 |
l width:0.8. |
|
349 |
||
350 |
top open |
|
351 |
||
113 | 352 |
|
353 |
... it is much easier, to use a geometry handler, such as |
|
63 | 354 |
a VerticalPanel. Try: |
113 | 355 |
|
63 | 356 |
|top panel l| |
357 |
||
358 |
top := StandardSystemView new. |
|
359 |
top extent:(200 @ 200). |
|
360 |
||
361 |
panel := VerticalPanelView |
|
362 |
origin:0.0 @ 0.0 |
|
363 |
corner:1.0 @ 1.0 |
|
364 |
in:top. |
|
365 |
||
366 |
panel horizontalLayout:#fit. |
|
367 |
panel verticalLayout:#center. |
|
368 |
||
369 |
l := Label in:panel. |
|
370 |
l borderWidth:1. |
|
371 |
l label:'default - centered'. |
|
372 |
||
373 |
l := Label in:panel. |
|
374 |
l borderWidth:1. |
|
375 |
l adjust:#left. |
|
376 |
l label:'left adjust'. |
|
377 |
||
378 |
l := Label in:panel. |
|
379 |
l borderWidth:1. |
|
380 |
l adjust:#right. |
|
381 |
l label:'right adjust'. |
|
382 |
||
383 |
top open |
|
384 |
||
113 | 385 |
|
63 | 386 |
labels with bitmaps or images: |
387 |
||
388 |
|top l| |
|
389 |
||
390 |
top := StandardSystemView new. |
|
391 |
top extent:(200 @ 200). |
|
392 |
||
393 |
l := Label in:top. |
|
394 |
l level:-1. |
|
118 | 395 |
l label:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.2 @ 0.2). |
63 | 396 |
l origin:50@100. |
397 |
||
398 |
top open |
|
113 | 399 |
|
400 |
||
145 | 401 |
Channel operation |
402 |
----------------- |
|
403 |
||
404 |
|top panel logoChannel fgChannel bgChannel l b| |
|
405 |
||
406 |
top := StandardSystemView new. |
|
407 |
top extent:(450 @ 200). |
|
408 |
||
409 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
410 |
||
411 |
l := Label in:panel. |
|
412 |
l level:-1. |
|
413 |
l label:'change my colors'. |
|
414 |
l origin:50@100. |
|
415 |
l sizeFixed:true. |
|
416 |
||
417 |
fgChannel := Color blue asValue. |
|
146 | 418 |
bgChannel := Color grey asValue. |
145 | 419 |
logoChannel := 'change me' asValue. |
420 |
||
421 |
b := Toggle label:'change fg' in:panel. b showLamp:false; onLevel:-2. |
|
422 |
b pressAction:[fgChannel value:Color red]. |
|
423 |
b releaseAction:[fgChannel value:Color blue]. |
|
424 |
||
425 |
b := Toggle label:'change bg' in:panel. |
|
426 |
b pressAction:[bgChannel value:Color yellow]. |
|
427 |
b releaseAction:[bgChannel value:Color grey]. |
|
428 |
||
429 |
b := Toggle label:'change text' in:panel. |
|
430 |
b pressAction:[logoChannel value:'wow']. |
|
431 |
b releaseAction:[logoChannel value:'not bad' ]. |
|
432 |
||
433 |
l labelChannel:logoChannel. |
|
434 |
l foregroundChannel:fgChannel. |
|
435 |
l backgroundChannel:bgChannel. |
|
436 |
||
437 |
top open |
|
438 |
||
439 |
||
146 | 440 |
multiple labels on one channel: |
441 |
||
442 |
|l1 l2 b conv| |
|
443 |
||
444 |
l1 := Label label:'label1'. |
|
445 |
||
446 |
l2 := Label label:'label2'. |
|
447 |
||
448 |
b := Button label:'change'. |
|
449 |
conv := (ConvertedValue new |
|
450 |
conversion:[:input | |
|
451 |
input ifTrue:[ |
|
452 |
Color red |
|
453 |
] ifFalse:[ |
|
454 |
Color blue |
|
455 |
]]). |
|
456 |
conv value:false. |
|
457 |
||
458 |
b controller pressChannel:conv. |
|
459 |
l1 foregroundChannel:conv. |
|
460 |
l2 foregroundColor:Color white; backgroundChannel:conv. |
|
461 |
||
462 |
b open. |
|
463 |
l1 open. |
|
464 |
l2 open. |
|
465 |
||
466 |
||
125 | 467 |
MVC operation |
145 | 468 |
------------- |
469 |
||
125 | 470 |
model provides the label): |
471 |
(have to use a plug to simulate a model which responds to |
|
472 |
the #someAspect message): |
|
113 | 473 |
|
474 |
|top l model| |
|
475 |
||
476 |
model := Plug new. |
|
477 |
model respondTo:#someAspect with:['models labelString']. |
|
478 |
||
479 |
top := StandardSystemView new. |
|
480 |
top extent:(200 @ 200). |
|
481 |
||
482 |
l := Label in:top. |
|
118 | 483 |
l model:model; labelMessage:#someAspect. |
113 | 484 |
|
485 |
top open |
|
118 | 486 |
... |
487 |
||
488 |
model changed:#someAspect |
|
489 |
... |
|
113 | 490 |
|
491 |
||
118 | 492 |
concrete example (track a counters value): |
125 | 493 |
(here, the default aspect #value is used both to notify the label about |
494 |
changes and to aquire a new value from the model). |
|
113 | 495 |
|
496 |
|top l model| |
|
497 |
||
118 | 498 |
model := ValueHolder new. |
499 |
model value:0. |
|
500 |
[ |
|
501 |
1 to:20 do:[:i | |
|
502 |
(Delay forSeconds:1) wait. |
|
503 |
model value:i |
|
504 |
]. |
|
505 |
top destroy |
|
506 |
] fork. |
|
113 | 507 |
|
508 |
top := StandardSystemView new. |
|
509 |
top extent:(200 @ 200). |
|
510 |
||
511 |
l := Label in:top. |
|
125 | 512 |
l level:-1. |
118 | 513 |
l model:model; labelMessage:#value. |
514 |
||
515 |
top open |
|
516 |
||
517 |
||
133 | 518 |
with a printConverter: |
519 |
||
520 |
|top l model| |
|
521 |
||
522 |
model := Date today asValue. |
|
523 |
[ |
|
524 |
1 to:50 do:[:i | |
|
525 |
(Delay forSeconds:1) wait. |
|
526 |
model value:(model value addDays:1) |
|
527 |
]. |
|
528 |
top destroy |
|
529 |
] fork. |
|
530 |
||
531 |
top := StandardSystemView new. |
|
532 |
top extent:(200 @ 200). |
|
533 |
||
534 |
l := Label in:top. |
|
535 |
l level:-1. |
|
536 |
l converter:(PrintConverter new initForDate). |
|
537 |
l model:model; labelMessage:#value. |
|
538 |
||
539 |
top open |
|
540 |
||
541 |
||
125 | 542 |
model changes aspect after a while; two labels on the same model: |
118 | 543 |
|
544 |
|top l model| |
|
545 |
||
546 |
model := Plug new. |
|
547 |
model respondTo:#labelValue1 with:['models labelString1']. |
|
548 |
model respondTo:#labelValue2 with:['models labelString2']. |
|
549 |
||
550 |
top := StandardSystemView new. |
|
551 |
top extent:(200 @ 200). |
|
552 |
||
553 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
|
554 |
l model:model; aspect:#someAspect; labelMessage:#labelValue1. |
|
555 |
l := Label origin:0.0@0.5 corner:1.0@1.0 in:top. |
|
556 |
l model:model; aspect:#someAspect; labelMessage:#labelValue2. |
|
113 | 557 |
|
558 |
top open. |
|
118 | 559 |
|
113 | 560 |
(Delay forSeconds:5) wait. |
118 | 561 |
model respondTo:#labelValue1 with:['new string1']. |
562 |
model respondTo:#labelValue2 with:['new string2']. |
|
563 |
||
113 | 564 |
model changed:#someAspect |
118 | 565 |
|
566 |
||
125 | 567 |
plugged MVC operation (getBlock returns the label): |
118 | 568 |
|
569 |
|top l model| |
|
570 |
||
571 |
model := PluggableAdaptor new |
|
572 |
getBlock:[:m | 'hello'] |
|
573 |
putBlock:nil |
|
574 |
updateBlock:nil. |
|
575 |
||
576 |
top := StandardSystemView new. |
|
577 |
top extent:(200 @ 200). |
|
578 |
||
579 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
|
580 |
l model:model; labelMessage:#value. |
|
581 |
||
582 |
top open. |
|
125 | 583 |
|
584 |
||
585 |
use different label-selectors to access fields of a complex model: |
|
586 |
||
587 |
|top panel model| |
|
588 |
||
589 |
model := Plug new. |
|
590 |
model respondTo:#field1 with:['value1']. |
|
591 |
model respondTo:#field2 with:['value2']. |
|
592 |
model respondTo:#field3 with:['value3']. |
|
593 |
model respondTo:#field4 with:['value4']. |
|
594 |
||
595 |
top := StandardSystemView new. |
|
596 |
||
597 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
598 |
panel elementsChangeSize:true. |
|
599 |
||
600 |
panel addSubView:((Label on:model) labelMessage:#field1). |
|
601 |
panel addSubView:((Label on:model) labelMessage:#field2). |
|
602 |
panel addSubView:((Label on:model) labelMessage:#field3). |
|
603 |
panel addSubView:((Label on:model) labelMessage:#field4). |
|
604 |
||
605 |
top extent:(200 @ 200). |
|
606 |
top open. |
|
607 |
||
608 |
(Delay forSeconds:5) wait. |
|
609 |
||
610 |
model respondTo:#field2 with:['new value2']. |
|
611 |
model changed:#value |
|
612 |
||
613 |
||
614 |
same as above, using default aspects in the label, and an adaptor |
|
615 |
to translate aspects: |
|
616 |
||
617 |
|top panel model v1| |
|
618 |
||
619 |
model := Plug new. |
|
620 |
model respondTo:#field1 with:[v1]. |
|
621 |
model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1]. |
|
622 |
model respondTo:#field2 with:['value2']. |
|
623 |
model respondTo:#field2: with:[:arg |]. |
|
624 |
model respondTo:#field3 with:['value3']. |
|
625 |
model respondTo:#field3: with:[:arg |]. |
|
626 |
model respondTo:#field4 with:['value4']. |
|
627 |
model respondTo:#field4: with:[:arg |]. |
|
628 |
||
629 |
top := StandardSystemView new. |
|
630 |
||
631 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
632 |
panel elementsChangeSize:true. |
|
633 |
||
634 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value). |
|
635 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value). |
|
636 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value). |
|
637 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value). |
|
638 |
||
639 |
top extent:(200 @ 200). |
|
640 |
top open. |
|
641 |
||
642 |
(Delay forSeconds:5) wait. |
|
643 |
||
644 |
model field1:'new value1'. |
|
645 |
||
646 |
||
647 |
use an adapter to access fields of a complex model: |
|
648 |
||
649 |
|top l panel model| |
|
650 |
||
651 |
model := #('one' 'two' 'three') asValue. |
|
652 |
||
653 |
top := StandardSystemView new. |
|
654 |
||
655 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
656 |
panel elementsChangeSize:true. |
|
657 |
||
658 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
659 |
subjectChannel:model |
|
660 |
accessPath:#(1))) labelMessage:#value). |
|
661 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
662 |
subjectChannel:model |
|
663 |
accessPath:#(2))) labelMessage:#value). |
|
664 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
665 |
subjectChannel:model |
|
666 |
accessPath:#(3))) labelMessage:#value). |
|
667 |
||
668 |
top extent:(200 @ 200). |
|
669 |
top open. |
|
670 |
||
671 |
(Delay forSeconds:5) wait. |
|
672 |
||
673 |
model value:#('oneone' 'twotwo' 'threethree'). |
|
63 | 674 |
" |
3 | 675 |
! ! |
676 |
||
105 | 677 |
!Label class methodsFor:'instance creation'! |
678 |
||
679 |
form:aForm |
|
118 | 680 |
"return a new Label showing a form. |
681 |
OBSOLETE: you should now use #label: for both text and bitmap labels." |
|
105 | 682 |
|
131 | 683 |
^ (self on:Screen current) form:aForm |
105 | 684 |
! |
685 |
||
686 |
form:aForm in:aView |
|
118 | 687 |
"return a new Label showing a form. |
688 |
OBSOLETE: you should now use #label:in: for both text and bitmap labels." |
|
105 | 689 |
|
690 |
^ (self in:aView) form:aForm |
|
691 |
! ! |
|
692 |
||
0 | 693 |
!Label class methodsFor:'defaults'! |
694 |
||
695 |
defaultExtent |
|
3 | 696 |
"return default extent" |
0 | 697 |
|
698 |
^ 16 @ 16 |
|
59 | 699 |
! |
700 |
||
118 | 701 |
defaultFont |
702 |
^ DefaultFont notNil ifTrue:[DefaultFont] ifFalse:[super defaultFont] |
|
703 |
! |
|
704 |
||
59 | 705 |
updateStyleCache |
77 | 706 |
DefaultForegroundColor := StyleSheet colorAt:'labelForegroundColor'. |
707 |
DefaultForegroundColor isNil ifTrue:[ |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
708 |
DefaultForegroundColor := StyleSheet colorAt:'foregroundColor' default:Black. |
77 | 709 |
]. |
60 | 710 |
DefaultBackgroundColor := StyleSheet colorAt:'labelBackgroundColor'. |
77 | 711 |
DefaultBackgroundColor isNil ifTrue:[ |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
712 |
DefaultBackgroundColor := StyleSheet colorAt:'backgroundColor'. |
77 | 713 |
]. |
60 | 714 |
DefaultFont := StyleSheet fontAt:'labelFont'. |
715 |
||
716 |
" |
|
717 |
self updateStyleCache |
|
718 |
" |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
719 |
|
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
720 |
"Modified: 14.12.1995 / 14:33:55 / cg" |
0 | 721 |
! ! |
722 |
||
202 | 723 |
!Label methodsFor:'accessing-channels'! |
105 | 724 |
|
260 | 725 |
backgroundChannel |
726 |
^ backgroundChannel. |
|
727 |
||
728 |
"Created: 16.12.1995 / 15:50:08 / cg" |
|
729 |
! |
|
730 |
||
202 | 731 |
backgroundChannel:aValueHolder |
732 |
|prev| |
|
105 | 733 |
|
202 | 734 |
prev := backgroundChannel. |
735 |
backgroundChannel := aValueHolder. |
|
736 |
self setupChannel:aValueHolder for:#backgroundChannelChanged withOld:prev |
|
737 |
! |
|
145 | 738 |
|
260 | 739 |
foregroundChannel |
740 |
^ foregroundChannel. |
|
741 |
||
742 |
"Created: 16.12.1995 / 15:50:01 / cg" |
|
743 |
! |
|
744 |
||
145 | 745 |
foregroundChannel:aValueHolder |
146 | 746 |
|prev| |
747 |
||
748 |
prev := foregroundChannel. |
|
145 | 749 |
foregroundChannel := aValueHolder. |
146 | 750 |
self setupChannel:aValueHolder for:#foregroundChannelChanged withOld:prev |
145 | 751 |
! |
752 |
||
260 | 753 |
labelChannel |
754 |
^ labelChannel. |
|
755 |
||
756 |
"Created: 16.12.1995 / 15:50:18 / cg" |
|
757 |
! |
|
758 |
||
145 | 759 |
labelChannel:aValueHolder |
146 | 760 |
|prev| |
761 |
||
762 |
prev := labelChannel. |
|
145 | 763 |
labelChannel := aValueHolder. |
146 | 764 |
self setupChannel:aValueHolder for:#labelChannelChanged withOld:prev |
145 | 765 |
! ! |
766 |
||
202 | 767 |
!Label methodsFor:'accessing-colors'! |
125 | 768 |
|
202 | 769 |
backgroundColor |
770 |
"return the background color" |
|
125 | 771 |
|
202 | 772 |
^ bgColor |
125 | 773 |
! |
774 |
||
202 | 775 |
backgroundColor:aColor |
776 |
"set the background color" |
|
125 | 777 |
|
263 | 778 |
aColor ~~ bgColor ifTrue:[ |
779 |
bgColor := aColor on:device. |
|
780 |
shown ifTrue:[self redraw] |
|
781 |
] |
|
782 |
||
783 |
"Modified: 17.12.1995 / 15:09:03 / cg" |
|
105 | 784 |
! |
785 |
||
786 |
foregroundColor |
|
787 |
"return the foreground color" |
|
788 |
||
789 |
^ fgColor |
|
790 |
! |
|
791 |
||
202 | 792 |
foregroundColor:aColor |
793 |
"set the foreground color" |
|
105 | 794 |
|
263 | 795 |
aColor ~~ fgColor ifTrue:[ |
796 |
fgColor := aColor on:device. |
|
797 |
shown ifTrue:[self redraw] |
|
798 |
]. |
|
799 |
||
800 |
"Modified: 17.12.1995 / 15:09:15 / cg" |
|
105 | 801 |
! |
802 |
||
803 |
foregroundColor:fg backgroundColor:bg |
|
804 |
"set the colors to be used for drawing" |
|
805 |
||
806 |
fgColor := fg on:device. |
|
807 |
bgColor := bg on:device. |
|
131 | 808 |
shown ifTrue:[self redraw] |
133 | 809 |
! ! |
810 |
||
811 |
!Label methodsFor:'accessing-contents'! |
|
0 | 812 |
|
202 | 813 |
form:aForm |
814 |
"set the labels form; adjust extent if not already realized. |
|
815 |
OBSOLETE: you should now use #label: for both strings and images" |
|
118 | 816 |
|
202 | 817 |
self label:aForm |
818 |
! |
|
819 |
||
820 |
label |
|
821 |
"return the labels string or image" |
|
822 |
||
823 |
^ logo |
|
118 | 824 |
! |
105 | 825 |
|
118 | 826 |
label:aStringOrFormOrImage |
827 |
"set the labelString or image; adjust extent if not already realized and |
|
828 |
not fixedSize" |
|
829 |
||
830 |
(aStringOrFormOrImage ~~ logo) ifTrue:[ |
|
831 |
"/ |
|
832 |
"/ avoid recompute of size, if its an image with |
|
833 |
"/ the same size |
|
834 |
"/ |
|
835 |
aStringOrFormOrImage isImageOrForm ifTrue:[ |
|
836 |
logo notNil ifTrue:[ |
|
837 |
logo isImageOrForm ifTrue:[ |
|
838 |
logo extent = aStringOrFormOrImage extent ifTrue:[ |
|
839 |
logo := aStringOrFormOrImage. |
|
840 |
^ self |
|
841 |
] |
|
105 | 842 |
] |
843 |
] |
|
118 | 844 |
] ifFalse:[ |
845 |
(logo = aStringOrFormOrImage) ifTrue:[ |
|
846 |
^ self |
|
847 |
] |
|
105 | 848 |
]. |
118 | 849 |
logo := aStringOrFormOrImage. |
105 | 850 |
self newLayout |
851 |
] |
|
852 |
! |
|
0 | 853 |
|
202 | 854 |
labelString:aString |
855 |
"for ST-80 compatibility: same as #label: |
|
856 |
set the label-string; adjust extent if not already realized and not fixedSize" |
|
118 | 857 |
|
202 | 858 |
self label:aString |
859 |
! |
|
860 |
||
861 |
labelWidth |
|
862 |
"return the logos width in pixels" |
|
863 |
||
864 |
^ labelWidth |
|
118 | 865 |
! |
866 |
||
867 |
logo:something |
|
868 |
"set the labels form or string. |
|
869 |
OBSOLETE: the old version used #form: for images and #label: for strings. |
|
870 |
you should now use #label: for any." |
|
871 |
||
872 |
self label:something |
|
133 | 873 |
! ! |
874 |
||
875 |
!Label methodsFor:'accessing-layout'! |
|
876 |
||
202 | 877 |
adjust |
878 |
"return the adjust symbol" |
|
0 | 879 |
|
202 | 880 |
^ adjust |
125 | 881 |
! |
882 |
||
105 | 883 |
adjust:how |
884 |
"set the adjust, how which must be one of |
|
0 | 885 |
|
105 | 886 |
#left -> left adjust logo |
887 |
#right -> right adjust logo |
|
888 |
#center -> center logo |
|
118 | 889 |
#centerRight -> center logo; if no fit, right adjust |
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
890 |
(use with filenames, where the interesting part is |
118 | 891 |
at the right if the label is too small) |
105 | 892 |
#centerLeft -> center logo; if it does not fit, left adjust it |
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
254
diff
changeset
|
893 |
(use with strings where the interesting part is at the |
118 | 894 |
left if the label is too small) |
105 | 895 |
" |
118 | 896 |
|
105 | 897 |
(adjust ~~ how) ifTrue:[ |
898 |
adjust := how. |
|
899 |
self newLayout |
|
900 |
] |
|
901 |
! |
|
902 |
||
202 | 903 |
font:aFont |
904 |
"set the font - if I'm not realized and not fixedSize, adjust my size" |
|
125 | 905 |
|
202 | 906 |
(aFont ~~ font) ifTrue:[ |
907 |
super font:(aFont on:device). |
|
908 |
self newLayout |
|
909 |
] |
|
133 | 910 |
! |
911 |
||
912 |
horizontalSpace:aNumber |
|
913 |
"set the number of pixels by which the logo |
|
914 |
is horizontally inset from the border" |
|
915 |
||
162 | 916 |
hSpace := aNumber. |
917 |
self newLayout |
|
133 | 918 |
! |
919 |
||
202 | 920 |
layout |
921 |
"for protocol compatibility: alias for #adjust. |
|
922 |
Please use #adjust, since #layout conflicts with a method |
|
923 |
in VW (which has a completely different meaning). |
|
924 |
In future versions of ST/X, #layout will behave the VW way." |
|
925 |
||
926 |
self obsoleteMethodWarning:'use #adjust'. |
|
927 |
^ self adjust |
|
928 |
! |
|
929 |
||
930 |
layout:something |
|
931 |
"OBSOLETE compatibility interface. Will vanish. |
|
932 |
for protocol compatibility: alias for #adjust:. |
|
933 |
Please use #adjust:, since #layout: conflicts with a method |
|
934 |
in VW (which has a completely different meaning). |
|
935 |
In future versions of ST/X, #layout: will behave the VW way. |
|
936 |
In the meantime, try to figure out what is meant ... a kludge" |
|
937 |
||
938 |
something isLayout ifTrue:[^ super layout:something]. |
|
939 |
||
940 |
self obsoleteMethodWarning:'use #adjust:'. |
|
941 |
self adjust:something |
|
942 |
||
943 |
"Modified: 31.8.1995 / 23:08:13 / claus" |
|
944 |
! |
|
945 |
||
946 |
sizeFixed |
|
947 |
"return the fix-size attribute" |
|
948 |
||
949 |
^ fixSize |
|
950 |
! |
|
951 |
||
952 |
sizeFixed:aBoolean |
|
953 |
"set/clear the fix-size attribute. |
|
954 |
If true, the receiver will not change its size when the labelString/logo |
|
955 |
changes. If false (the default), it will resize itself to make the logo |
|
956 |
fit." |
|
957 |
||
958 |
fixSize := aBoolean |
|
959 |
! |
|
960 |
||
961 |
verticalSpace:aNumber |
|
962 |
"set the number of pixels by which the logo |
|
963 |
is vertically inset from the border" |
|
964 |
||
965 |
vSpace := aNumber. |
|
966 |
self newLayout |
|
967 |
! ! |
|
968 |
||
969 |
!Label methodsFor:'accessing-mvc'! |
|
970 |
||
971 |
addModelInterfaceTo:aDictionary |
|
972 |
"see comment in View>>modelInterface" |
|
973 |
||
974 |
super addModelInterfaceTo:aDictionary. |
|
975 |
aDictionary at:#labelMessage put:labelMsg |
|
976 |
! |
|
977 |
||
978 |
converter:aConverter |
|
979 |
"set the printConverter; |
|
980 |
that one is asked to convert the models value to a printed |
|
981 |
representation (if non-nil). If nil, the model is supposed to |
|
982 |
return a string or bitmap image." |
|
983 |
||
984 |
converter := aConverter |
|
985 |
! |
|
105 | 986 |
|
202 | 987 |
labelMessage |
988 |
"return the symbol used to aquire the labelString/image from the model |
|
989 |
when the aspect changes. |
|
990 |
The default is nil, which means: leave the label unchanged." |
|
991 |
||
992 |
^ labelMsg |
|
993 |
! |
|
994 |
||
995 |
labelMessage:aSymbol |
|
996 |
"set the symbol used to aquire the labelString/image from the model. |
|
997 |
The default is nil, which means: leave the label unchanged." |
|
998 |
||
999 |
labelMsg ~~ aSymbol ifTrue:[ |
|
1000 |
labelMsg := aSymbol. |
|
1001 |
self getLabelFromModel |
|
1002 |
] |
|
1003 |
! |
|
1004 |
||
1005 |
model:aModel |
|
1006 |
super model:aModel. |
|
1007 |
self getLabelFromModel. |
|
1008 |
! ! |
|
1009 |
||
1010 |
!Label methodsFor:'change & update'! |
|
1011 |
||
1012 |
backgroundChannelChanged |
|
1013 |
self backgroundColor:(backgroundChannel value) |
|
1014 |
! |
|
1015 |
||
1016 |
foregroundChannelChanged |
|
1017 |
self foregroundColor:(foregroundChannel value) |
|
1018 |
! |
|
1019 |
||
1020 |
labelChannelChanged |
|
1021 |
self label:(labelChannel value) |
|
1022 |
! |
|
1023 |
||
1024 |
update:something with:aParameter from:changedObject |
|
1025 |
"the MVC way of changing the label ..." |
|
1026 |
||
1027 |
changedObject == model ifTrue:[ |
|
1028 |
something == aspectMsg ifTrue:[ |
|
1029 |
self getLabelFromModel. |
|
1030 |
^ self. |
|
1031 |
] |
|
1032 |
]. |
|
1033 |
^ super update:something with:aParameter from:changedObject |
|
1034 |
! ! |
|
1035 |
||
1036 |
!Label methodsFor:'event handling'! |
|
1037 |
||
1038 |
sizeChanged:how |
|
1039 |
"sent whenever size is changed by someone else - recompute the |
|
1040 |
logos position within the View." |
|
1041 |
||
1042 |
|prevPosition| |
|
1043 |
||
1044 |
super sizeChanged:how. |
|
1045 |
prevPosition := labelOriginX. |
|
1046 |
self computeLabelOrigin |
|
1047 |
shown ifTrue:[ |
|
1048 |
(adjust == #fit |
|
1049 |
or:[labelOriginX ~~ prevPosition |
|
1050 |
or:[how ~~ #smaller]]) ifTrue:[ |
|
1051 |
"/ self clear. |
|
1052 |
self redraw. |
|
1053 |
self redrawEdges |
|
1054 |
] |
|
105 | 1055 |
] |
0 | 1056 |
! ! |
1057 |
||
1058 |
!Label methodsFor:'initialization'! |
|
1059 |
||
1060 |
initStyle |
|
1061 |
super initStyle. |
|
1062 |
||
59 | 1063 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
1064 |
DefaultBackgroundColor notNil ifTrue:[ |
|
1065 |
bgColor := DefaultBackgroundColor on:device |
|
38 | 1066 |
] ifFalse:[ |
59 | 1067 |
bgColor := viewBackground on:device. |
1068 |
]. |
|
1069 |
DefaultForegroundColor notNil ifTrue:[ |
|
1070 |
fgColor := DefaultForegroundColor on:device |
|
1071 |
] ifFalse:[ |
|
1072 |
fgColor := Black on:device. |
|
38 | 1073 |
] |
0 | 1074 |
! |
1075 |
||
105 | 1076 |
initialize |
1077 |
super initialize. |
|
1078 |
||
1079 |
font := font on:device. |
|
1080 |
self height:(font height + font descent). |
|
1081 |
adjust := #center. |
|
118 | 1082 |
labelOriginX := labelOriginY := 0. |
1083 |
labelWidth := labelHeight := 0. |
|
105 | 1084 |
logo := nil. |
1085 |
fixSize := false. |
|
1086 |
hSpace := (self horizontalPixelPerMillimeter:0.5) rounded. |
|
131 | 1087 |
vSpace := (self verticalPixelPerMillimeter:0.25) rounded |
105 | 1088 |
! |
1089 |
||
0 | 1090 |
recreate |
1091 |
"after snapin, labels dimensions may have changed due to |
|
1092 |
different font parameters" |
|
1093 |
||
1094 |
super recreate. |
|
3 | 1095 |
font := font on:device. |
0 | 1096 |
self computeLabelSize. |
1097 |
self computeLabelOrigin |
|
1098 |
! ! |
|
1099 |
||
202 | 1100 |
!Label methodsFor:'private'! |
1101 |
||
1102 |
computeLabelOrigin |
|
1103 |
"(re)compute the origin of the label whenever label or font changes" |
|
1104 |
||
1105 |
|x y| |
|
1106 |
||
1107 |
labelHeight isNil ifTrue:[^ self]. |
|
1108 |
||
1109 |
adjust == #fit ifTrue:[ |
|
1110 |
labelOriginX := labelOriginY := margin. |
|
1111 |
^ self |
|
1112 |
]. |
|
1113 |
||
1114 |
"if it does not fit, should we make the origin visible, |
|
1115 |
or the center (for text, the center seems better. For images, |
|
1116 |
I dont really know ehich is better ... |
|
1117 |
The commented code below makes the origin visible |
|
1118 |
" |
|
1119 |
"/ (labelHeight < height) ifTrue:[ |
|
1120 |
"/ y := (height - labelHeight) // 2 |
|
1121 |
"/ ] ifFalse:[ |
|
1122 |
"/ y := 0 |
|
1123 |
"/ ]. |
|
1124 |
||
1125 |
"always center vertically" |
|
1126 |
y := (height - labelHeight) // 2. |
|
1127 |
||
1128 |
labelOriginY := y. |
|
1129 |
||
1130 |
(((adjust == #center) |
|
1131 |
or:[adjust == #centerRight]) |
|
1132 |
or:[adjust == #centerLeft]) ifTrue:[ |
|
1133 |
" center text/form in button " |
|
1134 |
x := (width - labelWidth) // 2. |
|
1135 |
(width < labelWidth) ifTrue:[ |
|
1136 |
"no fit" |
|
1137 |
(adjust == #centerLeft) ifTrue:[ |
|
1138 |
x := margin |
|
1139 |
] ifFalse:[ |
|
1140 |
(adjust == #centerRight) ifTrue:[ |
|
1141 |
x := width - labelWidth - margin |
|
1142 |
] |
|
1143 |
] |
|
1144 |
] |
|
1145 |
] ifFalse:[ |
|
1146 |
(adjust == #left) ifTrue:[ |
|
1147 |
x := margin |
|
1148 |
] ifFalse:[ |
|
1149 |
x := width - labelWidth - margin |
|
1150 |
] |
|
1151 |
]. |
|
1152 |
labelOriginX := x |
|
1153 |
! |
|
1154 |
||
1155 |
computeLabelSize |
|
1156 |
"compute the extent needed to hold the label; aForm or aString" |
|
1157 |
||
1158 |
|numberOfLines textHeight textWidth| |
|
1159 |
||
1160 |
logo isNil ifTrue:[^ self]. |
|
1161 |
||
1162 |
logo isImageOrForm ifTrue:[ |
|
1163 |
labelWidth := logo width. |
|
1164 |
labelHeight := logo height. |
|
1165 |
^ self |
|
1166 |
]. |
|
1167 |
||
1168 |
"must be a String or collection of strings" |
|
1169 |
logo isString ifTrue:[ |
|
1170 |
numberOfLines := 1 + (logo occurrencesOf:(Character cr)). |
|
1171 |
(numberOfLines ~~ 1) ifTrue:[ |
|
1172 |
logo := logo asStringCollection |
|
1173 |
] |
|
1174 |
] ifFalse:[ |
|
1175 |
numberOfLines := logo size. |
|
1176 |
(numberOfLines <= 1) ifTrue:[ |
|
1177 |
logo := logo asString |
|
1178 |
] |
|
1179 |
]. |
|
1180 |
||
1181 |
"/ textHeight := font height * numberOfLines + font descent. |
|
1182 |
textHeight := font height * numberOfLines. |
|
1183 |
textWidth := font widthOf:logo. |
|
1184 |
labelWidth := textWidth + (hSpace * 2) . |
|
1185 |
labelHeight := textHeight + (vSpace * 2) |
|
1186 |
! |
|
1187 |
||
1188 |
getLabelFromModel |
|
1189 |
"ask my model for the label to show. |
|
1190 |
Here, we use labelMsg (instead of aspectMsg). |
|
1191 |
This allows multiple labels to react on the same aspect, |
|
1192 |
but show different labels when changed |
|
1193 |
(also, since labelMsg defaults to nil, constant labels |
|
1194 |
which have a nil labelMsg will not try to aquire a labelString)." |
|
1195 |
||
1196 |
|val| |
|
1197 |
||
1198 |
(model notNil |
|
1199 |
and:[labelMsg notNil]) ifTrue:[ |
|
1200 |
val := model perform:labelMsg. |
|
1201 |
converter notNil ifTrue:[ |
|
1202 |
val := converter printStringFor:val |
|
1203 |
]. |
|
1204 |
self label:val. |
|
1205 |
]. |
|
1206 |
! |
|
1207 |
||
1208 |
newLayout |
|
1209 |
"recompute position/size after a change |
|
1210 |
- helper for form:/font: etc." |
|
1211 |
||
1212 |
self computeLabelSize. |
|
1213 |
fixSize ifFalse:[ |
|
1214 |
self resize |
|
1215 |
] ifTrue:[ |
|
1216 |
self computeLabelOrigin |
|
1217 |
]. |
|
1218 |
shown ifTrue:[ |
|
1219 |
self redraw |
|
1220 |
] |
|
1221 |
! ! |
|
1222 |
||
1223 |
!Label methodsFor:'queries'! |
|
1224 |
||
1225 |
preferredExtent |
|
1226 |
"return my preferred extent - this is the minimum size I would like to have" |
|
1227 |
||
1228 |
|extra| |
|
1229 |
||
1230 |
logo notNil ifTrue:[ |
|
1231 |
extra := margin * 2. |
|
1232 |
^ (labelWidth + extra + hSpace) @ (labelHeight + extra + vSpace) |
|
1233 |
]. |
|
1234 |
||
1235 |
^ super preferredExtent |
|
1236 |
! ! |
|
1237 |
||
0 | 1238 |
!Label methodsFor:'redrawing'! |
1239 |
||
77 | 1240 |
clearInsideWith:bg |
1241 |
|cutOff mustClear| |
|
0 | 1242 |
|
1243 |
cutOff := margin * 2. |
|
1244 |
||
3 | 1245 |
mustClear := true. |
1246 |
||
87 | 1247 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[ |
59 | 1248 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[ |
1249 |
logo width >= (width - cutOff) ifTrue:[ |
|
1250 |
logo height >= (height - cutOff) ifTrue:[ |
|
1251 |
"no need to clear before - avoid flicker" |
|
1252 |
mustClear := false |
|
1253 |
] |
|
1254 |
] |
|
1255 |
]. |
|
3 | 1256 |
]. |
1257 |
||
1258 |
mustClear ifTrue:[ |
|
59 | 1259 |
self paint:bg. |
1260 |
self fillRectangleX:margin y:margin |
|
1261 |
width:(width - cutOff) |
|
1262 |
height:(height - cutOff). |
|
3 | 1263 |
]. |
77 | 1264 |
! |
1265 |
||
1266 |
drawWith:fg and:bg |
|
1267 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1268 |
(especially Button) to redraw the logo in different colors." |
|
1269 |
||
132 | 1270 |
|x y scaleH scaleV nW nH hSep vSep m2| |
77 | 1271 |
|
1272 |
self clearInsideWith:bg. |
|
0 | 1273 |
|
1274 |
logo notNil ifTrue:[ |
|
59 | 1275 |
self paint:fg on:bg. |
131 | 1276 |
|
133 | 1277 |
m2 := margin * 2. |
1278 |
hSep := (hSpace*2). |
|
1279 |
vSep := (vSpace*2). |
|
1280 |
||
87 | 1281 |
logo isImageOrForm ifTrue:[ |
131 | 1282 |
x := labelOriginX. |
1283 |
y := labelOriginY. |
|
1284 |
||
1285 |
adjust == #fit ifTrue:[ |
|
1286 |
scaleH := ((width - hSep) / (logo width)) asFloat. |
|
1287 |
scaleV := ((height - vSep) / (logo height)) asFloat. |
|
1288 |
self scale:(scaleH @ scaleV). |
|
1289 |
x := transformation applyInverseScaleX:x. |
|
1290 |
y := transformation applyInverseScaleY:y. |
|
1291 |
]. |
|
1292 |
||
87 | 1293 |
logo := logo on:device. |
59 | 1294 |
"/ self background:bg. |
131 | 1295 |
self displayOpaqueForm:logo x:x y:y |
59 | 1296 |
] ifFalse:[ |
1297 |
x := labelOriginX + hSpace. |
|
1298 |
y := labelOriginY + (font ascent) + vSpace. |
|
0 | 1299 |
|
131 | 1300 |
adjust == #fit ifTrue:[ |
1301 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat. |
|
1302 |
scaleV := ((height - m2 - vSep) / (labelHeight - vSpace)) asFloat. |
|
1303 |
self scale:(scaleH min: scaleV). |
|
1304 |
x := transformation applyInverseScaleX:x. |
|
1305 |
y := y - font ascent + (transformation applyScaleY:font ascent). |
|
1306 |
y := transformation applyInverseScaleY:y. |
|
1307 |
scaleH < scaleV ifTrue:[ |
|
1308 |
nH := labelHeight * scaleH. |
|
1309 |
"/ now, center vertically |
|
1310 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2). |
|
1311 |
]. |
|
1312 |
scaleV < scaleH ifTrue:[ |
|
1313 |
"/ now, center horizontally |
|
1314 |
nW := labelWidth * scaleV. |
|
1315 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2) |
|
1316 |
]. |
|
1317 |
]. |
|
1318 |
||
87 | 1319 |
logo isString ifTrue:[ |
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
1320 |
self displayOpaqueString:logo x:x y:y |
59 | 1321 |
] ifFalse:[ |
1322 |
logo do:[ :line | |
|
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
1323 |
self displayOpaqueString:(line printString) x:x y:y. |
59 | 1324 |
y := y + (font height) |
1325 |
] |
|
131 | 1326 |
]. |
1327 |
||
1328 |
]. |
|
1329 |
||
1330 |
adjust == #fit ifTrue:[ |
|
1331 |
self scale:1 |
|
1332 |
]. |
|
1333 |
||
0 | 1334 |
] |
1335 |
! |
|
1336 |
||
1337 |
redraw |
|
1338 |
"redraw my label" |
|
1339 |
||
1340 |
shown ifTrue:[ |
|
59 | 1341 |
self drawWith:fgColor and:bgColor |
0 | 1342 |
] |
1343 |
! ! |
|
105 | 1344 |
|
110 | 1345 |
!Label methodsFor:'resizing'! |
1346 |
||
1347 |
forceResize |
|
118 | 1348 |
"resize myself to make text fit into myself. Here, this is done even if |
1349 |
fixSize is set." |
|
110 | 1350 |
|
1351 |
logo notNil ifTrue:[ |
|
130 | 1352 |
self extent:self preferredExtent. |
110 | 1353 |
self computeLabelOrigin |
1354 |
] |
|
105 | 1355 |
! |
1356 |
||
1357 |
resize |
|
1358 |
"resize myself to make text fit into myself. |
|
118 | 1359 |
but only do so, if I am not fixedSize and I have NOT been |
1360 |
given a relative extent or an extend computation block." |
|
105 | 1361 |
|
110 | 1362 |
(logo notNil |
1363 |
and:[fixSize not |
|
1364 |
and:[relativeExtent isNil |
|
1365 |
and:[extentRule isNil |
|
1366 |
and:[relativeCorner isNil |
|
1367 |
and:[cornerRule isNil]]]]]) ifTrue:[ |
|
1368 |
self forceResize |
|
1369 |
] ifFalse:[ |
|
105 | 1370 |
self computeLabelOrigin |
1371 |
] |
|
1372 |
! ! |
|
1373 |
||
205 | 1374 |
!Label class methodsFor:'documentation'! |
1375 |
||
1376 |
version |
|
263 | 1377 |
^ '$Header: /cvs/stx/stx/libwidg/Label.st,v 1.41 1995-12-17 14:48:40 cg Exp $' |
205 | 1378 |
! ! |