author | Claus Gittinger <cg@exept.de> |
Thu, 14 Dec 1995 14:56:43 +0100 | |
changeset 254 | aa15cac0670f |
parent 250 | 77012e65ac84 |
child 258 | ae4b8f1a6738 |
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 |
|
202 | 725 |
backgroundChannel:aValueHolder |
726 |
|prev| |
|
105 | 727 |
|
202 | 728 |
prev := backgroundChannel. |
729 |
backgroundChannel := aValueHolder. |
|
730 |
self setupChannel:aValueHolder for:#backgroundChannelChanged withOld:prev |
|
731 |
! |
|
145 | 732 |
|
733 |
foregroundChannel:aValueHolder |
|
146 | 734 |
|prev| |
735 |
||
736 |
prev := foregroundChannel. |
|
145 | 737 |
foregroundChannel := aValueHolder. |
146 | 738 |
self setupChannel:aValueHolder for:#foregroundChannelChanged withOld:prev |
145 | 739 |
! |
740 |
||
741 |
labelChannel:aValueHolder |
|
146 | 742 |
|prev| |
743 |
||
744 |
prev := labelChannel. |
|
145 | 745 |
labelChannel := aValueHolder. |
146 | 746 |
self setupChannel:aValueHolder for:#labelChannelChanged withOld:prev |
145 | 747 |
! ! |
748 |
||
202 | 749 |
!Label methodsFor:'accessing-colors'! |
125 | 750 |
|
202 | 751 |
backgroundColor |
752 |
"return the background color" |
|
125 | 753 |
|
202 | 754 |
^ bgColor |
125 | 755 |
! |
756 |
||
202 | 757 |
backgroundColor:aColor |
758 |
"set the background color" |
|
125 | 759 |
|
202 | 760 |
bgColor := aColor on:device. |
131 | 761 |
shown ifTrue:[self redraw] |
105 | 762 |
! |
763 |
||
764 |
foregroundColor |
|
765 |
"return the foreground color" |
|
766 |
||
767 |
^ fgColor |
|
768 |
! |
|
769 |
||
202 | 770 |
foregroundColor:aColor |
771 |
"set the foreground color" |
|
105 | 772 |
|
202 | 773 |
fgColor := aColor on:device. |
131 | 774 |
shown ifTrue:[self redraw] |
105 | 775 |
! |
776 |
||
777 |
foregroundColor:fg backgroundColor:bg |
|
778 |
"set the colors to be used for drawing" |
|
779 |
||
780 |
fgColor := fg on:device. |
|
781 |
bgColor := bg on:device. |
|
131 | 782 |
shown ifTrue:[self redraw] |
133 | 783 |
! ! |
784 |
||
785 |
!Label methodsFor:'accessing-contents'! |
|
0 | 786 |
|
202 | 787 |
form:aForm |
788 |
"set the labels form; adjust extent if not already realized. |
|
789 |
OBSOLETE: you should now use #label: for both strings and images" |
|
118 | 790 |
|
202 | 791 |
self label:aForm |
792 |
! |
|
793 |
||
794 |
label |
|
795 |
"return the labels string or image" |
|
796 |
||
797 |
^ logo |
|
118 | 798 |
! |
105 | 799 |
|
118 | 800 |
label:aStringOrFormOrImage |
801 |
"set the labelString or image; adjust extent if not already realized and |
|
802 |
not fixedSize" |
|
803 |
||
804 |
(aStringOrFormOrImage ~~ logo) ifTrue:[ |
|
805 |
"/ |
|
806 |
"/ avoid recompute of size, if its an image with |
|
807 |
"/ the same size |
|
808 |
"/ |
|
809 |
aStringOrFormOrImage isImageOrForm ifTrue:[ |
|
810 |
logo notNil ifTrue:[ |
|
811 |
logo isImageOrForm ifTrue:[ |
|
812 |
logo extent = aStringOrFormOrImage extent ifTrue:[ |
|
813 |
logo := aStringOrFormOrImage. |
|
814 |
^ self |
|
815 |
] |
|
105 | 816 |
] |
817 |
] |
|
118 | 818 |
] ifFalse:[ |
819 |
(logo = aStringOrFormOrImage) ifTrue:[ |
|
820 |
^ self |
|
821 |
] |
|
105 | 822 |
]. |
118 | 823 |
logo := aStringOrFormOrImage. |
105 | 824 |
self newLayout |
825 |
] |
|
826 |
! |
|
0 | 827 |
|
202 | 828 |
labelString:aString |
829 |
"for ST-80 compatibility: same as #label: |
|
830 |
set the label-string; adjust extent if not already realized and not fixedSize" |
|
118 | 831 |
|
202 | 832 |
self label:aString |
833 |
! |
|
834 |
||
835 |
labelWidth |
|
836 |
"return the logos width in pixels" |
|
837 |
||
838 |
^ labelWidth |
|
118 | 839 |
! |
840 |
||
841 |
logo:something |
|
842 |
"set the labels form or string. |
|
843 |
OBSOLETE: the old version used #form: for images and #label: for strings. |
|
844 |
you should now use #label: for any." |
|
845 |
||
846 |
self label:something |
|
133 | 847 |
! ! |
848 |
||
849 |
!Label methodsFor:'accessing-layout'! |
|
850 |
||
202 | 851 |
adjust |
852 |
"return the adjust symbol" |
|
0 | 853 |
|
202 | 854 |
^ adjust |
125 | 855 |
! |
856 |
||
105 | 857 |
adjust:how |
858 |
"set the adjust, how which must be one of |
|
0 | 859 |
|
105 | 860 |
#left -> left adjust logo |
861 |
#right -> right adjust logo |
|
862 |
#center -> center logo |
|
118 | 863 |
#centerRight -> center logo; if no fit, right adjust |
864 |
(use with filenames, where the interresting part is |
|
865 |
at the right if the label is too small) |
|
105 | 866 |
#centerLeft -> center logo; if it does not fit, left adjust it |
118 | 867 |
(use with strings where the interresting part is at the |
868 |
left if the label is too small) |
|
105 | 869 |
" |
118 | 870 |
|
105 | 871 |
(adjust ~~ how) ifTrue:[ |
872 |
adjust := how. |
|
873 |
self newLayout |
|
874 |
] |
|
875 |
! |
|
876 |
||
202 | 877 |
font:aFont |
878 |
"set the font - if I'm not realized and not fixedSize, adjust my size" |
|
125 | 879 |
|
202 | 880 |
(aFont ~~ font) ifTrue:[ |
881 |
super font:(aFont on:device). |
|
882 |
self newLayout |
|
883 |
] |
|
133 | 884 |
! |
885 |
||
886 |
horizontalSpace:aNumber |
|
887 |
"set the number of pixels by which the logo |
|
888 |
is horizontally inset from the border" |
|
889 |
||
162 | 890 |
hSpace := aNumber. |
891 |
self newLayout |
|
133 | 892 |
! |
893 |
||
202 | 894 |
layout |
895 |
"for protocol compatibility: alias for #adjust. |
|
896 |
Please use #adjust, since #layout conflicts with a method |
|
897 |
in VW (which has a completely different meaning). |
|
898 |
In future versions of ST/X, #layout will behave the VW way." |
|
899 |
||
900 |
self obsoleteMethodWarning:'use #adjust'. |
|
901 |
^ self adjust |
|
902 |
! |
|
903 |
||
904 |
layout:something |
|
905 |
"OBSOLETE compatibility interface. Will vanish. |
|
906 |
for protocol compatibility: alias for #adjust:. |
|
907 |
Please use #adjust:, since #layout: conflicts with a method |
|
908 |
in VW (which has a completely different meaning). |
|
909 |
In future versions of ST/X, #layout: will behave the VW way. |
|
910 |
In the meantime, try to figure out what is meant ... a kludge" |
|
911 |
||
912 |
something isLayout ifTrue:[^ super layout:something]. |
|
913 |
||
914 |
self obsoleteMethodWarning:'use #adjust:'. |
|
915 |
self adjust:something |
|
916 |
||
917 |
"Modified: 31.8.1995 / 23:08:13 / claus" |
|
918 |
! |
|
919 |
||
920 |
sizeFixed |
|
921 |
"return the fix-size attribute" |
|
922 |
||
923 |
^ fixSize |
|
924 |
! |
|
925 |
||
926 |
sizeFixed:aBoolean |
|
927 |
"set/clear the fix-size attribute. |
|
928 |
If true, the receiver will not change its size when the labelString/logo |
|
929 |
changes. If false (the default), it will resize itself to make the logo |
|
930 |
fit." |
|
931 |
||
932 |
fixSize := aBoolean |
|
933 |
! |
|
934 |
||
935 |
verticalSpace:aNumber |
|
936 |
"set the number of pixels by which the logo |
|
937 |
is vertically inset from the border" |
|
938 |
||
939 |
vSpace := aNumber. |
|
940 |
self newLayout |
|
941 |
! ! |
|
942 |
||
943 |
!Label methodsFor:'accessing-mvc'! |
|
944 |
||
945 |
addModelInterfaceTo:aDictionary |
|
946 |
"see comment in View>>modelInterface" |
|
947 |
||
948 |
super addModelInterfaceTo:aDictionary. |
|
949 |
aDictionary at:#labelMessage put:labelMsg |
|
950 |
! |
|
951 |
||
952 |
converter:aConverter |
|
953 |
"set the printConverter; |
|
954 |
that one is asked to convert the models value to a printed |
|
955 |
representation (if non-nil). If nil, the model is supposed to |
|
956 |
return a string or bitmap image." |
|
957 |
||
958 |
converter := aConverter |
|
959 |
! |
|
105 | 960 |
|
202 | 961 |
labelMessage |
962 |
"return the symbol used to aquire the labelString/image from the model |
|
963 |
when the aspect changes. |
|
964 |
The default is nil, which means: leave the label unchanged." |
|
965 |
||
966 |
^ labelMsg |
|
967 |
! |
|
968 |
||
969 |
labelMessage:aSymbol |
|
970 |
"set the symbol used to aquire the labelString/image from the model. |
|
971 |
The default is nil, which means: leave the label unchanged." |
|
972 |
||
973 |
labelMsg ~~ aSymbol ifTrue:[ |
|
974 |
labelMsg := aSymbol. |
|
975 |
self getLabelFromModel |
|
976 |
] |
|
977 |
! |
|
978 |
||
979 |
model:aModel |
|
980 |
super model:aModel. |
|
981 |
self getLabelFromModel. |
|
982 |
! ! |
|
983 |
||
984 |
!Label methodsFor:'change & update'! |
|
985 |
||
986 |
backgroundChannelChanged |
|
987 |
self backgroundColor:(backgroundChannel value) |
|
988 |
! |
|
989 |
||
990 |
foregroundChannelChanged |
|
991 |
self foregroundColor:(foregroundChannel value) |
|
992 |
! |
|
993 |
||
994 |
labelChannelChanged |
|
995 |
self label:(labelChannel value) |
|
996 |
! |
|
997 |
||
998 |
update:something with:aParameter from:changedObject |
|
999 |
"the MVC way of changing the label ..." |
|
1000 |
||
1001 |
changedObject == model ifTrue:[ |
|
1002 |
something == aspectMsg ifTrue:[ |
|
1003 |
self getLabelFromModel. |
|
1004 |
^ self. |
|
1005 |
] |
|
1006 |
]. |
|
1007 |
^ super update:something with:aParameter from:changedObject |
|
1008 |
! ! |
|
1009 |
||
1010 |
!Label methodsFor:'event handling'! |
|
1011 |
||
1012 |
sizeChanged:how |
|
1013 |
"sent whenever size is changed by someone else - recompute the |
|
1014 |
logos position within the View." |
|
1015 |
||
1016 |
|prevPosition| |
|
1017 |
||
1018 |
super sizeChanged:how. |
|
1019 |
prevPosition := labelOriginX. |
|
1020 |
self computeLabelOrigin |
|
1021 |
shown ifTrue:[ |
|
1022 |
(adjust == #fit |
|
1023 |
or:[labelOriginX ~~ prevPosition |
|
1024 |
or:[how ~~ #smaller]]) ifTrue:[ |
|
1025 |
"/ self clear. |
|
1026 |
self redraw. |
|
1027 |
self redrawEdges |
|
1028 |
] |
|
105 | 1029 |
] |
0 | 1030 |
! ! |
1031 |
||
1032 |
!Label methodsFor:'initialization'! |
|
1033 |
||
1034 |
initStyle |
|
1035 |
super initStyle. |
|
1036 |
||
59 | 1037 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
1038 |
DefaultBackgroundColor notNil ifTrue:[ |
|
1039 |
bgColor := DefaultBackgroundColor on:device |
|
38 | 1040 |
] ifFalse:[ |
59 | 1041 |
bgColor := viewBackground on:device. |
1042 |
]. |
|
1043 |
DefaultForegroundColor notNil ifTrue:[ |
|
1044 |
fgColor := DefaultForegroundColor on:device |
|
1045 |
] ifFalse:[ |
|
1046 |
fgColor := Black on:device. |
|
38 | 1047 |
] |
0 | 1048 |
! |
1049 |
||
105 | 1050 |
initialize |
1051 |
super initialize. |
|
1052 |
||
1053 |
font := font on:device. |
|
1054 |
self height:(font height + font descent). |
|
1055 |
adjust := #center. |
|
118 | 1056 |
labelOriginX := labelOriginY := 0. |
1057 |
labelWidth := labelHeight := 0. |
|
105 | 1058 |
logo := nil. |
1059 |
fixSize := false. |
|
1060 |
hSpace := (self horizontalPixelPerMillimeter:0.5) rounded. |
|
131 | 1061 |
vSpace := (self verticalPixelPerMillimeter:0.25) rounded |
105 | 1062 |
! |
1063 |
||
0 | 1064 |
recreate |
1065 |
"after snapin, labels dimensions may have changed due to |
|
1066 |
different font parameters" |
|
1067 |
||
1068 |
super recreate. |
|
3 | 1069 |
font := font on:device. |
0 | 1070 |
self computeLabelSize. |
1071 |
self computeLabelOrigin |
|
1072 |
! ! |
|
1073 |
||
202 | 1074 |
!Label methodsFor:'private'! |
1075 |
||
1076 |
computeLabelOrigin |
|
1077 |
"(re)compute the origin of the label whenever label or font changes" |
|
1078 |
||
1079 |
|x y| |
|
1080 |
||
1081 |
labelHeight isNil ifTrue:[^ self]. |
|
1082 |
||
1083 |
adjust == #fit ifTrue:[ |
|
1084 |
labelOriginX := labelOriginY := margin. |
|
1085 |
^ self |
|
1086 |
]. |
|
1087 |
||
1088 |
"if it does not fit, should we make the origin visible, |
|
1089 |
or the center (for text, the center seems better. For images, |
|
1090 |
I dont really know ehich is better ... |
|
1091 |
The commented code below makes the origin visible |
|
1092 |
" |
|
1093 |
"/ (labelHeight < height) ifTrue:[ |
|
1094 |
"/ y := (height - labelHeight) // 2 |
|
1095 |
"/ ] ifFalse:[ |
|
1096 |
"/ y := 0 |
|
1097 |
"/ ]. |
|
1098 |
||
1099 |
"always center vertically" |
|
1100 |
y := (height - labelHeight) // 2. |
|
1101 |
||
1102 |
labelOriginY := y. |
|
1103 |
||
1104 |
(((adjust == #center) |
|
1105 |
or:[adjust == #centerRight]) |
|
1106 |
or:[adjust == #centerLeft]) ifTrue:[ |
|
1107 |
" center text/form in button " |
|
1108 |
x := (width - labelWidth) // 2. |
|
1109 |
(width < labelWidth) ifTrue:[ |
|
1110 |
"no fit" |
|
1111 |
(adjust == #centerLeft) ifTrue:[ |
|
1112 |
x := margin |
|
1113 |
] ifFalse:[ |
|
1114 |
(adjust == #centerRight) ifTrue:[ |
|
1115 |
x := width - labelWidth - margin |
|
1116 |
] |
|
1117 |
] |
|
1118 |
] |
|
1119 |
] ifFalse:[ |
|
1120 |
(adjust == #left) ifTrue:[ |
|
1121 |
x := margin |
|
1122 |
] ifFalse:[ |
|
1123 |
x := width - labelWidth - margin |
|
1124 |
] |
|
1125 |
]. |
|
1126 |
labelOriginX := x |
|
1127 |
! |
|
1128 |
||
1129 |
computeLabelSize |
|
1130 |
"compute the extent needed to hold the label; aForm or aString" |
|
1131 |
||
1132 |
|numberOfLines textHeight textWidth| |
|
1133 |
||
1134 |
logo isNil ifTrue:[^ self]. |
|
1135 |
||
1136 |
logo isImageOrForm ifTrue:[ |
|
1137 |
labelWidth := logo width. |
|
1138 |
labelHeight := logo height. |
|
1139 |
^ self |
|
1140 |
]. |
|
1141 |
||
1142 |
"must be a String or collection of strings" |
|
1143 |
logo isString ifTrue:[ |
|
1144 |
numberOfLines := 1 + (logo occurrencesOf:(Character cr)). |
|
1145 |
(numberOfLines ~~ 1) ifTrue:[ |
|
1146 |
logo := logo asStringCollection |
|
1147 |
] |
|
1148 |
] ifFalse:[ |
|
1149 |
numberOfLines := logo size. |
|
1150 |
(numberOfLines <= 1) ifTrue:[ |
|
1151 |
logo := logo asString |
|
1152 |
] |
|
1153 |
]. |
|
1154 |
||
1155 |
"/ textHeight := font height * numberOfLines + font descent. |
|
1156 |
textHeight := font height * numberOfLines. |
|
1157 |
textWidth := font widthOf:logo. |
|
1158 |
labelWidth := textWidth + (hSpace * 2) . |
|
1159 |
labelHeight := textHeight + (vSpace * 2) |
|
1160 |
! |
|
1161 |
||
1162 |
getLabelFromModel |
|
1163 |
"ask my model for the label to show. |
|
1164 |
Here, we use labelMsg (instead of aspectMsg). |
|
1165 |
This allows multiple labels to react on the same aspect, |
|
1166 |
but show different labels when changed |
|
1167 |
(also, since labelMsg defaults to nil, constant labels |
|
1168 |
which have a nil labelMsg will not try to aquire a labelString)." |
|
1169 |
||
1170 |
|val| |
|
1171 |
||
1172 |
(model notNil |
|
1173 |
and:[labelMsg notNil]) ifTrue:[ |
|
1174 |
val := model perform:labelMsg. |
|
1175 |
converter notNil ifTrue:[ |
|
1176 |
val := converter printStringFor:val |
|
1177 |
]. |
|
1178 |
self label:val. |
|
1179 |
]. |
|
1180 |
! |
|
1181 |
||
1182 |
newLayout |
|
1183 |
"recompute position/size after a change |
|
1184 |
- helper for form:/font: etc." |
|
1185 |
||
1186 |
self computeLabelSize. |
|
1187 |
fixSize ifFalse:[ |
|
1188 |
self resize |
|
1189 |
] ifTrue:[ |
|
1190 |
self computeLabelOrigin |
|
1191 |
]. |
|
1192 |
shown ifTrue:[ |
|
1193 |
self redraw |
|
1194 |
] |
|
1195 |
! ! |
|
1196 |
||
1197 |
!Label methodsFor:'queries'! |
|
1198 |
||
1199 |
preferredExtent |
|
1200 |
"return my preferred extent - this is the minimum size I would like to have" |
|
1201 |
||
1202 |
|extra| |
|
1203 |
||
1204 |
logo notNil ifTrue:[ |
|
1205 |
extra := margin * 2. |
|
1206 |
^ (labelWidth + extra + hSpace) @ (labelHeight + extra + vSpace) |
|
1207 |
]. |
|
1208 |
||
1209 |
^ super preferredExtent |
|
1210 |
! ! |
|
1211 |
||
0 | 1212 |
!Label methodsFor:'redrawing'! |
1213 |
||
77 | 1214 |
clearInsideWith:bg |
1215 |
|cutOff mustClear| |
|
0 | 1216 |
|
1217 |
cutOff := margin * 2. |
|
1218 |
||
3 | 1219 |
mustClear := true. |
1220 |
||
87 | 1221 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[ |
59 | 1222 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[ |
1223 |
logo width >= (width - cutOff) ifTrue:[ |
|
1224 |
logo height >= (height - cutOff) ifTrue:[ |
|
1225 |
"no need to clear before - avoid flicker" |
|
1226 |
mustClear := false |
|
1227 |
] |
|
1228 |
] |
|
1229 |
]. |
|
3 | 1230 |
]. |
1231 |
||
1232 |
mustClear ifTrue:[ |
|
59 | 1233 |
self paint:bg. |
1234 |
self fillRectangleX:margin y:margin |
|
1235 |
width:(width - cutOff) |
|
1236 |
height:(height - cutOff). |
|
3 | 1237 |
]. |
77 | 1238 |
! |
1239 |
||
1240 |
drawWith:fg and:bg |
|
1241 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1242 |
(especially Button) to redraw the logo in different colors." |
|
1243 |
||
132 | 1244 |
|x y scaleH scaleV nW nH hSep vSep m2| |
77 | 1245 |
|
1246 |
self clearInsideWith:bg. |
|
0 | 1247 |
|
1248 |
logo notNil ifTrue:[ |
|
59 | 1249 |
self paint:fg on:bg. |
131 | 1250 |
|
133 | 1251 |
m2 := margin * 2. |
1252 |
hSep := (hSpace*2). |
|
1253 |
vSep := (vSpace*2). |
|
1254 |
||
87 | 1255 |
logo isImageOrForm ifTrue:[ |
131 | 1256 |
x := labelOriginX. |
1257 |
y := labelOriginY. |
|
1258 |
||
1259 |
adjust == #fit ifTrue:[ |
|
1260 |
scaleH := ((width - hSep) / (logo width)) asFloat. |
|
1261 |
scaleV := ((height - vSep) / (logo height)) asFloat. |
|
1262 |
self scale:(scaleH @ scaleV). |
|
1263 |
x := transformation applyInverseScaleX:x. |
|
1264 |
y := transformation applyInverseScaleY:y. |
|
1265 |
]. |
|
1266 |
||
87 | 1267 |
logo := logo on:device. |
59 | 1268 |
"/ self background:bg. |
131 | 1269 |
self displayOpaqueForm:logo x:x y:y |
59 | 1270 |
] ifFalse:[ |
1271 |
x := labelOriginX + hSpace. |
|
1272 |
y := labelOriginY + (font ascent) + vSpace. |
|
0 | 1273 |
|
131 | 1274 |
adjust == #fit ifTrue:[ |
1275 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat. |
|
1276 |
scaleV := ((height - m2 - vSep) / (labelHeight - vSpace)) asFloat. |
|
1277 |
self scale:(scaleH min: scaleV). |
|
1278 |
x := transformation applyInverseScaleX:x. |
|
1279 |
y := y - font ascent + (transformation applyScaleY:font ascent). |
|
1280 |
y := transformation applyInverseScaleY:y. |
|
1281 |
scaleH < scaleV ifTrue:[ |
|
1282 |
nH := labelHeight * scaleH. |
|
1283 |
"/ now, center vertically |
|
1284 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2). |
|
1285 |
]. |
|
1286 |
scaleV < scaleH ifTrue:[ |
|
1287 |
"/ now, center horizontally |
|
1288 |
nW := labelWidth * scaleV. |
|
1289 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2) |
|
1290 |
]. |
|
1291 |
]. |
|
1292 |
||
87 | 1293 |
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
|
1294 |
self displayOpaqueString:logo x:x y:y |
59 | 1295 |
] ifFalse:[ |
1296 |
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
|
1297 |
self displayOpaqueString:(line printString) x:x y:y. |
59 | 1298 |
y := y + (font height) |
1299 |
] |
|
131 | 1300 |
]. |
1301 |
||
1302 |
]. |
|
1303 |
||
1304 |
adjust == #fit ifTrue:[ |
|
1305 |
self scale:1 |
|
1306 |
]. |
|
1307 |
||
0 | 1308 |
] |
1309 |
! |
|
1310 |
||
1311 |
redraw |
|
1312 |
"redraw my label" |
|
1313 |
||
1314 |
shown ifTrue:[ |
|
59 | 1315 |
self drawWith:fgColor and:bgColor |
0 | 1316 |
] |
1317 |
! ! |
|
105 | 1318 |
|
110 | 1319 |
!Label methodsFor:'resizing'! |
1320 |
||
1321 |
forceResize |
|
118 | 1322 |
"resize myself to make text fit into myself. Here, this is done even if |
1323 |
fixSize is set." |
|
110 | 1324 |
|
1325 |
logo notNil ifTrue:[ |
|
130 | 1326 |
self extent:self preferredExtent. |
110 | 1327 |
self computeLabelOrigin |
1328 |
] |
|
105 | 1329 |
! |
1330 |
||
1331 |
resize |
|
1332 |
"resize myself to make text fit into myself. |
|
118 | 1333 |
but only do so, if I am not fixedSize and I have NOT been |
1334 |
given a relative extent or an extend computation block." |
|
105 | 1335 |
|
110 | 1336 |
(logo notNil |
1337 |
and:[fixSize not |
|
1338 |
and:[relativeExtent isNil |
|
1339 |
and:[extentRule isNil |
|
1340 |
and:[relativeCorner isNil |
|
1341 |
and:[cornerRule isNil]]]]]) ifTrue:[ |
|
1342 |
self forceResize |
|
1343 |
] ifFalse:[ |
|
105 | 1344 |
self computeLabelOrigin |
1345 |
] |
|
1346 |
! ! |
|
1347 |
||
205 | 1348 |
!Label class methodsFor:'documentation'! |
1349 |
||
1350 |
version |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
1351 |
^ '$Header: /cvs/stx/stx/libwidg/Label.st,v 1.38 1995-12-14 13:56:43 cg Exp $' |
205 | 1352 |
! ! |