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