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
Add stylesheet example to widget styling and remove clock example, as I feel those are redundant with widget creation. The content is still there, as some parts already written could be reused in remaining chapters.
Copy file name to clipboardExpand all lines: Chapters/toplo/skinningAWidget.md
+184-1Lines changed: 184 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,4 +292,187 @@ space show.
292
292
293
293
### Using a stylesheet
294
294
295
-
TODO
295
+
Stylesheet is another way to style an element. With stylesheet, we select on which element we want to apply our style using dedicated selector
296
+
297
+
A style rule is an association between a selector and one or more writers. A rule can only be applied to a graphic element if the rule's selector corresponds to the graphic element. There are 5 types of selector, and they can be combined with different operators. The five selector types are:
298
+
299
+
***Any:** Selects any element.
300
+
***Action:** Evaluates a *block closure* with the graphic element as argument. If the block returns true, then the element is selected, otherwise it is not.
301
+
***Type:** Used to test whether the graphic element is an object of a given class. For example, it can check that the graphic element is a **ToButton**.
302
+
***Id:** Selects graphic elements according to their *id*. The id is a BlElement's property.
303
+
***Stamp:** Checks that the graphic element has a stamp with a given key.
304
+
305
+
Selectors can be combined together using different operators. There are 6 different operators:
306
+
307
+
***Not:** Negates the selection.
308
+
***And:** Boolean combination of *and* between two selectors.
309
+
***Or:** Boolean *or* combination between two selectors.
310
+
***Child:** Used to apply a selector to the graphic element's children. It is possible to set a child depth level.
311
+
***Parent:** Allows you to apply a selector to the graphic element's parent. It is possible to set a parent depth level.
312
+
***Sibling:** Allows you to apply a selector to graphic elements having the same parent as the graphic element.
313
+
314
+
All our element needs to be ToElement. Let's update our element creation
315
+
accordingly:
316
+
317
+
```smalltalk
318
+
ToIntegerInputElement >> createCircle
319
+
320
+
| circle |
321
+
circle := ToElement new
322
+
background: Color black;
323
+
border: (BlBorder paint: Color pink width: 2);
324
+
layout: BlFrameLayout new;
325
+
geometry: BlCircleGeometry new.
326
+
^ circle
327
+
```
328
+
329
+
Let's adapt our input widget to ease sub-element selection, by adding an *id* to relevant parts:
0 commit comments