Skip to main content
Visitor II
August 25, 2023
Question

Click on a widget without touchscreen

  • August 25, 2023
  • 1 reply
  • 1064 views

Hi,

For a device without touchscreen, I'm prototyping a GUI using a clickable wheel as user input. A red box is used as visual focus on widget. I tied the following code to deliver a programmatic click :

void navScreenView::selectClicked(){
Rect clickedRect = (*focused)->getFirstChild()->getAbsoluteRect();
Application* app = Application::getInstance();
int x = clickedRect.x + clickedRect.width / 2;
int y = clickedRect.y + clickedRect.height / 2;

snprintf(debugStringBuffer, sizeof(debugStringBuffer), "Click: %d, %d", x, y);
Application::invalidateDebugRegion();

ClickEvent ev = ClickEvent(ClickEvent::PRESSED,x ,y);
app->handleClickEvent(ev);
HAL::getInstance()->taskDelay(200);
ev = ClickEvent(ClickEvent::RELEASED,x ,y);
app->handleClickEvent(ev);
}

 The coordinates x,y are correct, but passing the event to the application does not trigger anything.

Any advice ?

This topic has been closed for replies.

1 reply

ST Employee
September 1, 2023

Hello @Fribes ,

You can simply define your widgets as 'ClickListener' through the designer and continue using your ClickEvent. You don't need to use the application in this case.

ClickListener Option in the DesignerClickListener Option in the Designer

 

You can read more about the ClickListener here:

https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_click_listener

 

I hope this would help.

Mohammad MORADIST Software Developer | TouchGFX