author | ca |
Mon, 26 Jan 1998 19:54:50 +0100 | |
changeset 1428 | a4b075871259 |
parent 1414 | b86d8f36f3a9 |
child 1508 | 15d1b3e7e92a |
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 |
||
935 | 22 |
!Label class methodsFor:'documentation'! |
3 | 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. |
|
655 | 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 |
|
1374 | 497 |
Channel operation (controlling fg, 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 |
||
935 | 781 |
!Label class methodsFor:'instance creation'! |
105 | 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 |
|
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
787 |
self obsoleteMethodWarning:'use #label:'. |
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
788 |
^ (self onDevice:Screen current) form:aForm |
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
789 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
790 |
"Modified: 16.6.1997 / 11:47:38 / cg" |
105 | 791 |
! |
792 |
||
793 |
form:aForm in:aView |
|
118 | 794 |
"return a new Label showing a form. |
795 |
OBSOLETE: you should now use #label:in: for both text and bitmap labels." |
|
105 | 796 |
|
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
797 |
self obsoleteMethodWarning:'use #label:in:'. |
105 | 798 |
^ (self in:aView) form:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
799 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
800 |
"Modified: 16.6.1997 / 11:47:57 / cg" |
105 | 801 |
! ! |
802 |
||
935 | 803 |
!Label class methodsFor:'defaults'! |
0 | 804 |
|
805 |
defaultExtent |
|
571 | 806 |
"return the default extent of my instances. |
807 |
The value returned here is usually ignored, and |
|
808 |
the value from preferredExtent taken instead." |
|
0 | 809 |
|
810 |
^ 16 @ 16 |
|
571 | 811 |
|
812 |
"Modified: 22.4.1996 / 23:36:11 / cg" |
|
59 | 813 |
! |
814 |
||
815 |
updateStyleCache |
|
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
816 |
"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
|
817 |
|
1356 | 818 |
<resource: #style (#'label.foregroundColor' #'label.backgroundColor' |
442 | 819 |
#foregroundColor #backgroundColor |
1356 | 820 |
#'label.font')> |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
821 |
|
1356 | 822 |
DefaultForegroundColor := StyleSheet colorAt:'label.foregroundColor'. |
77 | 823 |
DefaultForegroundColor isNil ifTrue:[ |
1374 | 824 |
"/ fallBack: comon value |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
825 |
DefaultForegroundColor := StyleSheet colorAt:'foregroundColor' default:Black. |
77 | 826 |
]. |
1356 | 827 |
DefaultBackgroundColor := StyleSheet colorAt:'label.backgroundColor'. |
77 | 828 |
DefaultBackgroundColor isNil ifTrue:[ |
1374 | 829 |
"/ fallBack: comon value |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
830 |
DefaultBackgroundColor := StyleSheet colorAt:'backgroundColor'. |
77 | 831 |
]. |
1356 | 832 |
DefaultFont := StyleSheet fontAt:'label.font'. |
60 | 833 |
|
834 |
" |
|
835 |
self updateStyleCache |
|
836 |
" |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
837 |
|
1374 | 838 |
"Modified: / 31.10.1997 / 14:53:48 / cg" |
0 | 839 |
! ! |
840 |
||
202 | 841 |
!Label methodsFor:'accessing-channels'! |
105 | 842 |
|
260 | 843 |
backgroundChannel |
1374 | 844 |
"return the backgroundChannel - or nil" |
845 |
||
260 | 846 |
^ backgroundChannel. |
847 |
||
1374 | 848 |
"Created: / 16.12.1995 / 15:50:08 / cg" |
849 |
"Modified: / 31.10.1997 / 14:42:49 / cg" |
|
260 | 850 |
! |
851 |
||
202 | 852 |
backgroundChannel:aValueHolder |
1374 | 853 |
"set the foregroundChannel - a valueHolder holding a color" |
854 |
||
202 | 855 |
|prev| |
105 | 856 |
|
202 | 857 |
prev := backgroundChannel. |
1374 | 858 |
backgroundChannel := aValueHolder. |
859 |
self setupChannel:aValueHolder for:nil withOld:prev |
|
1162 | 860 |
|
1374 | 861 |
"Modified: / 31.10.1997 / 14:39:05 / cg" |
202 | 862 |
! |
145 | 863 |
|
260 | 864 |
foregroundChannel |
1374 | 865 |
"return the foregroundChannel - or nil" |
866 |
||
260 | 867 |
^ foregroundChannel. |
868 |
||
1374 | 869 |
"Created: / 16.12.1995 / 15:50:01 / cg" |
870 |
"Modified: / 31.10.1997 / 14:43:05 / cg" |
|
260 | 871 |
! |
872 |
||
145 | 873 |
foregroundChannel:aValueHolder |
1374 | 874 |
"set the foregroundChannel - a valueHolder holding a color" |
875 |
||
146 | 876 |
|prev| |
877 |
||
878 |
prev := foregroundChannel. |
|
1374 | 879 |
foregroundChannel := aValueHolder. |
880 |
self setupChannel:aValueHolder for:nil withOld:prev |
|
1162 | 881 |
|
1374 | 882 |
"Modified: / 31.10.1997 / 14:38:38 / cg" |
145 | 883 |
! |
884 |
||
260 | 885 |
labelChannel |
1374 | 886 |
"return the labelChannel - or nil" |
887 |
||
260 | 888 |
^ labelChannel. |
889 |
||
1374 | 890 |
"Created: / 16.12.1995 / 15:50:18 / cg" |
891 |
"Modified: / 31.10.1997 / 14:43:14 / cg" |
|
260 | 892 |
! |
893 |
||
145 | 894 |
labelChannel:aValueHolder |
1374 | 895 |
"set the labelChannel - a valueHolder holding a string or image |
896 |
which is shown as my logo" |
|
897 |
||
146 | 898 |
|prev| |
899 |
||
900 |
prev := labelChannel. |
|
145 | 901 |
labelChannel := aValueHolder. |
1374 | 902 |
self setupChannel:aValueHolder for:nil withOld:prev |
903 |
||
904 |
"Modified: / 31.10.1997 / 14:37:02 / cg" |
|
145 | 905 |
! ! |
906 |
||
202 | 907 |
!Label methodsFor:'accessing-colors'! |
125 | 908 |
|
202 | 909 |
backgroundColor |
910 |
"return the background color" |
|
125 | 911 |
|
202 | 912 |
^ bgColor |
125 | 913 |
! |
914 |
||
202 | 915 |
backgroundColor:aColor |
916 |
"set the background color" |
|
125 | 917 |
|
263 | 918 |
aColor ~~ bgColor ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
919 |
bgColor := aColor onDevice:device. |
1218 | 920 |
self class == Label ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
921 |
super viewBackground:bgColor |
1218 | 922 |
]. |
993 | 923 |
shown ifTrue:[self invalidate] |
263 | 924 |
] |
925 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
926 |
"Modified: / 8.2.1997 / 15:19:31 / cg" |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
927 |
"Modified: / 15.1.1998 / 00:14:10 / stefan" |
105 | 928 |
! |
929 |
||
930 |
foregroundColor |
|
931 |
"return the foreground color" |
|
932 |
||
933 |
^ fgColor |
|
934 |
! |
|
935 |
||
202 | 936 |
foregroundColor:aColor |
937 |
"set the foreground color" |
|
105 | 938 |
|
263 | 939 |
aColor ~~ fgColor ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
940 |
fgColor := aColor onDevice:device. |
993 | 941 |
shown ifTrue:[self invalidate] |
263 | 942 |
]. |
943 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
944 |
"Modified: / 8.2.1997 / 15:19:29 / cg" |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
945 |
"Modified: / 15.1.1998 / 00:14:22 / stefan" |
105 | 946 |
! |
947 |
||
948 |
foregroundColor:fg backgroundColor:bg |
|
949 |
"set the colors to be used for drawing" |
|
950 |
||
993 | 951 |
(fgColor ~~ fg or:[bgColor ~~ bg]) ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
952 |
fgColor := fg onDevice:device. |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
953 |
bgColor := bg onDevice:device. |
1218 | 954 |
self class == Label ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
955 |
super viewBackground:bgColor |
1218 | 956 |
]. |
993 | 957 |
shown ifTrue:[self invalidate] |
958 |
]. |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
959 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
960 |
"Modified: / 8.2.1997 / 15:19:22 / cg" |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
961 |
"Modified: / 15.1.1998 / 00:14:36 / stefan" |
1218 | 962 |
! |
963 |
||
964 |
viewBackground:aColor |
|
965 |
"for labels, the viewBackground is forced to be the same as |
|
966 |
the backgroundColor" |
|
967 |
||
968 |
self class == Label ifTrue:[ |
|
969 |
self backgroundColor:aColor |
|
970 |
]. |
|
971 |
super viewBackground:aColor |
|
133 | 972 |
! ! |
973 |
||
974 |
!Label methodsFor:'accessing-contents'! |
|
0 | 975 |
|
202 | 976 |
form:aForm |
977 |
"set the labels form; adjust extent if not already realized. |
|
978 |
OBSOLETE: you should now use #label: for both strings and images" |
|
118 | 979 |
|
202 | 980 |
self label:aForm |
981 |
! |
|
982 |
||
983 |
label |
|
984 |
"return the labels string or image" |
|
985 |
||
986 |
^ logo |
|
118 | 987 |
! |
105 | 988 |
|
118 | 989 |
label:aStringOrFormOrImage |
990 |
"set the labelString or image; adjust extent if not already realized and |
|
991 |
not fixedSize" |
|
992 |
||
993 |
(aStringOrFormOrImage ~~ logo) ifTrue:[ |
|
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
994 |
"/ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
995 |
"/ avoid recompute of size, if its an image with |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
996 |
"/ the same size |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
997 |
"/ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
998 |
aStringOrFormOrImage isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
999 |
logo notNil ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1000 |
logo isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1001 |
logo extent = aStringOrFormOrImage extent ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1002 |
logo := aStringOrFormOrImage. |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1003 |
shown ifTrue:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1004 |
self invalidate |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1005 |
]. |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1006 |
^ self |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1007 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1008 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1009 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1010 |
] ifFalse:[ |
806
a641ed42df70
dont ignore new label setting, if the emphasis changed
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
1011 |
"/ any change ? |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1012 |
(logo = aStringOrFormOrImage) ifTrue:[ |
817
58c611fad735
check if label is a string, before asking for emphasis
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1013 |
(logo isString) ifTrue:[ |
58c611fad735
check if label is a string, before asking for emphasis
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1014 |
(logo emphasis = aStringOrFormOrImage emphasis) ifTrue:[ |
58c611fad735
check if label is a string, before asking for emphasis
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1015 |
^ self |
58c611fad735
check if label is a string, before asking for emphasis
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1016 |
] |
806
a641ed42df70
dont ignore new label setting, if the emphasis changed
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
1017 |
] |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1018 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1019 |
]. |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1020 |
logo := aStringOrFormOrImage. |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1021 |
self newLayout |
105 | 1022 |
] |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1023 |
|
817
58c611fad735
check if label is a string, before asking for emphasis
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1024 |
"Modified: 2.8.1996 / 21:02:41 / cg" |
105 | 1025 |
! |
0 | 1026 |
|
1367 | 1027 |
label:newLabel suppressResize:suppress |
1028 |
"change the label and optionally suppress a resize operation" |
|
1029 |
||
1030 |
|wasFix| |
|
1031 |
||
1032 |
wasFix := fixSize. |
|
1033 |
suppress ifTrue:[ |
|
1034 |
fixSize := true. |
|
1035 |
]. |
|
1036 |
here label:newLabel. |
|
1037 |
fixSize := wasFix |
|
1038 |
||
1039 |
"Modified: / 29.10.1997 / 15:50:01 / cg" |
|
1040 |
! |
|
1041 |
||
202 | 1042 |
labelString:aString |
1043 |
"for ST-80 compatibility: same as #label: |
|
1044 |
set the label-string; adjust extent if not already realized and not fixedSize" |
|
118 | 1045 |
|
202 | 1046 |
self label:aString |
1047 |
! |
|
1048 |
||
1049 |
labelWidth |
|
1050 |
"return the logos width in pixels" |
|
1051 |
||
1052 |
^ labelWidth |
|
118 | 1053 |
! |
1054 |
||
1055 |
logo:something |
|
1056 |
"set the labels form or string. |
|
1057 |
OBSOLETE: the old version used #form: for images and #label: for strings. |
|
1058 |
you should now use #label: for any." |
|
1059 |
||
1060 |
self label:something |
|
133 | 1061 |
! ! |
1062 |
||
1063 |
!Label methodsFor:'accessing-layout'! |
|
1064 |
||
202 | 1065 |
adjust |
1066 |
"return the adjust symbol" |
|
0 | 1067 |
|
202 | 1068 |
^ adjust |
125 | 1069 |
! |
1070 |
||
105 | 1071 |
adjust:how |
1072 |
"set the adjust, how which must be one of |
|
0 | 1073 |
|
105 | 1074 |
#left -> left adjust logo |
1075 |
#right -> right adjust logo |
|
1076 |
#center -> center logo |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1077 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1078 |
#centerRight -> center logo if it fits; |
533 | 1079 |
BUT, if it does not fit, right adjust the logo |
1080 |
(use with filenames, where the interesting part is |
|
1081 |
at the right if the label is too small) |
|
1082 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1083 |
#centerLeft -> center logo if it fits; |
533 | 1084 |
BUT, if it does not fit, left adjust the logo |
1085 |
(use with strings where the interesting part is at the |
|
1086 |
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
|
1087 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1088 |
#leftRight -> left adjust logo if it fits |
533 | 1089 |
BUT, if it does not fit, right adjust the logo |
1090 |
(use with filenames, where the interesting part is |
|
1091 |
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
|
1092 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1093 |
#rightLeft -> right adjust logo if it fits |
533 | 1094 |
BUT, if it does not fit, left adjust the logo |
1095 |
(use with strings where the interesting part is at the |
|
1096 |
left if the label is too small) |
|
1097 |
||
1098 |
See examples in the documentation category. |
|
105 | 1099 |
" |
118 | 1100 |
|
105 | 1101 |
(adjust ~~ how) ifTrue:[ |
533 | 1102 |
adjust := how. |
1103 |
self newLayout |
|
105 | 1104 |
] |
533 | 1105 |
|
1106 |
"Modified: 13.4.1996 / 11:17:58 / cg" |
|
105 | 1107 |
! |
1108 |
||
202 | 1109 |
font:aFont |
665 | 1110 |
"set the font - if I'm not realized and not fixedSize, adjust my size. |
1111 |
CAVEAT: with the addition of Text objects, |
|
1112 |
this method is going to be obsoleted by a textStyle |
|
1113 |
method, which allows specific control over |
|
1114 |
normalFont/boldFont/italicFont parameters." |
|
125 | 1115 |
|
416 | 1116 |
(aFont notNil and:[aFont ~~ font]) ifTrue:[ |
1117 |
super font:(aFont on:device). |
|
1118 |
self newLayout |
|
202 | 1119 |
] |
416 | 1120 |
|
665 | 1121 |
"Modified: 22.5.1996 / 12:36:29 / cg" |
133 | 1122 |
! |
1123 |
||
1124 |
horizontalSpace:aNumber |
|
1125 |
"set the number of pixels by which the logo |
|
1126 |
is horizontally inset from the border" |
|
1127 |
||
162 | 1128 |
hSpace := aNumber. |
1129 |
self newLayout |
|
133 | 1130 |
! |
1131 |
||
202 | 1132 |
layout:something |
1133 |
"OBSOLETE compatibility interface. Will vanish. |
|
1134 |
for protocol compatibility: alias for #adjust:. |
|
1135 |
Please use #adjust:, since #layout: conflicts with a method |
|
1136 |
in VW (which has a completely different meaning). |
|
1137 |
In future versions of ST/X, #layout: will behave the VW way. |
|
1138 |
In the meantime, try to figure out what is meant ... a kludge" |
|
1139 |
||
1140 |
something isLayout ifTrue:[^ super layout:something]. |
|
1141 |
||
1142 |
self obsoleteMethodWarning:'use #adjust:'. |
|
1143 |
self adjust:something |
|
1144 |
||
1145 |
"Modified: 31.8.1995 / 23:08:13 / claus" |
|
1146 |
! |
|
1147 |
||
1148 |
sizeFixed |
|
1149 |
"return the fix-size attribute" |
|
1150 |
||
1151 |
^ fixSize |
|
1152 |
! |
|
1153 |
||
1154 |
sizeFixed:aBoolean |
|
1155 |
"set/clear the fix-size attribute. |
|
1156 |
If true, the receiver will not change its size when the labelString/logo |
|
1157 |
changes. If false (the default), it will resize itself to make the logo |
|
1158 |
fit." |
|
1159 |
||
1160 |
fixSize := aBoolean |
|
1161 |
! |
|
1162 |
||
1163 |
verticalSpace:aNumber |
|
1164 |
"set the number of pixels by which the logo |
|
1165 |
is vertically inset from the border" |
|
1166 |
||
1167 |
vSpace := aNumber. |
|
1168 |
self newLayout |
|
1169 |
! ! |
|
1170 |
||
1171 |
!Label methodsFor:'accessing-mvc'! |
|
1172 |
||
1173 |
addModelInterfaceTo:aDictionary |
|
1174 |
"see comment in View>>modelInterface" |
|
1175 |
||
1176 |
super addModelInterfaceTo:aDictionary. |
|
1177 |
aDictionary at:#labelMessage put:labelMsg |
|
1178 |
! |
|
1179 |
||
1180 |
converter:aConverter |
|
1181 |
"set the printConverter; |
|
1182 |
that one is asked to convert the models value to a printed |
|
1183 |
representation (if non-nil). If nil, the model is supposed to |
|
1184 |
return a string or bitmap image." |
|
1185 |
||
1186 |
converter := aConverter |
|
1187 |
! |
|
105 | 1188 |
|
202 | 1189 |
labelMessage |
1190 |
"return the symbol used to aquire the labelString/image from the model |
|
1191 |
when the aspect changes. |
|
1192 |
The default is nil, which means: leave the label unchanged." |
|
1193 |
||
1194 |
^ labelMsg |
|
1195 |
! |
|
1196 |
||
1197 |
labelMessage:aSymbol |
|
1198 |
"set the symbol used to aquire the labelString/image from the model. |
|
1199 |
The default is nil, which means: leave the label unchanged." |
|
1200 |
||
1201 |
labelMsg ~~ aSymbol ifTrue:[ |
|
1202 |
labelMsg := aSymbol. |
|
1203 |
self getLabelFromModel |
|
1204 |
] |
|
1205 |
! |
|
1206 |
||
1207 |
model:aModel |
|
1208 |
super model:aModel. |
|
1039 | 1209 |
labelMsg notNil ifTrue:[ |
1210 |
self getLabelFromModel. |
|
1211 |
] |
|
202 | 1212 |
! ! |
1213 |
||
1214 |
!Label methodsFor:'change & update'! |
|
1215 |
||
1216 |
update:something with:aParameter from:changedObject |
|
1217 |
"the MVC way of changing the label ..." |
|
1218 |
||
1374 | 1219 |
changedObject notNil ifTrue:[ |
1220 |
changedObject == backgroundChannel ifTrue:[ |
|
1221 |
self backgroundColor:(backgroundChannel value). |
|
1222 |
^ self |
|
1223 |
]. |
|
1224 |
changedObject == foregroundChannel ifTrue:[ |
|
1225 |
self foregroundColor:(foregroundChannel value). |
|
1226 |
^ self |
|
1227 |
]. |
|
1228 |
changedObject == labelChannel ifTrue:[ |
|
1229 |
self label:(labelChannel value). |
|
1230 |
^ self |
|
1231 |
]. |
|
1232 |
||
1233 |
changedObject == model ifTrue:[ |
|
1234 |
something == aspectMsg ifTrue:[ |
|
1235 |
self getLabelFromModel. |
|
1236 |
^ self. |
|
1237 |
] |
|
1238 |
]. |
|
202 | 1239 |
]. |
1240 |
^ super update:something with:aParameter from:changedObject |
|
1374 | 1241 |
|
1242 |
"Modified: / 31.10.1997 / 14:32:02 / cg" |
|
202 | 1243 |
! ! |
1244 |
||
1245 |
!Label methodsFor:'event handling'! |
|
1246 |
||
1247 |
sizeChanged:how |
|
1248 |
"sent whenever size is changed by someone else - recompute the |
|
1249 |
logos position within the View." |
|
1250 |
||
1251 |
|prevPosition| |
|
1252 |
||
1253 |
super sizeChanged:how. |
|
1254 |
prevPosition := labelOriginX. |
|
1392 | 1255 |
self computeLabelOrigin. |
202 | 1256 |
shown ifTrue:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1257 |
(adjust == #fit |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1258 |
or:[labelOriginX ~~ prevPosition |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1259 |
or:[how ~~ #smaller]]) ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1260 |
"/ self clear. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1261 |
self invalidate. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1262 |
"/ self redrawEdges |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1263 |
] |
105 | 1264 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1265 |
|
1392 | 1266 |
"Modified: / 3.11.1997 / 18:17:12 / cg" |
0 | 1267 |
! ! |
1268 |
||
1269 |
!Label methodsFor:'initialization'! |
|
1270 |
||
1398 | 1271 |
destroy |
1272 |
labelChannel notNil ifTrue:[ |
|
1273 |
labelChannel removeDependent:self. |
|
1274 |
labelChannel := nil. |
|
1275 |
]. |
|
1276 |
foregroundChannel notNil ifTrue:[ |
|
1277 |
foregroundChannel removeDependent:self. |
|
1278 |
foregroundChannel := nil. |
|
1279 |
]. |
|
1280 |
backgroundChannel notNil ifTrue:[ |
|
1281 |
backgroundChannel removeDependent:self. |
|
1282 |
backgroundChannel := nil. |
|
1283 |
]. |
|
1284 |
super destroy |
|
1285 |
||
1286 |
"Created: / 14.11.1997 / 13:48:52 / cg" |
|
1287 |
"Modified: / 14.11.1997 / 13:59:38 / cg" |
|
1288 |
! |
|
1289 |
||
935 | 1290 |
fetchDeviceResources |
1291 |
"fetch device colors, to avoid reallocation at redraw time" |
|
1292 |
||
1293 |
super fetchDeviceResources. |
|
1294 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1295 |
fgColor := fgColor onDevice:device. |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1296 |
bgColor := bgColor onDevice:device. |
935 | 1297 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1298 |
"Created: / 13.1.1997 / 23:34:30 / cg" |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1299 |
"Modified: / 15.1.1998 / 00:13:46 / stefan" |
935 | 1300 |
! |
1301 |
||
0 | 1302 |
initStyle |
967 | 1303 |
"setup viewStyle specifics" |
1304 |
||
0 | 1305 |
super initStyle. |
1306 |
||
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
1307 |
"/ DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
1308 |
|
59 | 1309 |
DefaultBackgroundColor notNil ifTrue:[ |
935 | 1310 |
bgColor := DefaultBackgroundColor |
38 | 1311 |
] ifFalse:[ |
935 | 1312 |
bgColor := viewBackground. |
59 | 1313 |
]. |
1314 |
DefaultForegroundColor notNil ifTrue:[ |
|
935 | 1315 |
fgColor := DefaultForegroundColor |
59 | 1316 |
] ifFalse:[ |
935 | 1317 |
fgColor := Black. |
1374 | 1318 |
]. |
1319 |
self class == Label ifTrue:[ |
|
1320 |
borderWidth := 0. |
|
38 | 1321 |
] |
935 | 1322 |
|
1374 | 1323 |
"Modified: / 31.10.1997 / 14:57:23 / cg" |
0 | 1324 |
! |
1325 |
||
105 | 1326 |
initialize |
1327 |
super initialize. |
|
1328 |
||
1329 |
font := font on:device. |
|
832 | 1330 |
self initialHeight:(font height + font descent). |
105 | 1331 |
adjust := #center. |
118 | 1332 |
labelOriginX := labelOriginY := 0. |
1333 |
labelWidth := labelHeight := 0. |
|
105 | 1334 |
logo := nil. |
1335 |
fixSize := false. |
|
1336 |
hSpace := (self horizontalPixelPerMillimeter:0.5) rounded. |
|
131 | 1337 |
vSpace := (self verticalPixelPerMillimeter:0.25) rounded |
105 | 1338 |
! |
1339 |
||
0 | 1340 |
recreate |
1341 |
"after snapin, labels dimensions may have changed due to |
|
1342 |
different font parameters" |
|
1343 |
||
1344 |
super recreate. |
|
3 | 1345 |
font := font on:device. |
0 | 1346 |
self computeLabelSize. |
1347 |
self computeLabelOrigin |
|
1348 |
! ! |
|
1349 |
||
202 | 1350 |
!Label methodsFor:'private'! |
1351 |
||
1352 |
computeLabelOrigin |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1353 |
"(re)compute the origin of the label whenever label, font or view-size changes" |
202 | 1354 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1355 |
|x y a| |
202 | 1356 |
|
1357 |
labelHeight isNil ifTrue:[^ self]. |
|
1358 |
||
1359 |
adjust == #fit ifTrue:[ |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1360 |
labelOriginX := labelOriginY := margin. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1361 |
^ self |
202 | 1362 |
]. |
1363 |
||
1364 |
"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
|
1365 |
or the center ? |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1366 |
(for text, the center seems better. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1367 |
For images, I dont really know ...) |
202 | 1368 |
The commented code below makes the origin visible |
1369 |
" |
|
1370 |
"/ (labelHeight < height) ifTrue:[ |
|
1371 |
"/ y := (height - labelHeight) // 2 |
|
1372 |
"/ ] ifFalse:[ |
|
1373 |
"/ y := 0 |
|
1374 |
"/ ]. |
|
1375 |
||
1376 |
"always center vertically" |
|
1377 |
y := (height - labelHeight) // 2. |
|
1378 |
||
1379 |
labelOriginY := y. |
|
1380 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1381 |
a := adjust. |
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1382 |
(width < labelWidth) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1383 |
((adjust == #centerRight) or:[adjust == #leftRight]) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1384 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1385 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1386 |
((adjust == #centerLeft) or:[adjust == #rightLeft]) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1387 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1388 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1389 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1390 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1391 |
((adjust == #centerRight) or:[adjust == #centerLeft]) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1392 |
a := #center |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1393 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1394 |
adjust == #leftRight ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1395 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1396 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1397 |
adjust == #rightLeft ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1398 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1399 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1400 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1401 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1402 |
]. |
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1403 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1404 |
(a == #center) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1405 |
" center text/form in button " |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1406 |
x := (width - labelWidth) // 2. |
202 | 1407 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1408 |
(a == #left) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1409 |
x := margin |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1410 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1411 |
"/ #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1412 |
x := width - labelWidth - margin |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1413 |
] |
202 | 1414 |
]. |
1415 |
labelOriginX := x |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1416 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1417 |
"Modified: 13.5.1996 / 10:55:17 / cg" |
202 | 1418 |
! |
1419 |
||
1420 |
computeLabelSize |
|
1421 |
"compute the extent needed to hold the label; aForm or aString" |
|
1422 |
||
1284 | 1423 |
|numberOfLines textHeight textWidth b| |
202 | 1424 |
|
1425 |
logo isNil ifTrue:[^ self]. |
|
1426 |
||
1427 |
logo isString ifTrue:[ |
|
626 | 1428 |
numberOfLines := 1 + (logo occurrencesOf:(Character cr)). |
1429 |
(numberOfLines ~~ 1) ifTrue:[ |
|
1430 |
logo := logo asStringCollection |
|
1431 |
] |
|
202 | 1432 |
] ifFalse:[ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1433 |
(logo isKindOf:StringCollection) ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1434 |
numberOfLines := logo size. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1435 |
(numberOfLines <= 1) ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1436 |
logo := logo asString |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1437 |
] |
626 | 1438 |
] |
202 | 1439 |
]. |
1440 |
||
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1441 |
numberOfLines isNil ifTrue:[ |
756 | 1442 |
(logo respondsTo:#preferredBounds) ifTrue:[ |
1443 |
b := logo preferredBounds. |
|
1444 |
labelWidth := b width. |
|
1445 |
labelHeight := b height. |
|
1446 |
] ifFalse:[ |
|
1447 |
labelWidth := logo widthOn:self. |
|
1448 |
labelHeight := logo heightOn:self. |
|
1449 |
]. |
|
640 | 1450 |
|
1451 |
"/ b := logo bounds. |
|
1452 |
"/ labelWidth := b right. |
|
1453 |
"/ labelHeight := b bottom. |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1454 |
logo isImageOrForm ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1455 |
labelWidth := labelWidth + (hSpace * 2). |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1456 |
labelHeight := labelHeight + (vSpace * 2). |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1457 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1458 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1459 |
^ self |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1460 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1461 |
|
202 | 1462 |
"/ textHeight := font height * numberOfLines + font descent. |
626 | 1463 |
|
640 | 1464 |
logo isString ifTrue:[ |
1465 |
"/ a string or Text |
|
1466 |
textHeight := logo heightOn:self. |
|
1467 |
textWidth := logo widthOn:self. |
|
1468 |
] ifFalse:[ |
|
1469 |
"/ a StringCollection |
|
1470 |
textHeight := font height * numberOfLines. |
|
794 | 1471 |
"/ textWidth := font widthOf:logo. |
1472 |
||
1473 |
textWidth := 0. |
|
1474 |
logo do:[:line | |
|
1475 |
|this| |
|
1476 |
||
1477 |
line notNil ifTrue:[ |
|
1478 |
this := line asString widthOn:self. |
|
1479 |
(this > textWidth) ifTrue:[textWidth := this] |
|
1480 |
] |
|
1481 |
]. |
|
640 | 1482 |
]. |
1483 |
||
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1484 |
labelWidth := textWidth + (hSpace * 2). |
202 | 1485 |
labelHeight := textHeight + (vSpace * 2) |
626 | 1486 |
|
794 | 1487 |
"Modified: 17.7.1996 / 14:33:10 / cg" |
202 | 1488 |
! |
1489 |
||
1490 |
getLabelFromModel |
|
1491 |
"ask my model for the label to show. |
|
1492 |
Here, we use labelMsg (instead of aspectMsg). |
|
1493 |
This allows multiple labels to react on the same aspect, |
|
1494 |
but show different labels when changed |
|
1495 |
(also, since labelMsg defaults to nil, constant labels |
|
1496 |
which have a nil labelMsg will not try to aquire a labelString)." |
|
1497 |
||
1498 |
|val| |
|
1499 |
||
1500 |
(model notNil |
|
1501 |
and:[labelMsg notNil]) ifTrue:[ |
|
1502 |
val := model perform:labelMsg. |
|
1503 |
converter notNil ifTrue:[ |
|
1504 |
val := converter printStringFor:val |
|
1505 |
]. |
|
1506 |
self label:val. |
|
1507 |
]. |
|
1508 |
! |
|
1509 |
||
1510 |
newLayout |
|
1511 |
"recompute position/size after a change |
|
1512 |
- helper for form:/font: etc." |
|
1513 |
||
1514 |
self computeLabelSize. |
|
1515 |
fixSize ifFalse:[ |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1516 |
self resize |
202 | 1517 |
]. |
1428 | 1518 |
self computeLabelOrigin. |
202 | 1519 |
shown ifTrue:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1520 |
self invalidate |
202 | 1521 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1522 |
|
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1523 |
"Modified: 26.5.1996 / 18:09:52 / cg" |
202 | 1524 |
! ! |
1525 |
||
1526 |
!Label methodsFor:'queries'! |
|
1527 |
||
1528 |
preferredExtent |
|
1529 |
"return my preferred extent - this is the minimum size I would like to have" |
|
1530 |
||
1531 |
|extra| |
|
1532 |
||
799 | 1533 |
"/ If I have an explicit preferredExtent .. |
1534 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1535 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1536 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1537 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1538 |
|
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1539 |
fixSize ifTrue:[^ self extent]. |
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1540 |
|
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1541 |
logo isNil ifTrue:[ |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1542 |
self label:'' |
202 | 1543 |
]. |
1544 |
||
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1545 |
logo notNil ifTrue:[ |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1546 |
extra := margin * 2. |
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1547 |
^ (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
|
1548 |
]. |
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1549 |
|
202 | 1550 |
^ super preferredExtent |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1551 |
|
799 | 1552 |
"Modified: 19.7.1996 / 20:44:41 / cg" |
993 | 1553 |
! |
1554 |
||
1555 |
redrawsFull |
|
1556 |
^ true |
|
1557 |
||
1558 |
"Created: 7.2.1997 / 16:41:41 / cg" |
|
202 | 1559 |
! ! |
1560 |
||
0 | 1561 |
!Label methodsFor:'redrawing'! |
1562 |
||
77 | 1563 |
clearInsideWith:bg |
1564 |
|cutOff mustClear| |
|
0 | 1565 |
|
1566 |
cutOff := margin * 2. |
|
1567 |
||
3 | 1568 |
mustClear := true. |
1569 |
||
87 | 1570 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[ |
59 | 1571 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[ |
1572 |
logo width >= (width - cutOff) ifTrue:[ |
|
1573 |
logo height >= (height - cutOff) ifTrue:[ |
|
1574 |
"no need to clear before - avoid flicker" |
|
1575 |
mustClear := false |
|
1576 |
] |
|
1577 |
] |
|
1578 |
]. |
|
3 | 1579 |
]. |
1580 |
||
1581 |
mustClear ifTrue:[ |
|
59 | 1582 |
self paint:bg. |
1583 |
self fillRectangleX:margin y:margin |
|
1584 |
width:(width - cutOff) |
|
1585 |
height:(height - cutOff). |
|
3 | 1586 |
]. |
77 | 1587 |
! |
1588 |
||
1589 |
drawWith:fg and:bg |
|
1590 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1591 |
(especially Button) to redraw the logo in different colors." |
|
1592 |
||
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1593 |
|x y scaleH scaleV nW nH hSep vSep m2 stringLogo| |
77 | 1594 |
|
1595 |
self clearInsideWith:bg. |
|
0 | 1596 |
|
1597 |
logo notNil ifTrue:[ |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1598 |
self paint:fg on:bg. |
131 | 1599 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1600 |
m2 := margin * 2. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1601 |
hSep := (hSpace*2). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1602 |
vSep := (vSpace*2). |
133 | 1603 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1604 |
x := labelOriginX. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1605 |
y := labelOriginY. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1606 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1607 |
logo isImageOrForm ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1608 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1609 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1610 |
"/ 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
|
1611 |
"/ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1612 |
scaleH := ((width - hSep) / (logo width)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1613 |
scaleV := ((height - vSep) / (logo height)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1614 |
self scale:(scaleH @ scaleV). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1615 |
x := transformation applyInverseScaleX:x. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1616 |
y := transformation applyInverseScaleY:y. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1617 |
]. |
131 | 1618 |
|
1242 | 1619 |
logo := logo onDevice:device. |
59 | 1620 |
"/ self background:bg. |
1089
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1621 |
logo mask notNil ifTrue:[ |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1622 |
self displayForm:logo x:x y:y |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1623 |
] ifFalse:[ |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1624 |
self displayOpaqueForm:logo x:x y:y |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1625 |
] |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1626 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1627 |
x := x + hSpace. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1628 |
y := y + vSpace. |
0 | 1629 |
|
1428 | 1630 |
(logo isString |
1631 |
or:[logo species == String |
|
1632 |
or:[logo isKindOf:StringCollection]]) ifTrue:[ |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1633 |
stringLogo := true. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1634 |
y := y + (font ascent). |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1635 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1636 |
stringLogo := false. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1637 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1638 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1639 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1640 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1641 |
"/ 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
|
1642 |
"/ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1643 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1644 |
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
|
1645 |
|
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1646 |
self scale:(scaleH min:scaleV). |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1647 |
x := transformation applyInverseScaleX:x. |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1648 |
stringLogo ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1649 |
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
|
1650 |
]. |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1651 |
y := transformation applyInverseScaleY:y. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1652 |
scaleH < scaleV ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1653 |
nH := labelHeight * scaleH. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1654 |
"/ now, center vertically |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1655 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1656 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1657 |
scaleV < scaleH ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1658 |
"/ now, center horizontally |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1659 |
nW := labelWidth * scaleV. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1660 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2) |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1661 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1662 |
]. |
131 | 1663 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1664 |
logo isString ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1665 |
self displayOpaqueString:logo x:x y:y |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1666 |
] ifFalse:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1667 |
(logo isKindOf:StringCollection) ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1668 |
logo do:[ :line | |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1669 |
self displayOpaqueString:(line printString) x:x y:y. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1670 |
y := y + (font height) |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1671 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1672 |
] ifFalse:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1673 |
"/ anything |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1674 |
logo displayOn:self x:x y:y |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1675 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1676 |
]. |
131 | 1677 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1678 |
]. |
131 | 1679 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1680 |
adjust == #fit ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1681 |
self scale:1 |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1682 |
]. |
131 | 1683 |
|
0 | 1684 |
] |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1685 |
|
1242 | 1686 |
"Modified: 6.6.1997 / 16:38:48 / cg" |
0 | 1687 |
! |
1688 |
||
1689 |
redraw |
|
1690 |
"redraw my label" |
|
1691 |
||
1692 |
shown ifTrue:[ |
|
59 | 1693 |
self drawWith:fgColor and:bgColor |
0 | 1694 |
] |
1695 |
! ! |
|
105 | 1696 |
|
110 | 1697 |
!Label methodsFor:'resizing'! |
1698 |
||
1699 |
forceResize |
|
118 | 1700 |
"resize myself to make text fit into myself. Here, this is done even if |
1701 |
fixSize is set." |
|
110 | 1702 |
|
1703 |
logo notNil ifTrue:[ |
|
130 | 1704 |
self extent:self preferredExtent. |
110 | 1705 |
self computeLabelOrigin |
1706 |
] |
|
105 | 1707 |
! |
1708 |
||
1709 |
resize |
|
1710 |
"resize myself to make text fit into myself. |
|
118 | 1711 |
but only do so, if I am not fixedSize and I have NOT been |
1712 |
given a relative extent or an extend computation block." |
|
105 | 1713 |
|
110 | 1714 |
(logo notNil |
1715 |
and:[fixSize not |
|
1716 |
and:[relativeExtent isNil |
|
1717 |
and:[extentRule isNil |
|
1718 |
and:[relativeCorner isNil |
|
1719 |
and:[cornerRule isNil]]]]]) ifTrue:[ |
|
1720 |
self forceResize |
|
1721 |
] ifFalse:[ |
|
105 | 1722 |
self computeLabelOrigin |
1723 |
] |
|
1724 |
! ! |
|
1725 |
||
935 | 1726 |
!Label class methodsFor:'documentation'! |
205 | 1727 |
|
1728 |
version |
|
1428 | 1729 |
^ '$Header: /cvs/stx/stx/libwidg/Label.st,v 1.88 1998-01-26 18:54:50 ca Exp $' |
205 | 1730 |
! ! |