|
| 1 | +## Skins in Action |
| 2 | + |
| 3 | +### Why my label changes when in space |
| 4 | + |
| 5 | +When we assign a foreground color to a `ToLabel`, this color will be applied when inspecting the label but not when displaying the label in a space. |
| 6 | + |
| 7 | +``` |
| 8 | +label := ToLabel new text: 'Hello'; foreground: Color blue; yourself. |
| 9 | +
|
| 10 | +label inspect. |
| 11 | +
|
| 12 | +label openInSpace. |
| 13 | +
|
| 14 | +label inspect. |
| 15 | +``` |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +### Skins in Action |
| 21 | + |
| 22 | +What you observe is the label skin in action. |
| 23 | +The skin is installed when the label is added in a space. |
| 24 | +And the installed default label color is black (for the raw theme). |
| 25 | + |
| 26 | +Now, you have three solutions to customize your label look. |
| 27 | + |
| 28 | +- 1 First you can use a `ToAttributedLabel`, which is a subclass of `ToLabel` without any skin. |
| 29 | +- 2 You can send `withNullSkin` directly to the label if you prefer to use a `ToLabel`. |
| 30 | +- 3 The default text color is looked-up in the theme. It is stored in the token value named `#’color-text’`. You can redefine it locally with `#addTokenNamed:withValue:`. |
| 31 | + |
| 32 | +We use more and more solution 3 when we want to customize a label in a skin (as an example, in the tab node skin) |
| 33 | + |
| 34 | +### Solution 1 |
| 35 | + |
| 36 | +``` |
| 37 | +| label | |
| 38 | +label := ToAttributedLabel new text: 'Hello'; foreground: Color red; yourself. |
| 39 | +label openInSpace |
| 40 | +``` |
| 41 | + |
| 42 | +### Solution 2 |
| 43 | + |
| 44 | +``` |
| 45 | +| label | |
| 46 | +label := ToLabel new withNullSkin; text: 'Hello'; foreground: Color red; yourself. |
| 47 | +label openInSpace |
| 48 | +``` |
| 49 | + |
| 50 | +### Solution 3 variation one |
| 51 | + |
| 52 | +``` |
| 53 | +| label | |
| 54 | +label := ToLabel text: 'Hello'. |
| 55 | +label addTokenNamed: #'color-text' withValue: Color red. |
| 56 | +label openInSpace |
| 57 | +``` |
| 58 | + |
| 59 | +### Solution 3 variation two |
| 60 | + |
| 61 | +``` |
| 62 | +| container label | |
| 63 | +label := ToLabel text: 'Hello'. |
| 64 | +container := ToPane horizontal. |
| 65 | +container addChild: label. |
| 66 | +container addTokenNamed: #'color-text' withValue: Color red. |
| 67 | +container openInSpace |
| 68 | +``` |
0 commit comments