From d718436b74c7911b361d768c1532995ca6dd32a5 Mon Sep 17 00:00:00 2001 From: Renaud de Villemeur Date: Tue, 30 Jul 2024 12:17:08 -0400 Subject: [PATCH] add another example + notes on event management --- Chapters/bloc/events.md | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Chapters/bloc/events.md b/Chapters/bloc/events.md index 97c8a6a..ce284e0 100644 --- a/Chapters/bloc/events.md +++ b/Chapters/bloc/events.md @@ -1,14 +1,7 @@ ## Event handling - - - - ### Event handling - - - ```smalltalk BlElement new background: Color white; @@ -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 @@ -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