cancel
Showing results for 
Search instead for 
Did you mean: 

Handle DragEvent in a customContainer with a list buttons and a slider

Iñaki_Bidasoro
Associate III

Hello,

 

Normally when i have to handle clicks or drags on a screen I just check where the clickEvent happens and if it has happened in the scroll with buttons inside it i cancel the event if its a scroll and do list.handleClick/Drag/Gesture event and if the click was somewhere else (sliders, buttons...) i do ScreenViewBase::handleClick/Drag/Gesture event.

But now I have this situation inside a container that at least to my knowledge if do CustomContainerBase::handleClick/Drag/Gesture event it doesn't make it's buttons or sliders handle it, 

So my idea was to (from the screen class)  redirect all the clicks directly to ScreenViewBase and if my container was visible redirect all drag/gestures to the container, 

This almost works, the button clicks and the drags of the list in the container work fine but the slider doesn't work, as it also needs the drag/gestureEvent I redirect to the list, i tried the following in my container code but the drag is done much lower than the actual click, 

void Choice_List::handleDragEvent(const DragEvent &evt)
{
  if (!m_slider.getAbsoluteRect().intersect(evt.getOldX(), evt.getOldY()))
  {
    m_can_scroll = true;
    m_scroll_elements.handleDragEvent(evt);
  }

  if (!m_scroll_elements.getAbsoluteRect().intersect(evt.getOldX(), evt.getOldY()))
  {
    m_can_scroll = false;
    m_slider.handleDragEvent(evt);
  }
}
void Choice_List::handleGestureEvent(const GestureEvent &evt)
{
  if (m_scroll_elements.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
  {
    m_can_scroll = true;
    m_scroll_elements.handleGestureEvent(evt);
  }
  else
  {
    m_can_scroll = false;
    m_slider.handleGestureEvent(evt);
  }
}

 

The result of that code works on the fact that it can drag both the list and the slider but the ball of the slider goes like 200px below the actual click, in the image below I show as i can, the red arrow is where i click to drag, and the the ball moves below it.

 

Iaki_Bidasoro_0-1726816736592.png

 

I know this post was poorly written but I don't know how to explain this situation.

 

5 REPLIES 5
GaetanGodart
ST Employee

Hello @Iñaki_Bidasoro ,

 

You should not modify the "base" files.

 

From what I understood, you have your slider inside a custom container.
When you touch the screen, the click values (x and y) are the coordinates on the screen.
So if you put your custom container at coordinate x:0 and y:200, you need to offset the clicked values to match the offset of the custom container.
Basicaly, it means that inside your custom container cpp file, when you use the coordinates of the click, you need to do xClick = xClick - self.getX() and yClick = yClick - self.getY().
I assume this is the issue you are encountering, you put your custom container around x:0 and y:200.

 

Could you share you full project so that we can help you better?

 

I hope this helps. :smiling_face_with_smiling_eyes:
If this comment fixes your issue, I invite you to select it as "best answer".

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
Iñaki_Bidasoro
Associate III

Yes the offset inside the container was the problem of the visual bug.

Anyways I don't really understand how clicks are interpreted in the enviroment, I mean if we have a screen with a container in it and if we click in the container, who is the one handling the click the container/widget or the screen. 

And how to grab that evt and react. 

I'm not able to see the .cpp files in which the handleClick/gest/drag events are defined so I think it would be a good idea to update the documentation on this matter.

It simply depend on where you fetch the click.

If you want the reference to be the custom container, you can set it clickable and fetch the click on your custom container with a callback, this way you get the coordinate relative to your custom container.
I have made an example illustrating that, please find it attached to this message.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Thanks for taking the time to do this, and I get it, 

But my problem is that when the list in myCustomContainer has a widget that has its own default behaviour inside touchgfx such as button or slider, it feels like it hijackes the event and i cant get the event inside the container. Not even after setting the mixin clickListener to the container from the screen.

I have created this small project to show you, its a list inside a container inside a screen, and the container has Clicklistener mixin activated and inside its cpp it has custom handleClick/Drag/Gesture events, but the behaviour that i get is:
if we click inside the container it reaches handleClick event, but if we click in a button (inside the list) event is handled by the button, so I cant drag the list as the button handles it, not the list, but if we drag in the middle of the buttons (in the margin) of the list then it drags, I want to handle the event in the customContainer code as I would in a normal screen.

I know im kinda messy when trying to explain it and im sorry but I don't really get how this interaction works between containers and screen with events and I need to know it to handle different scenarios in my real program.

Hello @Iñaki_Bidasoro ,

 

 

Can you just call the handleClickEvent/clickListener inside the function called by the button's click?
Something like:

void buttonIsClicked(intx, int y)
{
    handleClickEvent(button.getX()+x, button.getY()+y);
    /*
    *Whatever you want to do when the button is clicked
    */
}

(you might have to specify the namesapce in which the handleClickEvent function exist).

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)