author | Claus Gittinger <cg@exept.de> |
Wed, 20 Feb 2019 10:29:52 +0100 | |
changeset 6539 | 11056d07f893 |
parent 6485 | 40a6475c4b7a |
child 6542 | 9bc32510b526 |
permissions | -rw-r--r-- |
6326 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 5 |
All Rights Reserved |
0 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2192
e9068416fd41
foreground-, backgroundChannel moved to superclass (#destroy)
Stefan Vogel <sv@exept.de>
parents:
2098
diff
changeset
|
14 |
"{ Package: 'stx:libwidg' }" |
e9068416fd41
foreground-, backgroundChannel moved to superclass (#destroy)
Stefan Vogel <sv@exept.de>
parents:
2098
diff
changeset
|
15 |
|
5445 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
View subclass:#Label |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
19 |
instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust |
2496 | 20 |
hSpace vSpace bgColor fgColor etchedFgColor fixSize labelMsg |
21 |
converter labelChannel' |
|
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
22 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor' |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
23 |
poolDictionaries:'' |
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
24 |
category:'Views-Layout' |
0 | 25 |
! |
26 |
||
5751 | 27 |
Object subclass:#AnimatorState |
5755 | 28 |
instanceVariableNames:'timedBlock nextOffset logoShown moveDirection pointerEntered' |
5751 | 29 |
classVariableNames:'' |
30 |
poolDictionaries:'' |
|
31 |
privateIn:Label |
|
32 |
! |
|
33 |
||
935 | 34 |
!Label class methodsFor:'documentation'! |
3 | 35 |
|
38 | 36 |
copyright |
37 |
" |
|
38 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 39 |
All Rights Reserved |
38 | 40 |
|
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
" |
|
48 |
! |
|
49 |
||
3 | 50 |
documentation |
51 |
" |
|
38 | 52 |
This class implements labels, which are views to display a string or image. |
53 |
The Label will try to do its best to make its contents fit into the |
|
54 |
view. The contents can be a String, a collection of Strings (i.e. |
|
118 | 55 |
a StringCollection) or a Form/Image. |
63 | 56 |
|
57 |
The contents is drawn in fgColor/bgColor, which can be changed using: |
|
58 |
||
585 | 59 |
aLabel foregroundColor:aColor |
60 |
aLabel backgroundColor:aColor |
|
3 | 61 |
|
38 | 62 |
When a label is assigned a contents, it will resize itself to fit |
63 |
the required size. This resizing can be suppressed by setting the |
|
64 |
fixsize attribute to true using: |
|
63 | 65 |
|
585 | 66 |
aLabel sizeFixed:true |
3 | 67 |
|
38 | 68 |
This can be used, if resizing of the label is not wanted. |
63 | 69 |
However, in this case you have to make certain that the size is big enough |
118 | 70 |
to hold any changed logos later. (usually, you create the label first with |
71 |
the longest string first to have it compute its size, then set the fixSize |
|
72 |
attribute to avoid resizing later). |
|
125 | 73 |
Be careful when placing self-resizing labels into panels - by default, |
74 |
panels do not react on the size change - leading to ugly looking geometry. |
|
75 |
(but you can tell the panel to watch for changes with #elementsCHangeSize:) |
|
38 | 76 |
|
77 |
The placement of the contents within the label is controlled by |
|
63 | 78 |
the adjust attribute, it can be set with: |
79 |
||
585 | 80 |
aLabel adjust:how |
3 | 81 |
|
1946 | 82 |
where how is one of the symbols left, #right, #center, #centerEach, |
83 |
#centerLeft, #centerRight, #leftRight or #rightLeft |
|
84 |
(see the comment in Label>>adjust:). The default is #center. |
|
3 | 85 |
|
145 | 86 |
model-less operation (ok for static labels): |
118 | 87 |
if no model is set, the labels contents is set with: |
88 |
||
585 | 89 |
aLabel label:aStringOrImage |
118 | 90 |
|
91 |
and stays constant unless changed by new calls to #label:. |
|
92 |
||
93 |
||
145 | 94 |
model operation (ST-80 style): |
118 | 95 |
labels with a model, aspectMsg and labelMsg react to |
96 |
changes of the aspect, and send a labelMsg-message |
|
5782 | 97 |
to the model in order to acquire a new labelString or image. |
118 | 98 |
The model should send 'self changed:aspectMsg' if it thinks the label |
99 |
should change and return a string or image from the labelMsg-message. |
|
100 |
||
585 | 101 |
label model:aModel. |
102 |
label aspect:aspectSymbol. |
|
103 |
label labelMessage:labelSymbol. |
|
118 | 104 |
|
585 | 105 |
model sends #changed:aspectSymbol |
106 |
---> label will redraw its label from value of model perform:labelSymbol |
|
118 | 107 |
|
108 |
Having a labelSymbol different from the aspectSymbol allows for two labels |
|
109 |
to react on the same aspect-change, but use different messages when asking |
|
110 |
the model for a new label contents. By default, the labelMsg is nil, |
|
111 |
so the label does NOT update its shown contents. |
|
112 |
The aspectMsg defaults to #value. |
|
113 |
||
125 | 114 |
|
145 | 115 |
|
116 |
channel operation (new ST/X style): |
|
117 |
||
118 |
the label will react on changes of the token found in the |
|
119 |
channels: foregroundChannel, backgroundChannel and labelChannel. |
|
120 |
These are valueHolders and can be shared between labels. |
|
121 |
||
122 |
||
123 |
||
585 | 124 |
[Instance variables:] |
3 | 125 |
|
585 | 126 |
logo <Object> the logo, can be a Form, String or Text |
127 |
labelWidth <Integer> the width of the logo in device units |
|
128 |
labelHeight <Integer> the height of the logo in device units |
|
129 |
labelOriginX <Integer> the x-position of the logo withing the Label |
|
130 |
labelOriginY <Integer> the y-position of the logo withing the Label |
|
131 |
adjust <Symbol> controls how the logo is positioned within the |
|
132 |
label. Can be one of:#left,#right,#center, |
|
133 |
#centerLeft or #centerRight (see comment in adjust:) |
|
134 |
hSpace <Integer> number of horizontal pixels around logo |
|
135 |
vSpace <Integer> number of vertical pixels around logo |
|
3 | 136 |
|
585 | 137 |
bgColor <Color> background color |
138 |
fgColor <Color> foreground color |
|
38 | 139 |
|
585 | 140 |
fixSize <Boolean> if true, a change of the logo change will not |
141 |
resize the label; otherwise, its size is adjusted. |
|
142 |
default:false. |
|
50 | 143 |
|
585 | 144 |
labelMsg <Symbol> if non-nil, this is sent to the model to |
5782 | 145 |
acquire the labelString or labelImage. |
585 | 146 |
If nil, the label stays as is |
113 | 147 |
|
585 | 148 |
[styleSheet parameters:] |
50 | 149 |
|
118 | 150 |
labelForegroundColor <Color> color to draw foreground pixels (i.e. the string) |
151 |
labelBackgroundColor <Color> color to draw background pixels |
|
152 |
labelFont <Font> font to use for textual labels |
|
585 | 153 |
|
154 |
[author:] |
|
155 |
Claus Gittinger |
|
593 | 156 |
|
157 |
[see also:] |
|
158 |
Panel HorizontalPanel VerticalPanel |
|
159 |
TextView EditTextView |
|
160 |
Button |
|
161 |
InfoBox WarningBox |
|
3 | 162 |
" |
63 | 163 |
! |
164 |
||
165 |
examples |
|
166 |
" |
|
167 |
Notice, that Buttons and others inherit from Label; |
|
168 |
therefore, the following geometry examples apply to all subclasses too. |
|
169 |
||
170 |
||
113 | 171 |
simple (default position is 0@0): |
593 | 172 |
[exBegin] |
173 |
|top l| |
|
63 | 174 |
|
593 | 175 |
top := StandardSystemView new. |
176 |
top extent:(200 @ 200). |
|
63 | 177 |
|
593 | 178 |
l := Label in:top. |
179 |
l label:'hello world'. |
|
63 | 180 |
|
593 | 181 |
top open |
182 |
[exEnd] |
|
6177 | 183 |
[exBegin] |
184 |
|top l| |
|
185 |
||
186 |
top := StandardSystemView new. |
|
187 |
top extent:(200 @ 200). |
|
188 |
||
189 |
l := Label in:top. |
|
190 |
l label:'hello\world' withCRs. |
|
191 |
||
192 |
top open |
|
193 |
[exEnd] |
|
63 | 194 |
|
113 | 195 |
|
626 | 196 |
simple with emphasis: |
197 |
[exBegin] |
|
198 |
|top l| |
|
199 |
||
200 |
top := StandardSystemView new. |
|
201 |
top extent:(300 @ 100). |
|
202 |
||
203 |
l := Label in:top. |
|
204 |
l level:-1. |
|
205 |
l label:('hello world - this is text in a label ' asText |
|
206 |
emphasizeFrom:7 to:11 with:#italic; |
|
207 |
emphasizeFrom:23 to:26 with:#bold). |
|
208 |
top open |
|
209 |
[exEnd] |
|
210 |
||
211 |
||
113 | 212 |
there is also a creation message which sets the label: |
593 | 213 |
[exBegin] |
214 |
|top l| |
|
113 | 215 |
|
593 | 216 |
top := StandardSystemView new. |
217 |
top extent:(200 @ 200). |
|
113 | 218 |
|
593 | 219 |
l := Label label:'hello world' in:top. |
113 | 220 |
|
593 | 221 |
top open |
222 |
[exEnd] |
|
113 | 223 |
|
224 |
||
63 | 225 |
placement: |
593 | 226 |
[exBegin] |
227 |
|top l| |
|
63 | 228 |
|
593 | 229 |
top := StandardSystemView new. |
230 |
top extent:(200 @ 200). |
|
63 | 231 |
|
593 | 232 |
l := Label in:top. |
233 |
l label:'hello world'. |
|
234 |
l origin:50@100. |
|
63 | 235 |
|
593 | 236 |
top open |
237 |
[exEnd] |
|
63 | 238 |
|
113 | 239 |
|
63 | 240 |
level: |
593 | 241 |
[exBegin] |
242 |
|top l| |
|
63 | 243 |
|
593 | 244 |
top := StandardSystemView new. |
245 |
top extent:(200 @ 200). |
|
63 | 246 |
|
593 | 247 |
l := Label in:top. |
248 |
l level:5. |
|
249 |
l label:'hello world'. |
|
250 |
l origin:50@100. |
|
63 | 251 |
|
593 | 252 |
top open |
253 |
[exEnd] |
|
63 | 254 |
|
113 | 255 |
|
63 | 256 |
another level: |
593 | 257 |
[exBegin] |
258 |
|top l| |
|
63 | 259 |
|
593 | 260 |
top := StandardSystemView new. |
261 |
top extent:(200 @ 200). |
|
63 | 262 |
|
593 | 263 |
l := Label in:top. |
264 |
l level:-1. |
|
265 |
l label:'hello world'. |
|
266 |
l origin:50@100. |
|
63 | 267 |
|
593 | 268 |
top open |
269 |
[exEnd] |
|
63 | 270 |
|
113 | 271 |
|
118 | 272 |
colors & font: |
593 | 273 |
[exBegin] |
274 |
|top l| |
|
118 | 275 |
|
593 | 276 |
top := StandardSystemView new. |
277 |
top extent:(200 @ 200). |
|
118 | 278 |
|
593 | 279 |
l := Label in:top. |
280 |
l level:-1. |
|
281 |
l font:(Font family:'Times' size:18). |
|
282 |
l foregroundColor:Color yellow. |
|
283 |
l backgroundColor:Color red. |
|
284 |
l label:'hello world'. |
|
285 |
l origin:50@100. |
|
118 | 286 |
|
593 | 287 |
top open |
288 |
[exEnd] |
|
118 | 289 |
|
290 |
||
63 | 291 |
border & colors: |
593 | 292 |
[exBegin] |
293 |
|top l| |
|
63 | 294 |
|
593 | 295 |
top := StandardSystemView new. |
296 |
top extent:(200 @ 200). |
|
63 | 297 |
|
593 | 298 |
l := Label in:top. |
299 |
l level:0. |
|
300 |
l borderWidth:1. |
|
301 |
l borderColor:Color red. |
|
302 |
l foregroundColor:Color green darkened. |
|
303 |
l backgroundColor:Color green lightened. |
|
304 |
l label:'hello world'. |
|
305 |
l origin:50@100. |
|
63 | 306 |
|
593 | 307 |
top open |
308 |
[exEnd] |
|
63 | 309 |
|
113 | 310 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
311 |
different adjusts (resize to see): |
593 | 312 |
[exBegin] |
313 |
|top l| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
314 |
|
593 | 315 |
top := StandardSystemView new. |
316 |
top extent:(300 @ 250). |
|
317 |
top label:'make me smaller'. |
|
318 |
||
319 |
l := Label in:top. |
|
320 |
l borderWidth:1. |
|
321 |
l label:'default - #centered'. |
|
322 |
l origin:0.1@40. |
|
323 |
l width:0.8. |
|
63 | 324 |
|
593 | 325 |
l := Label in:top. |
326 |
l borderWidth:1. |
|
327 |
l adjust:#left. |
|
328 |
l label:'#left adjust'. |
|
329 |
l origin:0.1@70. |
|
330 |
l width:0.8. |
|
63 | 331 |
|
593 | 332 |
l := Label in:top. |
333 |
l borderWidth:1. |
|
334 |
l adjust:#right. |
|
335 |
l label:'#right adjust'. |
|
336 |
l origin:0.1@100. |
|
337 |
l width:0.8. |
|
118 | 338 |
|
593 | 339 |
l := Label in:top. |
340 |
l borderWidth:1. |
|
341 |
l adjust:#centerLeft. |
|
342 |
l label:'#centerLeft adjust with a long text'. |
|
343 |
l origin:0.1@130. |
|
344 |
l width:0.8. |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
345 |
|
593 | 346 |
l := Label in:top. |
347 |
l borderWidth:1. |
|
348 |
l adjust:#centerRight. |
|
349 |
l label:'#centerRight adjust with a long text'. |
|
350 |
l origin:0.1@160. |
|
351 |
l width:0.8. |
|
63 | 352 |
|
593 | 353 |
l := Label in:top. |
354 |
l borderWidth:1. |
|
355 |
l adjust:#leftRight. |
|
356 |
l label:'#leftRight adjust with a long text'. |
|
357 |
l origin:0.1@190. |
|
358 |
l width:0.8. |
|
63 | 359 |
|
593 | 360 |
l := Label in:top. |
361 |
l borderWidth:1. |
|
362 |
l adjust:#rightLeft. |
|
363 |
l label:'#rightLeft adjust with a long text'. |
|
364 |
l origin:0.1@220. |
|
365 |
l width:0.8. |
|
118 | 366 |
|
593 | 367 |
top open |
368 |
[exEnd] |
|
63 | 369 |
|
113 | 370 |
|
1945 | 371 |
center vs. centerEach adjust (only with multiline labels): |
372 |
[exBegin] |
|
373 |
|top l| |
|
374 |
||
375 |
top := StandardSystemView new. |
|
376 |
top extent:(300 @ 250). |
|
377 |
top label:'resize me'. |
|
378 |
||
379 |
l := Label in:top. |
|
380 |
l borderWidth:1. |
|
381 |
l label:'this labels logo |
|
1946 | 382 |
consists of multiple lines |
383 |
with #center adjust'. |
|
1945 | 384 |
l origin:0.1@0.1. |
385 |
l corner:0.9@0.9. |
|
386 |
l adjust:#center. |
|
387 |
||
388 |
top open. |
|
389 |
||
390 |
top := StandardSystemView new. |
|
391 |
top extent:(300 @ 250). |
|
392 |
top label:'resize me'. |
|
393 |
||
394 |
l := Label in:top. |
|
395 |
l borderWidth:1. |
|
396 |
l label:'this labels logo |
|
1946 | 397 |
consists of multiple lines |
398 |
with #centerEach adjust'. |
|
1945 | 399 |
l origin:0.1@0.1. |
400 |
l corner:0.9@0.9. |
|
401 |
l adjust:#centerEach. |
|
402 |
||
403 |
top open |
|
404 |
||
405 |
[exEnd] |
|
406 |
||
131 | 407 |
fitting-adjust (resize to see): |
408 |
Warning: #fit is experimental and should not be used. |
|
593 | 409 |
[exBegin] |
410 |
|top l| |
|
131 | 411 |
|
593 | 412 |
top := StandardSystemView new. |
413 |
top extent:(200 @ 200). |
|
131 | 414 |
|
593 | 415 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
416 |
l label:'stretch'. |
|
417 |
l level:-1. |
|
418 |
l adjust:#fit. |
|
131 | 419 |
|
593 | 420 |
top open |
421 |
[exEnd] |
|
131 | 422 |
|
423 |
or: |
|
424 |
Warning: #fit is experimental and should not be used. |
|
593 | 425 |
[exBegin] |
426 |
|top l| |
|
131 | 427 |
|
593 | 428 |
top := StandardSystemView new. |
429 |
top extent:(200 @ 200). |
|
131 | 430 |
|
593 | 431 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
432 |
l label:(Image fromFile:'bitmaps/SBrowser.xbm'). |
|
433 |
l level:-1. |
|
434 |
l adjust:#fit. |
|
131 | 435 |
|
593 | 436 |
top open |
437 |
[exEnd] |
|
131 | 438 |
|
439 |
||
63 | 440 |
just a reminder, that instead of doing placement manually |
113 | 441 |
as in ...: |
593 | 442 |
[exBegin] |
443 |
|top l| |
|
63 | 444 |
|
593 | 445 |
top := StandardSystemView new. |
446 |
top extent:(200 @ 200). |
|
63 | 447 |
|
593 | 448 |
l := Label in:top. |
449 |
l borderWidth:1. |
|
450 |
l label:'default - centered'. |
|
451 |
l origin:0.1@70. |
|
452 |
l width:0.8. |
|
63 | 453 |
|
593 | 454 |
l := Label in:top. |
455 |
l borderWidth:1. |
|
456 |
l adjust:#left. |
|
457 |
l label:'left adjust'. |
|
458 |
l origin:0.1@100. |
|
459 |
l width:0.8. |
|
63 | 460 |
|
593 | 461 |
l := Label in:top. |
462 |
l borderWidth:1. |
|
463 |
l adjust:#right. |
|
464 |
l label:'right adjust'. |
|
465 |
l origin:0.1@130. |
|
466 |
l width:0.8. |
|
63 | 467 |
|
593 | 468 |
top open |
469 |
[exEnd] |
|
63 | 470 |
|
113 | 471 |
|
472 |
... it is much easier, to use a geometry handler, such as |
|
63 | 473 |
a VerticalPanel. Try: |
593 | 474 |
[exBegin] |
475 |
|top panel l| |
|
63 | 476 |
|
593 | 477 |
top := StandardSystemView new. |
478 |
top extent:(200 @ 200). |
|
63 | 479 |
|
593 | 480 |
panel := VerticalPanelView |
481 |
origin:0.1 @ 0.0 |
|
482 |
corner:0.9 @ 1.0 |
|
483 |
in:top. |
|
63 | 484 |
|
593 | 485 |
panel horizontalLayout:#fit. |
486 |
panel verticalLayout:#center. |
|
63 | 487 |
|
593 | 488 |
l := Label in:panel. |
489 |
l borderWidth:1. |
|
490 |
l label:'default - centered'. |
|
63 | 491 |
|
593 | 492 |
l := Label in:panel. |
493 |
l borderWidth:1. |
|
494 |
l adjust:#left. |
|
495 |
l label:'left adjust'. |
|
63 | 496 |
|
593 | 497 |
l := Label in:panel. |
498 |
l borderWidth:1. |
|
499 |
l adjust:#right. |
|
500 |
l label:'right adjust'. |
|
63 | 501 |
|
593 | 502 |
top open |
503 |
[exEnd] |
|
63 | 504 |
|
113 | 505 |
|
63 | 506 |
labels with bitmaps or images: |
593 | 507 |
[exBegin] |
508 |
|top l| |
|
63 | 509 |
|
593 | 510 |
top := StandardSystemView new. |
511 |
top extent:(200 @ 200). |
|
63 | 512 |
|
593 | 513 |
l := Label in:top. |
514 |
l level:-1. |
|
5855 | 515 |
l label:((Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') magnifiedBy:0.2 @ 0.2). |
593 | 516 |
l origin:50@100. |
63 | 517 |
|
593 | 518 |
top open |
519 |
[exEnd] |
|
113 | 520 |
|
521 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
522 |
that even works with #fit: |
593 | 523 |
[exBegin] |
524 |
|top l| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
525 |
|
593 | 526 |
top := StandardSystemView new. |
527 |
top extent:(200 @ 200). |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
528 |
|
593 | 529 |
l := Label in:top. |
530 |
l adjust:#fit. |
|
531 |
l level:-1. |
|
5855 | 532 |
l label:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
593 | 533 |
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
|
534 |
|
593 | 535 |
top open |
536 |
[exEnd] |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
537 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
538 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
539 |
notice, that Buttons inherit from Label; thus: |
593 | 540 |
[exBegin] |
541 |
|top b| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
542 |
|
593 | 543 |
top := StandardSystemView new. |
544 |
top extent:(200 @ 200). |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
545 |
|
593 | 546 |
b := Button in:top. |
547 |
b adjust:#fit. |
|
5855 | 548 |
b label:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
593 | 549 |
b origin:0.2@0.2 corner:0.8@0.8. |
655 | 550 |
b action:[Transcript showCR:'wow']. |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
551 |
|
593 | 552 |
top open |
553 |
[exEnd] |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
554 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
555 |
|
1374 | 556 |
Channel operation (controlling fg, bg and labelText via ValueHolders) |
145 | 557 |
----------------- |
593 | 558 |
[exBegin] |
559 |
|top panel logoChannel fgChannel bgChannel l b| |
|
145 | 560 |
|
593 | 561 |
top := StandardSystemView new. |
562 |
top extent:(450 @ 200). |
|
145 | 563 |
|
593 | 564 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
145 | 565 |
|
593 | 566 |
l := Label in:panel. |
567 |
l level:-1. |
|
568 |
l label:'change my colors'. |
|
569 |
l origin:50@100. |
|
570 |
l sizeFixed:true. |
|
145 | 571 |
|
593 | 572 |
fgChannel := Color blue asValue. |
573 |
bgChannel := Color grey asValue. |
|
574 |
logoChannel := 'change me' asValue. |
|
145 | 575 |
|
593 | 576 |
b := Toggle label:'change fg' in:panel. b showLamp:false; onLevel:-2. |
577 |
b pressAction:[fgChannel value:Color red]. |
|
578 |
b releaseAction:[fgChannel value:Color blue]. |
|
145 | 579 |
|
593 | 580 |
b := Toggle label:'change bg' in:panel. |
581 |
b pressAction:[bgChannel value:Color yellow]. |
|
582 |
b releaseAction:[bgChannel value:Color grey]. |
|
145 | 583 |
|
593 | 584 |
b := Toggle label:'change text' in:panel. |
585 |
b pressAction:[logoChannel value:'wow']. |
|
586 |
b releaseAction:[logoChannel value:'not bad' ]. |
|
145 | 587 |
|
593 | 588 |
l labelChannel:logoChannel. |
589 |
l foregroundChannel:fgChannel. |
|
590 |
l backgroundChannel:bgChannel. |
|
145 | 591 |
|
593 | 592 |
top open |
593 |
[exEnd] |
|
145 | 594 |
|
595 |
||
146 | 596 |
multiple labels on one channel: |
593 | 597 |
[exBegin] |
598 |
|l1 l2 b conv| |
|
146 | 599 |
|
593 | 600 |
l1 := Label label:'label1'. |
146 | 601 |
|
593 | 602 |
l2 := Label label:'label2'. |
146 | 603 |
|
593 | 604 |
b := Button label:'change'. |
605 |
conv := (ConvertedValue new |
|
606 |
conversion:[:input | |
|
607 |
input ifTrue:[ |
|
608 |
Color red |
|
609 |
] ifFalse:[ |
|
610 |
Color blue |
|
611 |
]]). |
|
612 |
conv value:false. |
|
146 | 613 |
|
593 | 614 |
b controller pressChannel:conv. |
615 |
l1 foregroundChannel:conv. |
|
616 |
l2 foregroundColor:Color white; backgroundChannel:conv. |
|
146 | 617 |
|
593 | 618 |
b open. |
619 |
l1 open. |
|
620 |
l2 open. |
|
621 |
[exEnd] |
|
146 | 622 |
|
623 |
||
125 | 624 |
MVC operation |
145 | 625 |
------------- |
626 |
||
125 | 627 |
model provides the label): |
628 |
(have to use a plug to simulate a model which responds to |
|
593 | 629 |
the #someAspect message): |
630 |
|top l model| |
|
113 | 631 |
|
593 | 632 |
model := Plug new. |
633 |
model respondTo:#someAspect with:['models labelString']. |
|
113 | 634 |
|
593 | 635 |
top := StandardSystemView new. |
636 |
top extent:(200 @ 200). |
|
113 | 637 |
|
593 | 638 |
l := Label in:top. |
639 |
l model:model; labelMessage:#someAspect. |
|
113 | 640 |
|
593 | 641 |
top open |
642 |
... |
|
118 | 643 |
|
593 | 644 |
model changed:#someAspect |
645 |
... |
|
113 | 646 |
|
647 |
||
118 | 648 |
concrete example (track a counters value): |
125 | 649 |
(here, the default aspect #value is used both to notify the label about |
5782 | 650 |
changes and to acquire a new value from the model). |
593 | 651 |
[exBegin] |
652 |
|top l model| |
|
113 | 653 |
|
593 | 654 |
model := ValueHolder new. |
655 |
model value:'0'. |
|
656 |
[ |
|
657 |
1 to:20 do:[:i | |
|
658 |
(Delay forSeconds:1) wait. |
|
659 |
model value:i printString |
|
660 |
]. |
|
661 |
top destroy |
|
662 |
] fork. |
|
113 | 663 |
|
593 | 664 |
top := StandardSystemView new. |
665 |
top extent:(200 @ 200). |
|
113 | 666 |
|
593 | 667 |
l := Label in:top. |
668 |
l level:-1. |
|
669 |
l model:model; labelMessage:#value. |
|
118 | 670 |
|
593 | 671 |
top open |
672 |
[exEnd] |
|
118 | 673 |
|
674 |
||
133 | 675 |
with a printConverter: |
593 | 676 |
[exBegin] |
677 |
|top l model| |
|
133 | 678 |
|
593 | 679 |
model := Date today asValue. |
680 |
[ |
|
681 |
1 to:50 do:[:i | |
|
682 |
(Delay forSeconds:1) wait. |
|
683 |
model value:(model value addDays:1) |
|
684 |
]. |
|
685 |
top destroy |
|
686 |
] fork. |
|
133 | 687 |
|
593 | 688 |
top := StandardSystemView new. |
689 |
top extent:(200 @ 200). |
|
133 | 690 |
|
593 | 691 |
l := Label in:top. |
692 |
l level:-1. |
|
693 |
l converter:(PrintConverter new initForDate). |
|
694 |
l model:model; labelMessage:#value. |
|
133 | 695 |
|
593 | 696 |
top open |
697 |
[exEnd] |
|
133 | 698 |
|
699 |
||
125 | 700 |
model changes aspect after a while; two labels on the same model: |
593 | 701 |
[exBegin] |
702 |
|top l model| |
|
118 | 703 |
|
593 | 704 |
model := Plug new. |
705 |
model respondTo:#labelValue1 with:['models labelString1']. |
|
706 |
model respondTo:#labelValue2 with:['models labelString2']. |
|
118 | 707 |
|
593 | 708 |
top := StandardSystemView new. |
709 |
top extent:(200 @ 200). |
|
118 | 710 |
|
593 | 711 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
712 |
l model:model; aspect:#someAspect; labelMessage:#labelValue1. |
|
713 |
l := Label origin:0.0@0.5 corner:1.0@1.0 in:top. |
|
714 |
l model:model; aspect:#someAspect; labelMessage:#labelValue2. |
|
715 |
||
716 |
top open. |
|
113 | 717 |
|
593 | 718 |
(Delay forSeconds:5) wait. |
719 |
model respondTo:#labelValue1 with:['new string1']. |
|
720 |
model respondTo:#labelValue2 with:['new string2']. |
|
118 | 721 |
|
593 | 722 |
model changed:#someAspect |
723 |
[exEnd] |
|
118 | 724 |
|
725 |
||
125 | 726 |
plugged MVC operation (getBlock returns the label): |
593 | 727 |
[exBegin] |
728 |
|top l model| |
|
118 | 729 |
|
593 | 730 |
model := PluggableAdaptor new |
731 |
getBlock:[:m | 'hello'] |
|
732 |
putBlock:nil |
|
733 |
updateBlock:nil. |
|
118 | 734 |
|
593 | 735 |
top := StandardSystemView new. |
736 |
top extent:(200 @ 200). |
|
118 | 737 |
|
593 | 738 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
739 |
l model:model; labelMessage:#value. |
|
118 | 740 |
|
593 | 741 |
top open. |
742 |
[exEnd] |
|
125 | 743 |
|
744 |
||
745 |
use different label-selectors to access fields of a complex model: |
|
593 | 746 |
[exBegin] |
747 |
|top panel model| |
|
125 | 748 |
|
593 | 749 |
model := Plug new. |
750 |
model respondTo:#field1 with:['value1']. |
|
751 |
model respondTo:#field2 with:['value2']. |
|
752 |
model respondTo:#field3 with:['value3']. |
|
753 |
model respondTo:#field4 with:['value4']. |
|
125 | 754 |
|
593 | 755 |
top := StandardSystemView new. |
756 |
||
757 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
758 |
panel elementsChangeSize:true. |
|
125 | 759 |
|
593 | 760 |
panel addSubView:((Label on:model) labelMessage:#field1). |
761 |
panel addSubView:((Label on:model) labelMessage:#field2). |
|
762 |
panel addSubView:((Label on:model) labelMessage:#field3). |
|
763 |
panel addSubView:((Label on:model) labelMessage:#field4). |
|
125 | 764 |
|
593 | 765 |
top extent:(200 @ 200). |
766 |
top open. |
|
125 | 767 |
|
593 | 768 |
(Delay forSeconds:5) wait. |
125 | 769 |
|
593 | 770 |
model respondTo:#field2 with:['new value2']. |
771 |
model changed:#value |
|
772 |
[exEnd] |
|
125 | 773 |
|
774 |
||
775 |
same as above, using default aspects in the label, and an adaptor |
|
776 |
to translate aspects: |
|
593 | 777 |
[exBegin] |
778 |
|top panel model v1| |
|
125 | 779 |
|
593 | 780 |
model := Plug new. |
781 |
model respondTo:#field1 with:[v1]. |
|
782 |
model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1]. |
|
783 |
model respondTo:#field2 with:['value2']. |
|
784 |
model respondTo:#field2: with:[:arg |]. |
|
785 |
model respondTo:#field3 with:['value3']. |
|
786 |
model respondTo:#field3: with:[:arg |]. |
|
787 |
model respondTo:#field4 with:['value4']. |
|
788 |
model respondTo:#field4: with:[:arg |]. |
|
125 | 789 |
|
593 | 790 |
top := StandardSystemView new. |
125 | 791 |
|
593 | 792 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
793 |
panel elementsChangeSize:true. |
|
794 |
||
795 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value). |
|
796 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value). |
|
797 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value). |
|
798 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value). |
|
125 | 799 |
|
593 | 800 |
top extent:(200 @ 200). |
801 |
top open. |
|
125 | 802 |
|
593 | 803 |
(Delay forSeconds:5) wait. |
125 | 804 |
|
593 | 805 |
model field1:'new value1'. |
806 |
[exEnd] |
|
125 | 807 |
|
808 |
||
809 |
use an adapter to access fields of a complex model: |
|
593 | 810 |
[exBegin] |
811 |
|top l panel model| |
|
125 | 812 |
|
593 | 813 |
model := #('one' 'two' 'three') asValue. |
125 | 814 |
|
593 | 815 |
top := StandardSystemView new. |
125 | 816 |
|
593 | 817 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
818 |
panel elementsChangeSize:true. |
|
125 | 819 |
|
593 | 820 |
panel addSubView:((Label on:(ProtocolAdaptor |
821 |
subjectChannel:model |
|
822 |
accessPath:#(1))) labelMessage:#value). |
|
823 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
824 |
subjectChannel:model |
|
825 |
accessPath:#(2))) labelMessage:#value). |
|
826 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
827 |
subjectChannel:model |
|
828 |
accessPath:#(3))) labelMessage:#value). |
|
125 | 829 |
|
593 | 830 |
top extent:(200 @ 200). |
831 |
top open. |
|
125 | 832 |
|
593 | 833 |
(Delay forSeconds:5) wait. |
125 | 834 |
|
593 | 835 |
model value:#('oneone' 'twotwo' 'threethree'). |
836 |
[exEnd] |
|
63 | 837 |
" |
3 | 838 |
! ! |
839 |
||
935 | 840 |
!Label class methodsFor:'instance creation'! |
105 | 841 |
|
842 |
form:aForm |
|
118 | 843 |
"return a new Label showing a form. |
844 |
OBSOLETE: you should now use #label: for both text and bitmap labels." |
|
105 | 845 |
|
2366 | 846 |
<resource:#obsolete> |
847 |
||
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
848 |
self obsoleteMethodWarning:'use #label:'. |
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
849 |
^ (self onDevice:Screen current) label:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
850 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
851 |
"Modified: 16.6.1997 / 11:47:38 / cg" |
105 | 852 |
! |
853 |
||
854 |
form:aForm in:aView |
|
118 | 855 |
"return a new Label showing a form. |
856 |
OBSOLETE: you should now use #label:in: for both text and bitmap labels." |
|
105 | 857 |
|
2366 | 858 |
<resource:#obsolete> |
859 |
||
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
860 |
self obsoleteMethodWarning:'use #label:in:'. |
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
861 |
^ (self in:aView) label:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
862 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
863 |
"Modified: 16.6.1997 / 11:47:57 / cg" |
105 | 864 |
! ! |
865 |
||
935 | 866 |
!Label class methodsFor:'defaults'! |
0 | 867 |
|
868 |
defaultExtent |
|
571 | 869 |
"return the default extent of my instances. |
870 |
The value returned here is usually ignored, and |
|
871 |
the value from preferredExtent taken instead." |
|
0 | 872 |
|
873 |
^ 16 @ 16 |
|
571 | 874 |
|
875 |
"Modified: 22.4.1996 / 23:36:11 / cg" |
|
59 | 876 |
! |
877 |
||
2098
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
878 |
defaultForegroundColor |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
879 |
"return the default foregroundColor of my instances." |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
880 |
|
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
881 |
^ DefaultForegroundColor |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
882 |
|
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
883 |
! |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
884 |
|
59 | 885 |
updateStyleCache |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
886 |
"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
|
887 |
|
1356 | 888 |
<resource: #style (#'label.foregroundColor' #'label.backgroundColor' |
442 | 889 |
#foregroundColor #backgroundColor |
1356 | 890 |
#'label.font')> |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
891 |
|
1872 | 892 |
DefaultForegroundColor := StyleSheet colorAt:#'label.foregroundColor'. |
77 | 893 |
DefaultForegroundColor isNil ifTrue:[ |
1374 | 894 |
"/ fallBack: comon value |
4915 | 895 |
DefaultForegroundColor := StyleSheet colorAt:#'foregroundColor' default:Color black. |
77 | 896 |
]. |
1872 | 897 |
DefaultBackgroundColor := StyleSheet colorAt:#'label.backgroundColor'. |
77 | 898 |
DefaultBackgroundColor isNil ifTrue:[ |
1374 | 899 |
"/ fallBack: comon value |
1872 | 900 |
DefaultBackgroundColor := StyleSheet colorAt:#'backgroundColor'. |
77 | 901 |
]. |
1872 | 902 |
DefaultFont := StyleSheet fontAt:#'label.font'. |
60 | 903 |
|
904 |
" |
|
905 |
self updateStyleCache |
|
906 |
" |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
907 |
|
1374 | 908 |
"Modified: / 31.10.1997 / 14:53:48 / cg" |
0 | 909 |
! ! |
910 |
||
4670 | 911 |
!Label class methodsFor:'menu specs'! |
912 |
||
913 |
middleButtonMenu |
|
914 |
"This resource specification was automatically generated |
|
915 |
by the MenuEditor of ST/X." |
|
916 |
||
917 |
"Do not manually edit this!! If it is corrupted, |
|
918 |
the MenuEditor may not be able to read the specification." |
|
919 |
||
920 |
||
921 |
" |
|
922 |
MenuEditor new openOnClass:Label andSelector:#middleButtonMenu |
|
923 |
(Menu new fromLiteralArrayEncoding:(Label middleButtonMenu)) startUp |
|
924 |
" |
|
925 |
||
926 |
<resource: #menu> |
|
927 |
||
928 |
^ |
|
929 |
#(Menu |
|
930 |
( |
|
931 |
(MenuItem |
|
932 |
label: 'Copy Label Text' |
|
933 |
itemValue: copyLabelText |
|
6455 | 934 |
enabled: canCopyLabelText |
4670 | 935 |
) |
936 |
) |
|
937 |
nil |
|
938 |
nil |
|
939 |
) |
|
940 |
! ! |
|
941 |
||
202 | 942 |
!Label methodsFor:'accessing-channels'! |
105 | 943 |
|
260 | 944 |
labelChannel |
1374 | 945 |
"return the labelChannel - or nil" |
946 |
||
260 | 947 |
^ labelChannel. |
948 |
||
1374 | 949 |
"Created: / 16.12.1995 / 15:50:18 / cg" |
950 |
"Modified: / 31.10.1997 / 14:43:14 / cg" |
|
260 | 951 |
! |
952 |
||
145 | 953 |
labelChannel:aValueHolder |
1374 | 954 |
"set the labelChannel - a valueHolder holding a string or image |
955 |
which is shown as my logo" |
|
956 |
||
146 | 957 |
|prev| |
958 |
||
959 |
prev := labelChannel. |
|
145 | 960 |
labelChannel := aValueHolder. |
3927 | 961 |
self setupChannel:aValueHolder for:nil withOld:prev. |
962 |
self getLabelFromLabelChannel. |
|
1374 | 963 |
|
964 |
"Modified: / 31.10.1997 / 14:37:02 / cg" |
|
145 | 965 |
! ! |
966 |
||
6238 | 967 |
!Label methodsFor:'accessing-color & font'! |
125 | 968 |
|
202 | 969 |
backgroundColor |
970 |
"return the background color" |
|
125 | 971 |
|
202 | 972 |
^ bgColor |
125 | 973 |
! |
974 |
||
202 | 975 |
backgroundColor:aColor |
976 |
"set the background color" |
|
125 | 977 |
|
263 | 978 |
aColor ~~ bgColor ifTrue:[ |
3582 | 979 |
bgColor := aColor. |
980 |
bgColor notNil ifTrue:[ |
|
5633 | 981 |
bgColor := bgColor onDevice:device. |
3597 | 982 |
self class == Label ifTrue:[ |
983 |
super viewBackground:bgColor |
|
984 |
]. |
|
1218 | 985 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
986 |
self invalidateRepairNow:true |
263 | 987 |
] |
988 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
989 |
"Modified: / 15.1.1998 / 00:14:10 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
990 |
"Modified: / 6.6.1998 / 20:01:56 / cg" |
105 | 991 |
! |
992 |
||
2496 | 993 |
etchedForegroundColor |
994 |
"return the etched foreground color (or nil)" |
|
995 |
||
996 |
^ etchedFgColor |
|
997 |
! |
|
998 |
||
999 |
etchedForegroundColor:aColor |
|
1000 |
"set the etched foreground color" |
|
1001 |
||
1002 |
aColor ~~ etchedFgColor ifTrue:[ |
|
1003 |
etchedFgColor := aColor. |
|
1004 |
etchedFgColor notNil ifTrue:[ |
|
5633 | 1005 |
etchedFgColor := etchedFgColor onDevice:device. |
2496 | 1006 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1007 |
self invalidateRepairNow:true |
2496 | 1008 |
]. |
1009 |
! |
|
1010 |
||
105 | 1011 |
foregroundColor |
1012 |
"return the foreground color" |
|
1013 |
||
1014 |
^ fgColor |
|
1015 |
! |
|
1016 |
||
202 | 1017 |
foregroundColor:aColor |
1018 |
"set the foreground color" |
|
105 | 1019 |
|
263 | 1020 |
aColor ~~ fgColor ifTrue:[ |
5633 | 1021 |
fgColor := aColor onDevice:device. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1022 |
self invalidateRepairNow:true |
263 | 1023 |
]. |
1024 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1025 |
"Modified: / 15.1.1998 / 00:14:22 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1026 |
"Modified: / 6.6.1998 / 20:02:02 / cg" |
105 | 1027 |
! |
1028 |
||
1029 |
foregroundColor:fg backgroundColor:bg |
|
1030 |
"set the colors to be used for drawing" |
|
1031 |
||
993 | 1032 |
(fgColor ~~ fg or:[bgColor ~~ bg]) ifTrue:[ |
5633 | 1033 |
fgColor := fg onDevice:device. |
1034 |
bgColor := bg onDevice:device. |
|
1218 | 1035 |
self class == Label ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1036 |
super viewBackground:bgColor |
1218 | 1037 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1038 |
self invalidateRepairNow:true |
993 | 1039 |
]. |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1040 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1041 |
"Modified: / 15.1.1998 / 00:14:36 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1042 |
"Modified: / 6.6.1998 / 20:02:07 / cg" |
1218 | 1043 |
! |
1044 |
||
1045 |
viewBackground:aColor |
|
1046 |
"for labels, the viewBackground is forced to be the same as |
|
1047 |
the backgroundColor" |
|
1048 |
||
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1049 |
super viewBackground:aColor. |
1218 | 1050 |
self class == Label ifTrue:[ |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1051 |
self backgroundColor:aColor |
1218 | 1052 |
]. |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1053 |
|
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1054 |
"Modified: / 6.6.1998 / 20:02:22 / cg" |
133 | 1055 |
! ! |
1056 |
||
1057 |
!Label methodsFor:'accessing-contents'! |
|
0 | 1058 |
|
202 | 1059 |
form:aForm |
1060 |
"set the labels form; adjust extent if not already realized. |
|
1061 |
OBSOLETE: you should now use #label: for both strings and images" |
|
118 | 1062 |
|
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1063 |
<resource:#obsolete> |
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1064 |
|
202 | 1065 |
self label:aForm |
1066 |
! |
|
1067 |
||
1068 |
label |
|
1069 |
"return the labels string or image" |
|
1070 |
||
1071 |
^ logo |
|
118 | 1072 |
! |
105 | 1073 |
|
118 | 1074 |
label:aStringOrFormOrImage |
4174 | 1075 |
"set the labelString or image; |
1076 |
adjust extent if not already realized and not fixedSize; |
|
1077 |
also redraw" |
|
1078 |
||
1079 |
self label:aStringOrFormOrImage redraw:true |
|
1080 |
||
1081 |
"Modified: / 13-10-2010 / 12:17:36 / cg" |
|
1082 |
! |
|
1083 |
||
1084 |
label:aStringOrFormOrImage redraw:doRedraw |
|
118 | 1085 |
"set the labelString or image; adjust extent if not already realized and |
1086 |
not fixedSize" |
|
1087 |
||
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1088 |
|newLogo numberOfLines| |
2639 | 1089 |
|
1090 |
newLogo := aStringOrFormOrImage. |
|
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1091 |
newLogo isString ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1092 |
numberOfLines := 1 + (newLogo occurrencesOf:(Character cr)). |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1093 |
(numberOfLines ~~ 1) ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1094 |
newLogo := newLogo asStringCollection |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1095 |
] |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1096 |
] ifFalse:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1097 |
newLogo isStringCollection ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1098 |
numberOfLines := newLogo size. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1099 |
(numberOfLines <= 1) ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1100 |
newLogo := newLogo asString |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1101 |
] |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1102 |
] |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1103 |
]. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1104 |
|
118 | 1105 |
(aStringOrFormOrImage ~~ logo) ifTrue:[ |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1106 |
"/ |
6106 | 1107 |
"/ avoid recompute of size, if it's an image with |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1108 |
"/ the same size |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1109 |
"/ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1110 |
aStringOrFormOrImage isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1111 |
logo notNil ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1112 |
logo isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1113 |
logo extent = aStringOrFormOrImage extent ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1114 |
logo := aStringOrFormOrImage. |
4174 | 1115 |
doRedraw ifTrue:[ self invalidateRepairNow:true ]. |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1116 |
^ self |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1117 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1118 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1119 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1120 |
] ifFalse:[ |
806
a641ed42df70
dont ignore new label setting, if the emphasis changed
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
1121 |
"/ any change ? |
4443
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1122 |
(logo isString |
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1123 |
and:[ newLogo isString |
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1124 |
and:[ newLogo = logo |
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1125 |
and:[ logo emphasis = newLogo emphasis]]]) ifTrue:[ |
3649 | 1126 |
^ self |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1127 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1128 |
]. |
3557
e57daeff04be
changed #label: - fix typo in comment
Stefan Vogel <sv@exept.de>
parents:
3531
diff
changeset
|
1129 |
"/ do not check using #isString here; |
3531 | 1130 |
"/ we allow for non-strings to be used as logo as well (it must understand displayOn:). |
1131 |
newLogo isNumber ifTrue:[ |
|
1132 |
logo := newLogo asString |
|
1133 |
] ifFalse:[ |
|
1134 |
logo := newLogo. |
|
1135 |
]. |
|
4174 | 1136 |
doRedraw ifTrue:[ |
1137 |
self newLayout. |
|
1138 |
self repairDamage |
|
1139 |
]. |
|
105 | 1140 |
] |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1141 |
|
4174 | 1142 |
"Created: / 13-10-2010 / 12:16:34 / cg" |
6106 | 1143 |
"Modified (format): / 13-02-2017 / 20:26:33 / cg" |
105 | 1144 |
! |
0 | 1145 |
|
1367 | 1146 |
label:newLabel suppressResize:suppress |
1147 |
"change the label and optionally suppress a resize operation" |
|
1148 |
||
1149 |
|wasFix| |
|
1150 |
||
1151 |
wasFix := fixSize. |
|
1152 |
suppress ifTrue:[ |
|
1153 |
fixSize := true. |
|
1154 |
]. |
|
1155 |
here label:newLabel. |
|
1156 |
fixSize := wasFix |
|
1157 |
||
1158 |
"Modified: / 29.10.1997 / 15:50:01 / cg" |
|
1159 |
! |
|
1160 |
||
202 | 1161 |
labelString:aString |
1162 |
"for ST-80 compatibility: same as #label: |
|
1163 |
set the label-string; adjust extent if not already realized and not fixedSize" |
|
118 | 1164 |
|
202 | 1165 |
self label:aString |
1166 |
! |
|
1167 |
||
1168 |
labelWidth |
|
1169 |
"return the logos width in pixels" |
|
1170 |
||
1171 |
^ labelWidth |
|
118 | 1172 |
! |
1173 |
||
1174 |
logo:something |
|
1175 |
"set the labels form or string. |
|
1176 |
OBSOLETE: the old version used #form: for images and #label: for strings. |
|
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1177 |
you should now use #label: for any." |
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1178 |
|
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1179 |
<resource:#obsolete> |
118 | 1180 |
|
1181 |
self label:something |
|
133 | 1182 |
! ! |
1183 |
||
1184 |
!Label methodsFor:'accessing-layout'! |
|
1185 |
||
202 | 1186 |
adjust |
1921 | 1187 |
"return the adjust symbol. See #adjust: for an explanation." |
0 | 1188 |
|
202 | 1189 |
^ adjust |
125 | 1190 |
! |
1191 |
||
105 | 1192 |
adjust:how |
1193 |
"set the adjust, how which must be one of |
|
0 | 1194 |
|
105 | 1195 |
#left -> left adjust logo |
1196 |
#right -> right adjust logo |
|
1197 |
#center -> center logo |
|
6106 | 1198 |
#centerEach -> like #center, but if it's a multiline logo, |
1945 | 1199 |
center each line individually. |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1200 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1201 |
#centerRight -> center logo if it fits; |
533 | 1202 |
BUT, if it does not fit, right adjust the logo |
1203 |
(use with filenames, where the interesting part is |
|
1204 |
at the right if the label is too small) |
|
1205 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1206 |
#centerLeft -> center logo if it fits; |
533 | 1207 |
BUT, if it does not fit, left adjust the logo |
1208 |
(use with strings where the interesting part is at the |
|
1209 |
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
|
1210 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1211 |
#leftRight -> left adjust logo if it fits |
533 | 1212 |
BUT, if it does not fit, right adjust the logo |
1213 |
(use with filenames, where the interesting part is |
|
1214 |
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
|
1215 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1216 |
#rightLeft -> right adjust logo if it fits |
533 | 1217 |
BUT, if it does not fit, left adjust the logo |
1218 |
(use with strings where the interesting part is at the |
|
1219 |
left if the label is too small) |
|
1220 |
||
1221 |
See examples in the documentation category. |
|
105 | 1222 |
" |
118 | 1223 |
|
105 | 1224 |
(adjust ~~ how) ifTrue:[ |
533 | 1225 |
adjust := how. |
1226 |
self newLayout |
|
105 | 1227 |
] |
533 | 1228 |
|
6106 | 1229 |
"Modified: / 13-04-1996 / 11:17:58 / cg" |
1230 |
"Modified (comment): / 13-02-2017 / 20:26:28 / cg" |
|
6326 | 1231 |
"Modified (comment): / 24-05-2018 / 11:30:04 / Claus Gittinger" |
105 | 1232 |
! |
1233 |
||
5445 | 1234 |
extraMarginForBorder |
1235 |
"some (round) borders may need more space" |
|
1236 |
||
1237 |
^ 0 |
|
1238 |
! |
|
1239 |
||
202 | 1240 |
font:aFont |
665 | 1241 |
"set the font - if I'm not realized and not fixedSize, adjust my size. |
1242 |
CAVEAT: with the addition of Text objects, |
|
1243 |
this method is going to be obsoleted by a textStyle |
|
1244 |
method, which allows specific control over |
|
1245 |
normalFont/boldFont/italicFont parameters." |
|
125 | 1246 |
|
4891 | 1247 |
(aFont notNil and:[aFont ~~ gc font]) ifTrue:[ |
1248 |
super font:aFont. |
|
416 | 1249 |
self newLayout |
202 | 1250 |
] |
416 | 1251 |
|
665 | 1252 |
"Modified: 22.5.1996 / 12:36:29 / cg" |
133 | 1253 |
! |
1254 |
||
6089 | 1255 |
horizontalSpace |
1256 |
"get the number of pixels by which the logo |
|
1257 |
is horizontally inset from the border" |
|
1258 |
||
1259 |
^ hSpace |
|
1260 |
! |
|
1261 |
||
133 | 1262 |
horizontalSpace:aNumber |
1263 |
"set the number of pixels by which the logo |
|
1264 |
is horizontally inset from the border" |
|
1265 |
||
162 | 1266 |
hSpace := aNumber. |
1267 |
self newLayout |
|
133 | 1268 |
! |
1269 |
||
202 | 1270 |
layout:something |
1271 |
"OBSOLETE compatibility interface. Will vanish. |
|
1272 |
for protocol compatibility: alias for #adjust:. |
|
1273 |
Please use #adjust:, since #layout: conflicts with a method |
|
1274 |
in VW (which has a completely different meaning). |
|
1275 |
In future versions of ST/X, #layout: will behave the VW way. |
|
1276 |
In the meantime, try to figure out what is meant ... a kludge" |
|
1277 |
||
2366 | 1278 |
<resource:#obsolete> |
1279 |
||
3215 | 1280 |
something isSymbol ifFalse:[^ super layout:something]. |
202 | 1281 |
|
1282 |
self obsoleteMethodWarning:'use #adjust:'. |
|
1283 |
self adjust:something |
|
1284 |
||
1285 |
"Modified: 31.8.1995 / 23:08:13 / claus" |
|
1286 |
! |
|
1287 |
||
1288 |
sizeFixed |
|
1289 |
"return the fix-size attribute" |
|
1290 |
||
1291 |
^ fixSize |
|
1292 |
! |
|
1293 |
||
1294 |
sizeFixed:aBoolean |
|
1295 |
"set/clear the fix-size attribute. |
|
5708 | 1296 |
If true, the label will not change its size when the labelString/logo |
1297 |
changes. |
|
1298 |
If false (the default), it will resize itself to make the logo fit." |
|
202 | 1299 |
|
1300 |
fixSize := aBoolean |
|
1301 |
! |
|
1302 |
||
6088 | 1303 |
verticalSpace |
1304 |
"get the number of pixels by which the logo |
|
1305 |
is vertically inset from the border" |
|
1306 |
||
1307 |
^ vSpace |
|
1308 |
! |
|
1309 |
||
202 | 1310 |
verticalSpace:aNumber |
1311 |
"set the number of pixels by which the logo |
|
1312 |
is vertically inset from the border" |
|
1313 |
||
1314 |
vSpace := aNumber. |
|
1315 |
self newLayout |
|
1316 |
! ! |
|
1317 |
||
1318 |
!Label methodsFor:'accessing-mvc'! |
|
1319 |
||
1320 |
addModelInterfaceTo:aDictionary |
|
1321 |
"see comment in View>>modelInterface" |
|
1322 |
||
1323 |
super addModelInterfaceTo:aDictionary. |
|
1324 |
aDictionary at:#labelMessage put:labelMsg |
|
1325 |
! |
|
1326 |
||
1327 |
converter:aConverter |
|
1328 |
"set the printConverter; |
|
1329 |
that one is asked to convert the models value to a printed |
|
1330 |
representation (if non-nil). If nil, the model is supposed to |
|
1331 |
return a string or bitmap image." |
|
1332 |
||
1333 |
converter := aConverter |
|
1334 |
! |
|
105 | 1335 |
|
202 | 1336 |
labelMessage |
5782 | 1337 |
"return the symbol used to acquire the labelString/image from the model |
202 | 1338 |
when the aspect changes. |
1339 |
The default is nil, which means: leave the label unchanged." |
|
1340 |
||
1341 |
^ labelMsg |
|
1342 |
! |
|
1343 |
||
1344 |
labelMessage:aSymbol |
|
5782 | 1345 |
"set the symbol used to acquire the labelString/image from the model. |
202 | 1346 |
The default is nil, which means: leave the label unchanged." |
1347 |
||
1348 |
labelMsg ~~ aSymbol ifTrue:[ |
|
5782 | 1349 |
labelMsg := aSymbol. |
1350 |
self getLabelFromModel |
|
202 | 1351 |
] |
1352 |
! |
|
1353 |
||
1354 |
model:aModel |
|
1355 |
super model:aModel. |
|
1039 | 1356 |
labelMsg notNil ifTrue:[ |
1357 |
self getLabelFromModel. |
|
1358 |
] |
|
202 | 1359 |
! ! |
1360 |
||
1361 |
!Label methodsFor:'change & update'! |
|
1362 |
||
3924 | 1363 |
getLabelFromLabelChannel |
1364 |
self label:(labelChannel value). |
|
1365 |
! |
|
1366 |
||
202 | 1367 |
update:something with:aParameter from:changedObject |
1368 |
"the MVC way of changing the label ..." |
|
1369 |
||
1374 | 1370 |
changedObject notNil ifTrue:[ |
1371 |
changedObject == labelChannel ifTrue:[ |
|
3924 | 1372 |
self getLabelFromLabelChannel. |
1374 | 1373 |
^ self |
1374 |
]. |
|
1375 |
||
1376 |
changedObject == model ifTrue:[ |
|
1377 |
something == aspectMsg ifTrue:[ |
|
1378 |
self getLabelFromModel. |
|
1379 |
^ self. |
|
1380 |
] |
|
1381 |
]. |
|
202 | 1382 |
]. |
1383 |
^ super update:something with:aParameter from:changedObject |
|
1374 | 1384 |
|
1385 |
"Modified: / 31.10.1997 / 14:32:02 / cg" |
|
1828 | 1386 |
"Modified: / 30.3.1999 / 13:57:26 / stefan" |
202 | 1387 |
! ! |
1388 |
||
1389 |
!Label methodsFor:'event handling'! |
|
1390 |
||
1391 |
sizeChanged:how |
|
1392 |
"sent whenever size is changed by someone else - recompute the |
|
1393 |
logos position within the View." |
|
1394 |
||
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1395 |
|prevX prevY| |
202 | 1396 |
|
1397 |
super sizeChanged:how. |
|
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1398 |
|
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1399 |
prevX := labelOriginX. |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1400 |
prevY := labelOriginY. |
1392 | 1401 |
self computeLabelOrigin. |
202 | 1402 |
shown ifTrue:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1403 |
(adjust == #fit |
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1404 |
or:[labelOriginX ~~ prevX |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1405 |
or:[labelOriginY ~~ prevY |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1406 |
or:[how ~~ #smaller]]]) ifTrue:[ |
1509 | 1407 |
"/ self clear. |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1408 |
self invalidate. |
1509 | 1409 |
"/ self redrawEdges |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1410 |
] |
105 | 1411 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1412 |
|
1509 | 1413 |
"Modified: / 28.4.1998 / 17:07:57 / cg" |
0 | 1414 |
! ! |
1415 |
||
1867
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1416 |
!Label methodsFor:'focus handling'! |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1417 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1418 |
wantsFocusWithButtonPress |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1419 |
self class == Label ifTrue:[^ false]. |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1420 |
^ super wantsFocusWithButtonPress |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1421 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1422 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1423 |
! ! |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1424 |
|
6352 | 1425 |
!Label methodsFor:'help'! |
1426 |
||
1427 |
helpText |
|
1428 |
|help| |
|
1429 |
||
1430 |
(help := super helpText) isEmptyOrNil ifTrue:[ |
|
1431 |
"/ if my label is wider, return that as help text |
|
1432 |
logo isString ifTrue:[ |
|
1433 |
(labelWidth ? 0) > (self width + 2) ifTrue:[ |
|
1434 |
help := logo |
|
1435 |
]. |
|
1436 |
]. |
|
1437 |
]. |
|
1438 |
^ help |
|
1439 |
||
1440 |
"Created: / 15-06-2018 / 14:09:31 / Claus Gittinger" |
|
1441 |
! ! |
|
1442 |
||
2751 | 1443 |
!Label methodsFor:'initialization & release'! |
0 | 1444 |
|
935 | 1445 |
fetchDeviceResources |
1446 |
"fetch device colors, to avoid reallocation at redraw time" |
|
1447 |
||
1448 |
super fetchDeviceResources. |
|
1449 |
||
5633 | 1450 |
fgColor := fgColor onDevice:device. |
1451 |
bgColor := bgColor onDevice:device. |
|
935 | 1452 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1453 |
"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
|
1454 |
"Modified: / 15.1.1998 / 00:13:46 / stefan" |
935 | 1455 |
! |
1456 |
||
0 | 1457 |
initStyle |
967 | 1458 |
"setup viewStyle specifics" |
1459 |
||
0 | 1460 |
super initStyle. |
1461 |
||
59 | 1462 |
DefaultBackgroundColor notNil ifTrue:[ |
935 | 1463 |
bgColor := DefaultBackgroundColor |
38 | 1464 |
] ifFalse:[ |
935 | 1465 |
bgColor := viewBackground. |
59 | 1466 |
]. |
1467 |
DefaultForegroundColor notNil ifTrue:[ |
|
935 | 1468 |
fgColor := DefaultForegroundColor |
59 | 1469 |
] ifFalse:[ |
4915 | 1470 |
fgColor := self blackColor. |
1374 | 1471 |
]. |
1472 |
self class == Label ifTrue:[ |
|
4020
3b0d7d8915a8
no more direct accesses to borderWidth and borderColor
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
1473 |
self borderWidth:0. |
38 | 1474 |
] |
935 | 1475 |
|
4318 | 1476 |
"Modified: / 31-10-1997 / 14:57:23 / cg" |
1477 |
"Modified (comment): / 05-10-2011 / 15:51:09 / az" |
|
0 | 1478 |
! |
1479 |
||
105 | 1480 |
initialize |
4891 | 1481 |
|currentFont| |
1482 |
||
6077 | 1483 |
<modifier: #super> "must be called if redefined" |
1484 |
||
105 | 1485 |
super initialize. |
1486 |
||
5817 | 1487 |
currentFont := gc font. |
4891 | 1488 |
self initialHeight:(currentFont height + currentFont descent). |
105 | 1489 |
adjust := #center. |
118 | 1490 |
labelOriginX := labelOriginY := 0. |
1491 |
labelWidth := labelHeight := 0. |
|
105 | 1492 |
logo := nil. |
1493 |
fixSize := false. |
|
5943 | 1494 |
hSpace := ((self horizontalPixelPerMillimeter:0.5) max:2) rounded. |
1495 |
vSpace := ((self verticalPixelPerMillimeter:0.5) max:2) rounded |
|
6077 | 1496 |
|
1497 |
"Modified: / 08-02-2017 / 00:32:40 / cg" |
|
105 | 1498 |
! |
1499 |
||
0 | 1500 |
recreate |
2258 | 1501 |
"after snapin or a migration, labels dimensions may have changed due to |
0 | 1502 |
different font parameters" |
1503 |
||
1504 |
super recreate. |
|
1505 |
self computeLabelSize. |
|
1506 |
self computeLabelOrigin |
|
2592 | 1507 |
! |
1508 |
||
1509 |
release |
|
1510 |
labelChannel notNil ifTrue:[ |
|
1511 |
labelChannel removeDependent:self. |
|
1512 |
labelChannel := nil. |
|
1513 |
]. |
|
5746 | 1514 |
self stopAnimation. |
2592 | 1515 |
super release |
0 | 1516 |
! ! |
1517 |
||
5746 | 1518 |
!Label methodsFor:'label animation'! |
1519 |
||
1520 |
animationDelay |
|
1521 |
^ 100 milliseconds |
|
1522 |
! |
|
1523 |
||
1524 |
animationDelayTopOrBottom |
|
1525 |
^ 3 seconds |
|
1526 |
! |
|
1527 |
||
1528 |
doAnimate |
|
1529 |
"by slow scrolling the label, ensure that the label's text is readable. |
|
1530 |
(stops when the cursor enters)" |
|
1531 |
||
5751 | 1532 |
|animatorState offset atTop atBottom nextOffset nextMoveDirection nextAnimationDelay focusView| |
5746 | 1533 |
|
5751 | 1534 |
animatorState := self objectAttributeAt:#animator. |
1535 |
animatorState isNil ifTrue:[^ self "I have been stopped in the meanwhile"]. |
|
5746 | 1536 |
|
5785 | 1537 |
(gc drawableId isNil) ifTrue:[ |
5749 | 1538 |
"/ view has been closed. |
5751 | 1539 |
self stopAnimation. |
5749 | 1540 |
^ self |
1541 |
]. |
|
5751 | 1542 |
logo == (animatorState logoShown) ifFalse:[ |
5750 | 1543 |
"/ logo changed - stop it |
5751 | 1544 |
self stopAnimation. |
5750 | 1545 |
^ self |
1546 |
]. |
|
5752 | 1547 |
shown ifFalse:[ |
1548 |
"/ currently invisible (iconified/hidden) |
|
1549 |
Processor addTimedBlock:(animatorState timedBlock) after:self animationDelayTopOrBottom. |
|
1550 |
self computeLabelOrigin. |
|
1551 |
^ self. |
|
1552 |
]. |
|
5755 | 1553 |
(controller notNil and:[controller entered]) ifTrue:[ |
1554 |
"/ pause animation |
|
1555 |
Processor addTimedBlock:(animatorState timedBlock) after:0.5 seconds. |
|
1556 |
^ self. |
|
1557 |
]. |
|
5750 | 1558 |
|
5752 | 1559 |
offset := animatorState nextOffset max:0. |
1560 |
||
1561 |
atTop := (offset <= 0). |
|
1562 |
"/ Transcript printf:'labelHeight: %d offset: %d fA: %d fH: %d height: %d\n' |
|
1563 |
"/ withAll:{ labelHeight . offset . self font ascent . self font height . height }. |
|
1564 |
"/ (labelHeight - offset) is restHeight |
|
1565 |
atBottom := (labelHeight - offset) < height. |
|
5746 | 1566 |
|
5749 | 1567 |
nextAnimationDelay := (atTop | atBottom) |
1568 |
ifTrue:[ self animationDelayTopOrBottom ] |
|
1569 |
ifFalse:[ self animationDelay ]. |
|
1570 |
||
5751 | 1571 |
nextMoveDirection := animatorState moveDirection. |
1572 |
atTop ifTrue:[ |
|
1573 |
nextMoveDirection := #down |
|
1574 |
]. |
|
1575 |
||
5746 | 1576 |
atBottom ifTrue:[ |
1577 |
"/ after a longer delay, start again from top |
|
5751 | 1578 |
"/ nextOffset := 0. |
1579 |
"/ nextMoveDirection := #down. |
|
1580 |
"/ after a longer delay, start moving up again (fast) |
|
1581 |
nextOffset := offset - 1. |
|
1582 |
nextMoveDirection := #up. |
|
1583 |
] ifFalse:[ |
|
1584 |
nextMoveDirection == #down ifTrue:[ |
|
1585 |
nextOffset := offset + 1. |
|
1586 |
] ifFalse:[ |
|
5752 | 1587 |
nextOffset := offset - 2. |
1588 |
nextAnimationDelay := nextAnimationDelay / 4. "/ fast |
|
5751 | 1589 |
]. |
5746 | 1590 |
]. |
5749 | 1591 |
|
1592 |
"/ If I am not part of the active window, scroll back to top and wait longer... |
|
1593 |
((focusView := Display focusView) notNil |
|
1594 |
and:[ focusView windowGroup == self windowGroup ]) ifFalse:[ |
|
1595 |
nextOffset := offset := 0. |
|
1596 |
nextAnimationDelay := self animationDelayTopOrBottom. |
|
5751 | 1597 |
nextMoveDirection := #down. |
5749 | 1598 |
]. |
1599 |
||
5746 | 1600 |
labelOriginY := offset negated. |
5751 | 1601 |
animatorState nextOffset:nextOffset. |
1602 |
animatorState moveDirection:nextMoveDirection. |
|
5749 | 1603 |
|
5746 | 1604 |
self invalidate. |
5751 | 1605 |
Processor addTimedBlock:(animatorState timedBlock) after:nextAnimationDelay. |
5746 | 1606 |
! |
1607 |
||
1608 |
startAnimation |
|
5749 | 1609 |
"start an animator, which scrolls the label's text. |
5746 | 1610 |
(slow scroll which stops when the cursor enters)" |
1611 |
||
5751 | 1612 |
|timedBlock| |
5746 | 1613 |
|
5755 | 1614 |
self enableEnterLeaveEvents. |
1615 |
||
5746 | 1616 |
self stopAnimation. |
5749 | 1617 |
|
5751 | 1618 |
timedBlock := [ self doAnimate ]. |
1619 |
self |
|
1620 |
objectAttributeAt:#animator |
|
1621 |
put:(AnimatorState new |
|
1622 |
timedBlock:timedBlock |
|
1623 |
nextOffset:0 |
|
1624 |
moveDirection:#down |
|
1625 |
logoShown:logo). |
|
1626 |
Processor addTimedBlock:timedBlock after:(self animationDelay) |
|
5746 | 1627 |
|
1628 |
" |
|
1629 |
|l| |
|
1630 |
l := Label new. |
|
1631 |
l height:30. |
|
1632 |
l sizeFixed:true. |
|
1633 |
l label:'Line1 |
|
1634 |
Line2 |
|
1635 |
Line3 |
|
1636 |
Line4'. |
|
1637 |
l openAndWait. |
|
1638 |
l startAnimation. |
|
1639 |
Delay waitForSeconds:10. |
|
1640 |
l stopAnimation. |
|
1641 |
" |
|
1642 |
! |
|
1643 |
||
1644 |
stopAnimation |
|
5751 | 1645 |
|animatorState timedBlock| |
5746 | 1646 |
|
5751 | 1647 |
animatorState := self removeObjectAttribute:#animator. |
1648 |
animatorState notNil ifTrue:[ |
|
1649 |
timedBlock := animatorState timedBlock. |
|
1650 |
Processor removeTimedBlock:timedBlock. |
|
1651 |
||
1652 |
"/ ensure that things are in their normal state again |
|
1653 |
self computeLabelOrigin. |
|
5749 | 1654 |
shown ifTrue:[ |
1655 |
self invalidate. |
|
1656 |
]. |
|
5746 | 1657 |
]. |
1658 |
! ! |
|
1659 |
||
4670 | 1660 |
!Label methodsFor:'menu'! |
1661 |
||
1662 |
copyLabelText |
|
6455 | 1663 |
"copy the label's text to the clipboard" |
1664 |
||
4670 | 1665 |
|text| |
1666 |
||
6455 | 1667 |
text := logo asString string. |
4670 | 1668 |
self setClipboardText:text. |
1669 |
! |
|
1670 |
||
1671 |
middleButtonMenu |
|
1672 |
|m| |
|
1673 |
||
1674 |
m := super middleButtonMenu. |
|
1675 |
m isNil ifTrue:[ |
|
4672 | 1676 |
m := self yellowButtonMenu. |
1677 |
m isNil ifTrue:[ |
|
1678 |
"/ not a customized menu |
|
1679 |
self class == Label ifTrue:[ |
|
1680 |
m := self class middleButtonMenu |
|
1681 |
] |
|
4670 | 1682 |
]. |
1683 |
]. |
|
1684 |
^ m |
|
1685 |
! ! |
|
1686 |
||
5123 | 1687 |
!Label methodsFor:'native widget support'! |
1688 |
||
1689 |
nativeWindowType |
|
1690 |
"return a symbol describing my native window type |
|
5538 | 1691 |
(may be used internally by the device as a native window creation hint, |
1692 |
if the device supports native windows)" |
|
5123 | 1693 |
|
1694 |
self class == Label ifTrue:[ |
|
1695 |
^ #Label |
|
1696 |
]. |
|
1697 |
^ nil |
|
1698 |
! ! |
|
1699 |
||
202 | 1700 |
!Label methodsFor:'private'! |
1701 |
||
1702 |
computeLabelOrigin |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1703 |
"(re)compute the origin of the label whenever label, font or view-size changes" |
202 | 1704 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1705 |
|x y a| |
202 | 1706 |
|
1707 |
labelHeight isNil ifTrue:[^ self]. |
|
1708 |
||
1709 |
adjust == #fit ifTrue:[ |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1710 |
labelOriginX := labelOriginY := margin. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1711 |
^ self |
202 | 1712 |
]. |
1713 |
||
1714 |
"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
|
1715 |
or the center ? |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1716 |
(for text, the center seems better. |
5587 | 1717 |
For images, I don't really know ...) |
202 | 1718 |
The commented code below makes the origin visible |
1719 |
" |
|
6326 | 1720 |
"/ (labelHeight < height) ifTrue:[ |
1721 |
"/ y := (height - labelHeight) // 2 |
|
1722 |
"/ ] ifFalse:[ |
|
1723 |
"/ y := 0 |
|
1724 |
"/ ]. |
|
202 | 1725 |
|
1726 |
"always center vertically" |
|
1727 |
y := (height - labelHeight) // 2. |
|
1728 |
||
1729 |
labelOriginY := y. |
|
1730 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1731 |
a := adjust. |
1945 | 1732 |
a == #centerEach ifTrue:[a := #center]. |
1733 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1734 |
(width < labelWidth) ifTrue:[ |
1921 | 1735 |
((a == #centerRight) or:[a == #leftRight]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1736 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1737 |
] ifFalse:[ |
1921 | 1738 |
((a == #centerLeft) or:[a == #rightLeft]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1739 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1740 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1741 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1742 |
] ifFalse:[ |
1921 | 1743 |
((a == #centerRight) or:[a == #centerLeft]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1744 |
a := #center |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1745 |
] ifFalse:[ |
1921 | 1746 |
a == #leftRight ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1747 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1748 |
] ifFalse:[ |
1921 | 1749 |
a == #rightLeft ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1750 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1751 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1752 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1753 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1754 |
]. |
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1755 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1756 |
(a == #center) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1757 |
" center text/form in button " |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1758 |
x := (width - labelWidth) // 2. |
202 | 1759 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1760 |
(a == #left) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1761 |
x := margin |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1762 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1763 |
"/ #right |
5445 | 1764 |
x := width - labelWidth - margin - self extraMarginForBorder |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1765 |
] |
202 | 1766 |
]. |
1767 |
labelOriginX := x |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1768 |
|
6326 | 1769 |
"Modified: / 13-05-1996 / 10:55:17 / cg" |
1770 |
"Modified: / 24-05-2018 / 11:30:09 / Claus Gittinger" |
|
202 | 1771 |
! |
1772 |
||
1773 |
computeLabelSize |
|
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1774 |
"compute the extent needed to hold the logo" |
202 | 1775 |
|
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1776 |
|ext| |
202 | 1777 |
|
1778 |
logo isNil ifTrue:[^ self]. |
|
1779 |
||
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1780 |
ext := self rawLabelSizeOf:logo. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1781 |
labelWidth := ext x. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1782 |
labelHeight := ext y. |
202 | 1783 |
! |
1784 |
||
1785 |
getLabelFromModel |
|
1786 |
"ask my model for the label to show. |
|
1787 |
Here, we use labelMsg (instead of aspectMsg). |
|
1788 |
This allows multiple labels to react on the same aspect, |
|
1789 |
but show different labels when changed |
|
1790 |
(also, since labelMsg defaults to nil, constant labels |
|
5782 | 1791 |
which have a nil labelMsg will not try to acquire a labelString)." |
202 | 1792 |
|
1793 |
|val| |
|
1794 |
||
1795 |
(model notNil |
|
1796 |
and:[labelMsg notNil]) ifTrue:[ |
|
5782 | 1797 |
val := model perform:labelMsg. |
1798 |
converter notNil ifTrue:[ |
|
1799 |
val := converter printStringFor:val |
|
1800 |
]. |
|
1801 |
self label:val. |
|
202 | 1802 |
]. |
1803 |
! |
|
1804 |
||
1805 |
newLayout |
|
1806 |
"recompute position/size after a change |
|
1807 |
- helper for form:/font: etc." |
|
1808 |
||
1809 |
self computeLabelSize. |
|
3499 | 1810 |
|
202 | 1811 |
fixSize ifFalse:[ |
3499 | 1812 |
self resize. |
1813 |
] ifTrue:[ |
|
1814 |
self computeLabelOrigin. |
|
202 | 1815 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1816 |
self invalidate |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1817 |
|
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1818 |
"Modified: / 6.6.1998 / 19:23:45 / cg" |
5943 | 1819 |
! |
1820 |
||
1821 |
rawLabelSizeOf:aLogo |
|
1822 |
"compute the extent needed to hold aLogo; aForm or aString" |
|
1823 |
||
1824 |
|logoUsed numberOfLines w h textHeight textWidth bounds| |
|
1825 |
||
1826 |
logoUsed := aLogo. |
|
1827 |
aLogo isString ifTrue:[ |
|
1828 |
numberOfLines := 1 + (aLogo occurrencesOf:(Character cr)). |
|
1829 |
(numberOfLines ~~ 1) ifTrue:[ |
|
1830 |
logoUsed := aLogo asStringCollection |
|
1831 |
] |
|
1832 |
] ifFalse:[ |
|
1833 |
(aLogo isStringCollection) ifTrue:[ |
|
1834 |
numberOfLines := aLogo size. |
|
1835 |
(numberOfLines <= 1) ifTrue:[ |
|
1836 |
logoUsed := aLogo asString |
|
1837 |
] |
|
1838 |
] |
|
1839 |
]. |
|
1840 |
||
1841 |
numberOfLines isNil ifTrue:[ |
|
1842 |
"logoUsed is neither a String nor a StringCollection" |
|
1843 |
(logoUsed respondsTo:#preferredBounds) ifTrue:[ |
|
1844 |
bounds := logoUsed preferredBounds. |
|
1845 |
w := bounds width. |
|
1846 |
h := bounds height. |
|
1847 |
] ifFalse:[ |
|
1848 |
w := logoUsed widthOn:self. |
|
1849 |
h := logoUsed heightOn:self. |
|
1850 |
]. |
|
1851 |
||
1852 |
"/ b := logoUsed bounds. |
|
1853 |
"/ labelWidth := b right. |
|
1854 |
"/ labelHeight := b bottom. |
|
1855 |
logoUsed isImageOrForm ifFalse:[ |
|
1856 |
w := w + (hSpace * 2). |
|
1857 |
h := h + (vSpace * 2). |
|
1858 |
]. |
|
1859 |
^ w@h |
|
1860 |
]. |
|
1861 |
||
1862 |
logoUsed isString ifTrue:[ |
|
1863 |
"/ a string or Text |
|
1864 |
textHeight := logoUsed heightOn:self. |
|
1865 |
textWidth := logoUsed widthOn:self. |
|
1866 |
] ifFalse:[ |
|
1867 |
"/ a StringCollection |
|
1868 |
textHeight := (gc font height) * numberOfLines. |
|
1869 |
||
1870 |
textWidth := 0. |
|
1871 |
logoUsed do:[:line | |
|
1872 |
|thisWidth| |
|
1873 |
||
1874 |
line notNil ifTrue:[ |
|
1875 |
thisWidth := line asString widthOn:self. |
|
1876 |
textWidth := textWidth max:thisWidth |
|
1877 |
] |
|
1878 |
]. |
|
1879 |
]. |
|
1880 |
||
1881 |
w := textWidth + (hSpace * 2). |
|
1882 |
h := textHeight + (vSpace * 2). |
|
1883 |
^ w@h |
|
1884 |
||
1885 |
"Modified: / 05-12-2011 / 22:35:44 / cg" |
|
202 | 1886 |
! ! |
1887 |
||
1888 |
!Label methodsFor:'queries'! |
|
1889 |
||
6455 | 1890 |
canCopyLabelText |
1891 |
^ self isTextLabel |
|
1892 |
! |
|
1893 |
||
6485 | 1894 |
computePreferredExtent |
1895 |
"compute my preferred extent - this is the minimum size I would like to have" |
|
202 | 1896 |
|
5943 | 1897 |
|ext m2| |
202 | 1898 |
|
6485 | 1899 |
"/ "/ If I have a frozen extent value... |
1900 |
"/ fixSize ifTrue:[ |
|
1901 |
"/ ^ self extent |
|
1902 |
"/ ]. |
|
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1903 |
|
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1904 |
logo isNil ifTrue:[ |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1905 |
self label:'' |
202 | 1906 |
]. |
4003
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1907 |
ext := self rawLabelSizeOf:logo. |
5943 | 1908 |
m2 := (margin + self extraMarginForBorder) * 2. |
1909 |
^ (m2 + ext x + hSpace) @ (m2 + vSpace + ext y) |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1910 |
|
6485 | 1911 |
"Created: / 09-11-2018 / 19:45:49 / Claus Gittinger" |
1912 |
"Modified: / 09-11-2018 / 21:20:49 / Claus Gittinger" |
|
1913 |
! |
|
1914 |
||
1915 |
isTextLabel |
|
1916 |
^ logo isString or:[logo isText or:[logo isStringCollection]] |
|
993 | 1917 |
! |
1918 |
||
1919 |
redrawsFull |
|
1920 |
^ true |
|
1921 |
||
1922 |
"Created: 7.2.1997 / 16:41:41 / cg" |
|
202 | 1923 |
! ! |
1924 |
||
0 | 1925 |
!Label methodsFor:'redrawing'! |
1926 |
||
77 | 1927 |
clearInsideWith:bg |
1928 |
|cutOff mustClear| |
|
0 | 1929 |
|
1930 |
cutOff := margin * 2. |
|
1931 |
||
3 | 1932 |
mustClear := true. |
1933 |
||
87 | 1934 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[ |
6052 | 1935 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[ |
1936 |
logo width >= (width - cutOff) ifTrue:[ |
|
1937 |
logo height >= (height - cutOff) ifTrue:[ |
|
1938 |
"no need to clear before - avoid flicker" |
|
1939 |
mustClear := false |
|
1940 |
] |
|
1941 |
] |
|
1942 |
]. |
|
3 | 1943 |
]. |
1944 |
||
1945 |
mustClear ifTrue:[ |
|
6052 | 1946 |
gc paint:bg. |
1947 |
gc fillRectangleX:margin y:margin width:(width - cutOff) height:(height - cutOff). |
|
3 | 1948 |
]. |
77 | 1949 |
! |
1950 |
||
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1951 |
drawImageLogo:imageOrForm x:x y:y opaque:opaque |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1952 |
(opaque not or:[imageOrForm mask notNil]) ifTrue:[ |
6297 | 1953 |
gc clearRectangleX:x y:y width:imageOrForm width height:imageOrForm height. |
6052 | 1954 |
gc displayForm:imageOrForm x:x y:y |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1955 |
] ifFalse:[ |
6052 | 1956 |
gc displayOpaqueForm:imageOrForm x:x y:y |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1957 |
] |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1958 |
! |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1959 |
|
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1960 |
drawOtherLogo:something x:x y:y opaque:opaque |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1961 |
something displayOn:self x:x y:y opaque:opaque |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1962 |
! |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1963 |
|
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1964 |
drawStringLogo:aString x:x y:y |
6052 | 1965 |
gc displayString:aString x:x y:y |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1966 |
! |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1967 |
|
1679 | 1968 |
drawWin95FocusFrame |
1891 | 1969 |
|m1 m2| |
1970 |
||
1971 |
m1 := margin + 1. |
|
1972 |
m2 := margin + margin + 2. |
|
1679 | 1973 |
self |
1891 | 1974 |
displayDottedRectangleX:m1 |
1975 |
y:m1 |
|
1976 |
width:(width - m2) |
|
1977 |
height:(height - m2). |
|
1679 | 1978 |
|
1979 |
"Created: / 17.9.1998 / 14:16:46 / cg" |
|
1891 | 1980 |
"Modified: / 29.4.1999 / 21:49:22 / cg" |
1679 | 1981 |
! |
1982 |
||
77 | 1983 |
drawWith:fg and:bg |
1984 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1985 |
(especially Button) to redraw the logo in different colors." |
|
1986 |
||
2496 | 1987 |
self drawWith:fg and:bg clearInside:true etchedFg:etchedFgColor. |
1988 |
! |
|
1989 |
||
1990 |
drawWith:fg and:bg clearInside:doClear etchedFg:etchedFg |
|
1991 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1992 |
(especially Button) to redraw the logo in different colors." |
|
1993 |
||
5983 | 1994 |
|x y scaleH scaleV nW nH hSep vSep m2 ascent currentTransformation |
6177 | 1995 |
logoWidth logoHeight lines logoDrawn| |
77 | 1996 |
|
2496 | 1997 |
doClear ifTrue:[self clearInsideWith:bg]. |
0 | 1998 |
|
6052 | 1999 |
gc paint:fg on:bg. |
0 | 2000 |
logo notNil ifTrue:[ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2001 |
m2 := margin * 2. |
4899 | 2002 |
hSep := hSpace*2. |
2003 |
vSep := vSpace*2. |
|
133 | 2004 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2005 |
x := labelOriginX. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2006 |
y := labelOriginY. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2007 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2008 |
logo isImageOrForm ifTrue:[ |
5983 | 2009 |
logoWidth := logo width. |
2010 |
logoHeight := logo height. |
|
2011 |
((logoWidth == 0) or:[logoHeight == 0]) ifTrue:[ |
|
2012 |
"/ do nothing; also avoids followup errors in the image creation and division by zero... |
|
2013 |
^ self. |
|
2014 |
]. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2015 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2016 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2017 |
"/ 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
|
2018 |
"/ |
5983 | 2019 |
scaleH := ((width - hSep) / logoWidth) asFloat. |
2020 |
scaleV := ((height - vSep) / logoHeight) asFloat. |
|
2968 | 2021 |
scaleH <= 0 ifTrue:[scaleH := Float epsilon]. |
2022 |
scaleV <= 0 ifTrue:[scaleV := Float epsilon]. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2023 |
self scale:(scaleH @ scaleV). |
4899 | 2024 |
x := currentTransformation applyInverseScaleX:x. |
2025 |
y := currentTransformation applyInverseScaleY:y. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2026 |
]. |
131 | 2027 |
|
5633 | 2028 |
logo := logo onDevice:device. |
59 | 2029 |
"/ self background:bg. |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
2030 |
self drawImageLogo:logo x:x y:y opaque:doClear. |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2031 |
] ifFalse:[ |
6177 | 2032 |
"/ convert to a line-collection if required; |
2033 |
"/ otherwise, adjust may get it wrong... |
|
2034 |
logoDrawn := logo. |
|
2035 |
(logoDrawn isString and:[(lines := logoDrawn asStringCollection) size > 1]) |
|
2036 |
ifTrue:[ |
|
2037 |
logoDrawn := lines. |
|
2038 |
]. |
|
2039 |
||
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2040 |
x := x + hSpace. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2041 |
y := y + vSpace. |
0 | 2042 |
|
1665 | 2043 |
level < 0 ifTrue:[ |
2044 |
x := x + 1. |
|
2045 |
y := y + 1 |
|
1659
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
2046 |
]. |
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
2047 |
|
6177 | 2048 |
ascent := logoDrawn ascentOn:self. |
3651
c47e8c3583cf
Remove type specific vodoo - ask logo for ascent instead.
Stefan Vogel <sv@exept.de>
parents:
3649
diff
changeset
|
2049 |
y := y + ascent. |
c47e8c3583cf
Remove type specific vodoo - ask logo for ascent instead.
Stefan Vogel <sv@exept.de>
parents:
3649
diff
changeset
|
2050 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2051 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2052 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2053 |
"/ 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
|
2054 |
"/ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2055 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2056 |
scaleV := ((height - m2 - vSep) / (labelHeight - vSpace)) asFloat. |
2968 | 2057 |
scaleH <= 0 ifTrue:[scaleH := Float epsilon]. |
2058 |
scaleV <= 0 ifTrue:[scaleV := Float epsilon]. |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2059 |
|
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2060 |
self scale:(scaleH min:scaleV). |
4899 | 2061 |
currentTransformation := gc transformation. |
2062 |
x := currentTransformation applyInverseScaleX:x. |
|
3651
c47e8c3583cf
Remove type specific vodoo - ask logo for ascent instead.
Stefan Vogel <sv@exept.de>
parents:
3649
diff
changeset
|
2063 |
ascent ~~ 0 ifTrue:[ |
4899 | 2064 |
y := y - ascent + (currentTransformation applyScaleY:ascent). |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2065 |
]. |
4899 | 2066 |
y := currentTransformation applyInverseScaleY:y. |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2067 |
scaleH < scaleV ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2068 |
nH := labelHeight * scaleH. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2069 |
"/ now, center vertically |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2070 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2071 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2072 |
scaleV < scaleH ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2073 |
"/ now, center horizontally |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2074 |
nW := labelWidth * scaleV. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2075 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2) |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2076 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2077 |
]. |
131 | 2078 |
|
6177 | 2079 |
logoDrawn isString ifTrue:[ |
2496 | 2080 |
"/ doClear ifTrue:[ |
6177 | 2081 |
"/ self displayOpaqueString:logoDrawn x:x y:y |
2496 | 2082 |
"/ ] ifFalse:[ |
6177 | 2083 |
"/ self displayString:logoDrawn x:x y:y |
2496 | 2084 |
"/ ] |
2085 |
etchedFg notNil ifTrue:[ |
|
6052 | 2086 |
gc paint:etchedFg. |
6177 | 2087 |
self drawStringLogo:logoDrawn x:x+1 y:y+1. |
6052 | 2088 |
gc paint:fg. |
2496 | 2089 |
]. |
6177 | 2090 |
self drawStringLogo:logoDrawn x:x y:y |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2091 |
] ifFalse:[ |
6177 | 2092 |
(logoDrawn isStringCollection) ifTrue:[ |
2093 |
logoDrawn do:[ :line | |
|
2496 | 2094 |
|wThis str| |
2095 |
||
1945 | 2096 |
adjust == #centerEach ifTrue:[ |
2097 |
wThis := line asString widthOn:self. |
|
2098 |
x := (width - wThis) // 2. |
|
2099 |
]. |
|
2496 | 2100 |
str := line printString. |
2101 |
"/ doClear ifTrue:[ |
|
2102 |
"/ self displayOpaqueString:str x:x y:y. |
|
2103 |
"/ ] ifFalse:[ |
|
2104 |
"/ self displayString:str x:x y:y. |
|
2105 |
"/ ]. |
|
2106 |
etchedFg notNil ifTrue:[ |
|
6052 | 2107 |
gc paint:etchedFg. |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
2108 |
self drawStringLogo:str x:x+1 y:y+1. |
6052 | 2109 |
gc paint:fg. |
2496 | 2110 |
]. |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
2111 |
self drawStringLogo:str x:x y:y. |
4891 | 2112 |
y := y + (gc font height) |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2113 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2114 |
] ifFalse:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2115 |
"/ anything |
6177 | 2116 |
self drawOtherLogo:logoDrawn x:x y:y opaque:doClear |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2117 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2118 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2119 |
]. |
131 | 2120 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2121 |
adjust == #fit ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2122 |
self scale:1 |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2123 |
]. |
0 | 2124 |
] |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2125 |
|
6177 | 2126 |
"Modified: / 11-07-2017 / 14:35:40 / cg" |
0 | 2127 |
! |
2128 |
||
2129 |
redraw |
|
2130 |
"redraw my label" |
|
2131 |
||
2132 |
shown ifTrue:[ |
|
3924 | 2133 |
self clear. |
2134 |
self drawWith:fgColor and:bgColor |
|
0 | 2135 |
] |
2136 |
! ! |
|
105 | 2137 |
|
110 | 2138 |
!Label methodsFor:'resizing'! |
2139 |
||
2140 |
forceResize |
|
118 | 2141 |
"resize myself to make text fit into myself. Here, this is done even if |
2142 |
fixSize is set." |
|
110 | 2143 |
|
2664 | 2144 |
|prevFixSize| |
2145 |
||
110 | 2146 |
logo notNil ifTrue:[ |
2664 | 2147 |
prevFixSize := fixSize. |
2148 |
fixSize := false. |
|
2149 |
self extent:self preferredExtent. |
|
2150 |
self computeLabelOrigin. |
|
3499 | 2151 |
"/ this seems the only one which might depend on my contents. |
2152 |
layout isLayout ifTrue:[ |
|
2153 |
layout isAlignmentOrigin ifTrue:[ |
|
2154 |
self containerChangedSize. |
|
2155 |
] |
|
2156 |
]. |
|
2664 | 2157 |
fixSize := prevFixSize. |
2158 |
] |
|
2159 |
! |
|
2160 |
||
2161 |
forceResizeHorizontally |
|
2162 |
"resize myself horizontally to make text fit into myself. |
|
2163 |
Here, this is done even if fixSize is set." |
|
2164 |
||
2165 |
|prevFixSize| |
|
2166 |
||
2167 |
logo notNil ifTrue:[ |
|
2168 |
prevFixSize := fixSize. |
|
2169 |
fixSize := false. |
|
3615
a99127b32e61
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3597
diff
changeset
|
2170 |
self width:self preferredWidth. |
2664 | 2171 |
self computeLabelOrigin. |
2172 |
fixSize := prevFixSize. |
|
110 | 2173 |
] |
105 | 2174 |
! |
2175 |
||
2176 |
resize |
|
2177 |
"resize myself to make text fit into myself. |
|
118 | 2178 |
but only do so, if I am not fixedSize and I have NOT been |
2179 |
given a relative extent or an extend computation block." |
|
105 | 2180 |
|
110 | 2181 |
(logo notNil |
2182 |
and:[fixSize not |
|
2183 |
and:[relativeExtent isNil |
|
2184 |
and:[extentRule isNil |
|
2185 |
and:[relativeCorner isNil |
|
2186 |
and:[cornerRule isNil]]]]]) ifTrue:[ |
|
2187 |
self forceResize |
|
2188 |
] ifFalse:[ |
|
105 | 2189 |
self computeLabelOrigin |
2190 |
] |
|
2191 |
! ! |
|
2192 |
||
5751 | 2193 |
!Label::AnimatorState methodsFor:'accessing'! |
2194 |
||
2195 |
logoShown |
|
2196 |
^ logoShown |
|
2197 |
! |
|
2198 |
||
2199 |
moveDirection |
|
2200 |
^ moveDirection |
|
2201 |
! |
|
2202 |
||
2203 |
moveDirection:something |
|
2204 |
moveDirection := something. |
|
2205 |
! |
|
2206 |
||
2207 |
nextOffset |
|
2208 |
^ nextOffset |
|
2209 |
! |
|
2210 |
||
2211 |
nextOffset:something |
|
2212 |
nextOffset := something. |
|
2213 |
! |
|
2214 |
||
5755 | 2215 |
pointerEntered |
2216 |
^ pointerEntered |
|
2217 |
! |
|
2218 |
||
2219 |
pointerEntered:something |
|
2220 |
pointerEntered := something. |
|
2221 |
! |
|
2222 |
||
5751 | 2223 |
timedBlock |
2224 |
^ timedBlock |
|
2225 |
! |
|
2226 |
||
2227 |
timedBlock:timedBlockArg nextOffset:nextOffsetArg moveDirection:moveDirectionArg logoShown:logoShownArg |
|
2228 |
timedBlock := timedBlockArg. |
|
2229 |
nextOffset := nextOffsetArg. |
|
2230 |
moveDirection := moveDirectionArg. |
|
2231 |
logoShown := logoShownArg. |
|
2232 |
! ! |
|
2233 |
||
935 | 2234 |
!Label class methodsFor:'documentation'! |
205 | 2235 |
|
2236 |
version |
|
5445 | 2237 |
^ '$Header$' |
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
2238 |
! |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
2239 |
|
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
2240 |
version_CVS |
5445 | 2241 |
^ '$Header$' |
205 | 2242 |
! ! |
4670 | 2243 |