In the previous examples, we saw that most faces can have actors, which are event handlers that execute when a certain event occurs on that face. For example, the slider in the code we just explored has a default on-change actor, which is the code in the last block:
slider 100x20 data 25% [t/text: to-string face/data]
Not all faces can respond to all sorts of events. But a lot of faces can respond to multiple events as well.
Red defines some 40 events for which you can define actors on your faces. You can find the complete list here: https://doc.red-lang.org/en/view.html#_events.
Actors all have short names, such as move, over, or down. If we break them down into categories, we can distinguish the following:
- mouse events, such as down, up, drag, drop, click, dbl-click, over, wheel, and so on, including events for all three buttons, the mouse wheel, and hovering over faces
- window events, such as move and resize
- keyboard events, such as key, key-down, key-up, and enter
- touch events, such as zoom, pan, rotate, and tapping
- a timer event (time)
- general events, such as focus, select, change, and menu
To implement an actor on a face, specify an on-event name before its code block. This is only necessary for additional actors, not for the default actor. In the following sections, we look at some typical examples and learn more about their internals.