You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- define a skin class acting as root for the skins
235
235
- define a specific skin for the widget
236
236
237
237
#### Defining a new theme
238
238
239
+
To start defining a new theme, we obviously create a class inheriting from `ToTheme`.
239
240
```
240
-
241
241
ToTheme << #ToMooflooTheme
242
242
slots: {};
243
243
tag: 'Input';
244
244
package: 'myBecherBloc'
245
-
246
-
ToTheme << #ToNewTheme
247
-
tag: 'Input';
248
-
package: 'Bloc-Book'
249
-
250
245
```
251
246
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"
253
250
254
251
```
255
-
256
-
ToMooflooThemenewSkinInstanceFor: anElement
252
+
ToMooflooTheme >> newSkinInstanceFor: anElement
257
253
258
254
^ anElement newMooflooSkin
259
-
260
-
ToNewTheme >> newSkinInstanceFor: anElement
261
-
262
-
^ anElement newNewThemeSkin
263
-
264
255
```
265
256
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.
266
261
```
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'
278
266
```
279
267
280
268
```
281
-
282
269
BlElement >> newMooflooSkin
283
-
BlElement >> newNewThemeSkin
284
270
285
271
^ ToBasicMooflooSkin new
286
272
```
287
273
274
+
For elements we want to skin, we can simply return an instance of the said skin in `newMooflooSkin`
275
+
288
276
```
289
277
ToNumberInputElement >> newMooflooSkin
290
-
ToNumberInputElement >> newNewThemeSkin
291
-
292
278
293
279
^ ToInputElementSkin new
294
280
```
295
281
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
296
283
284
+
```
285
+
space := BlSpace new.
286
+
space toTheme: ToMooflooTheme new.
287
+
anInput := ToIntegerInputElement new position: 200 @ 200.
0 commit comments