TouchGFX has a range of mechanisms for reacting to events in the system. There is built-in handling of touch input events, physical button input events and timer events. In addition more high-level, application specific events can be added.
Touch input events
When the touch controller reports that the screen has been touched at a specific coordinate, TouchGFX will automatically notify the appropriate Drawable of this. TouchGFX will also interpret subsequent inputs and transform this into drag events or swipe gestures. Most standard drawables in TouchGFX will not listen for touch events, except of course drawables like
ScrollableContainer. Those will evoke a callback, which you can choose to act on in your application. Custom drawables can of course also be configured to react to touch events.
In addition to the appropriate drawable being notified, your View is also always notified of touch events, so you have full flexibility in determining what to do with a certain event, by overriding the handleClickEvent virtual function.
For details, please see the article Touch input and reacting to touch events
Physical button events
Since it is quite common for designs to include physical buttons in addition to a touch screen, TouchGFX has an event mechanism for these, which in TouchGFX context are called key events. If properly configured in the porting for your hardware board, physical button clicks are automatically routed to your active view and can be acted upon by overriding the handleKeyEvent function.
When doing animations it is necessary to have a periodic tick event notification. Like with touch and key events, your currently active View will get a function called every frame which can be overridden. This function is called
handleTickEvent. In addition, custom drawables can themselves subscribe to tick events, so you can encapsulate the animation code inside the custom drawable.
For details, please see the article Timer events and periodic ticks
User defined events
It is of course possible to make custom drawables emit application-specific events when something needs to be communicated from the drawable to e.g. the View. This is usually done by using callbacks, which are introduced briefly in the next section of this article.
In TouchGFX callbacks are a builtin mechanism for registering a pointer to a member function (a function that can take 0, 1 or 2 arguments of any type), and calling this function when something occurs. Some of the standard drawables use callbacks for various events. For example, the
Button widget will call a callback function when the button is clicked. Typically you would place the callback function within your View so you can easily manipulate other drawables when the button is clicked.
Alternatively, if for instance, you create a custom container that contains a Button and some other widgets, you might instead want to have the callback function placed in the custom container class instead, and this is of course also possible. You could then create a different callback for your custom container in order to communicate events to your View.
Callbacks are described in more detail in this knowledge base article