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