Skip to content

Commit 84b3838

Browse files
Update skinningAWidget.md
1 parent 08c5665 commit 84b3838

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

Chapters/toplo/skinningAWidget.md

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ To see this token property from our new theme applied, we need to apply this the
185185
```
186186
space := BlSpace new.
187187
space toTheme: ToInputTheme new.
188-
anInput := self ToIntegerInputElement position: 200 @ 200.
188+
anInput := ToIntegerInputElement new position: 200 @ 200.
189189
space root addChild: anInput.
190190
space show.
191191
```
@@ -231,72 +231,65 @@ ToNumberInputElement >> onAddedToSceneGraph
231231
We should now how we can define a full new theme.
232232
We will
233233
- define a theme class
234-
- define a skin class acting a root for the skins
234+
- define a skin class acting as root for the skins
235235
- define a specific skin for the widget
236236

237237
#### Defining a new theme
238238

239+
To start defining a new theme, we obviously create a class inheriting from `ToTheme`.
239240
```
240-
241241
ToTheme << #ToMooflooTheme
242242
slots: {};
243243
tag: 'Input';
244244
package: 'myBecherBloc'
245-
246-
ToTheme << #ToNewTheme
247-
tag: 'Input';
248-
package: 'Bloc-Book'
249-
250245
```
251246

252-
247+
A theme will try to apply skin corresponding to the type of skin defined in the theme, and those skins are called via the method we define in `newSkinInstanceFor:`.
248+
Indeed this method will be called on all elements when the theme is applied. This tells each element to search and return an instance of the skin to apply to it.
249+
The method called is by convention named "new[Theme name]Skin"
253250

254251
```
255-
256-
ToMooflooThemenewSkinInstanceFor: anElement
252+
ToMooflooTheme >> newSkinInstanceFor: anElement
257253
258254
^ anElement newMooflooSkin
259-
260-
ToNewTheme >> newSkinInstanceFor: anElement
261-
262-
^ anElement newNewThemeSkin
263-
264255
```
265256

257+
As the theme tries to apply a skin to each element, they need to return a default skin even if they are not supposed to have one.
258+
We can then define the `ToBasicMooflooSkin` class as subclass of `ToBasicSkin` to have a 'default' skin.
259+
Instances of `ToBasicMooflooSkin` can then be returned when needing a default skin for elements.
260+
We then define `newMooflooSkin` as an extension method on BlElement.
266261
```
267-
ToNumberInputElement class >> openInputWithSkin
268-
269-
<script>
270-
| space anInput |
271-
space := BlSpace new.
272-
space toTheme: ToMooflooTheme new.
273-
space toTheme: ToNewTheme new.
274-
anInput := self new position: 200 @ 200.
275-
space root addChild: anInput.
276-
space show.
277-
^ anInput
262+
ToBasicSkin << #ToBasicMooflooSkin
263+
slots: {};
264+
tag: 'Input';
265+
package: 'myBecherBloc'
278266
```
279267

280268
```
281-
282269
BlElement >> newMooflooSkin
283-
BlElement >> newNewThemeSkin
284270
285271
^ ToBasicMooflooSkin new
286272
```
287273

274+
For elements we want to skin, we can simply return an instance of the said skin in `newMooflooSkin`
275+
288276
```
289277
ToNumberInputElement >> newMooflooSkin
290-
ToNumberInputElement >> newNewThemeSkin
291-
292278
293279
^ ToInputElementSkin new
294280
```
295281

282+
If we execute this script where we redefine the space's theme, we can see it is applied just like in the example of the previous section
296283

284+
```
285+
space := BlSpace new.
286+
space toTheme: ToMooflooTheme new.
287+
anInput := ToIntegerInputElement new position: 200 @ 200.
288+
space root addChild: anInput.
289+
space show.
297290
298-
291+
```
299292

300293
### Using a stylesheet
301294

302-
295+
TODO

0 commit comments

Comments
 (0)