How to Add a Widget Event Filter - mchpgfx/legato.docs GitHub Wiki
Graphics does not exist in a vaccum. The whole point of Graphics User Interface is to provide human-machine interaction.
The previous guide How to Add a Widget Event Callback teaches how to create an widget event callback to widget. This guide teaches widget event filter and how to set one up.
Event filters can be used to add or 'override' default widget event handling.
The allow events like Touch Down/Up/Move, Change Language, Widget Paint, Widget Move, Widget Resized, Widget Focus to be handled in Application Code.
Event filters can also be used to 'mute' specific events from being handled.
Here is an example of adding a move event filter to the label "Fast" in Legato Quickstart.
- Open app.c in MPLABX
- Include definitions.h header file in app.c
- Define the event filter function. This will definte the actions that will be used when a touch event is received by the target widget
Here is the code for reference:
static leBool app_filterEvent(leWidget* target, leWidgetEvent* evt, void* data)
{
switch(evt->id)
{
case LE_EVENT_TOUCH_DOWN:
{
evt->owner = target;
evt->accepted = LE_TRUE;
break;
}
case LE_EVENT_TOUCH_MOVE:
{
int x, y;
leWidgetEvent_TouchMove * move = (leWidgetEvent_TouchMove *) evt;
x = move->x;
y = move->y;
target->fn->setPosition(target, x, y);
evt->accepted = LE_TRUE;
break;
}
default:
break;
}
return LE_FALSE;
}
- Also in app.c, define the event filter structure.
Code for reference:
static leWidgetEventFilter app_eventFilter =
{
app_filterEvent,
NULL
};
- Define the Screen0_OnShow event handler function (See the How to Add a Screen Event guide for details). In the handler, the event filter will be registered for the ‘Fast.’ label widget on the screen. This will enable event handling for the widget, and will move the widget when touched and dragged on the screen.
Code for reference:
void Screen0_OnShow(void)
{
Screen0_fastLabel->fn->installEventFilter(Screen0_fastLabel, app_eventFilter);
}
At this point, you’re ready to generate, build and run your application. Touch and drag the ‘Fast.’ label to move it around the screen. Observe how its movement slows down when it’s moved over the MPLAB® Harmony Graphics Suite image. Can you tell why it slows down?
If you are new to MPLAB® Harmony, you should probably start with these tutorials:
- MPLAB® Harmony v3 Graphics Example Applications at MPLAB® Discover
- MPLAB® Harmony v3 software framework
- MPLAB® Harmony v3 Configurator Overview
- Create a New MPLAB® Harmony v3 Project
Is this page helpful? Send feedback