Hey,
I'm trying to get touch events on (NativeUI) Labels to work.
So main question: is this possible? I looked at the RockPaperScissorsGameNativeUI example which uses touch events but the example uses MAWidgetHandles instead of Labels.
Specific problem: I really need a Calendar widget and I used the unofficial calendar widget that I found in the cookbook here, which worked fine for MAUI. However, I now use NativeUI instead so I'm trying to rewrite this widget to NativeUI instead.
So I have my Calendar.h:
class Calendar : public CustomEventListener {
. . .
void customEvent(const MAEvent& event);
void widgetClicked(MAHandle widgetHandle);
. . . }And my Calendar.cpp (customEvent does not catch touch events for some reason):
Calendar::Calendar(int x, int y, int width, int height)
: mX(x), mY(y), mWidth(width), mHeight(height) {
. . .
Environment::getEnvironment().addCustomEventListener(this);
. . . }
void Calendar::customEvent(const MAEvent& event)
{
//Trying to catch all events for debugging...
// If the event does not come from a widget, we just ignore it.
//if(event.type != EVENT_TYPE_WIDGET)
// return;
// Get the information sent by the widget.
MAWidgetEventData* widgetEventData = (MAWidgetEventData*) event.data;
//DEBUG
char buf[2];
sprintf(buf, "%i", widgetEventData->eventType);
//This only triggers event "0" on startup and nothing on touch events
maAlert("Event", buf, "ok", "0", "0");
// Check that the event was a click (touch) event.
if (widgetEventData->eventType == MAW_EVENT_CLICKED)
{
// Handle the event emitted by the widget
widgetClicked(widgetEventData->widgetHandle);
}
}
void Calendar::widgetClicked(MAHandle widgetHandle)
{
Vector_each(HorizontalLayout*, itr, mWeeks)
{
HorizontalLayout *week = *itr;
for(int i=0; i<7; i++)
{
Label *day = (Label*) week->getChild(i);
MAHandle handle = day->getWidgetHandle();
if(widgetHandle == handle)
{
//DEBUG
maAlert("Event", "Hit!", "ok", "0", "0");
//selectedDate = addDays(selectedDate, i - selectedIndex);
//formatMonth();
//informListener();
}
}
}
}I attach my Calendar code here if anyone is interested in trying to get this to work (the only thing that works so far is the initial rendering of the Calendar). To use it you can add to layout using:
Calendar *cal = new Calendar(...); yourMainLayout.addChild(cal->getMainLayout());
| Attachment | Size |
|---|---|
| NativeUICalendar.zip | 4.8 KB |