Skip to content

Commit

Permalink
add another example + notes on event management
Browse files Browse the repository at this point in the history
  • Loading branch information
rvillemeur committed Jul 30, 2024
1 parent 0d8afd6 commit d718436
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Chapters/bloc/events.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
## Event handling





### Event handling




```smalltalk
BlElement new
background: Color white;
Expand All @@ -20,6 +13,9 @@ BlElement new
```

`addEventHandlerOn:do:` returns the new handler so that we can store to remove it in case.

#addEventHandlerOn: do: returns the new event handler. add a #yourself send after to return a BlElement.

`when:do:` is now deprecated and rewritten as `addEventHandlerOn:do:`
SD: we should update the following

Expand All @@ -38,13 +34,29 @@ We should check `example_mouseEvent_descending_bubbling`

![Windows nested in each others in Toplo.](figures/4windows.png width=80)

To stop event propagation `anEvent consumed: true`

There is an option to forbid mouse events for an element.
You just send `preventMouseEvent` to it

```smalltalk
"As a more general explanation, all UI related events can be controlled. Have a look at BlElementFlags and BlElementEventDispatcherActivatedEvents and how these classes are used. "
container := BlElement new size: 500 asPoint; border: (BlBorder paint: Color red width: 2).
"#addEventHandlerOn: do: returns the new event handler. add a #yourself send after"
child1 := BlElement new size: 300 asPoint; background: Color lightGreen; position: 100 asPoint; addEventHandlerOn: BlClickEvent do: [ self inform: '1' ]; yourself .
"There is an option to forbid mouse events for an element.
You just send #preventMouseEvent to it."
child2 := BlElement new size: 200 asPoint; position: 200 asPoint; border: (BlBorder paint: Color blue width: 2);preventMouseEvents.
container addChild: child1.
container addChild: child2.
container openInSpace.
```

### Drag&drop

Expand Down

0 comments on commit d718436

Please sign in to comment.