Skip to main content
awiernie
Associate III
May 1, 2021
Solved

Scroll ist: itemSelectedCallback - is it possible to select instead of scroll if the touch coordinates are only moved a few pixels?

  • May 1, 2021
  • 2 replies
  • 844 views

I use a scroll list with setItemSelectedCallback. In principle, it works. But our measurement device needs to be explosion proof and therefore it has a rather thick glass above the screen.

If an entry of the scroll list is selected, it sometimes happens that the list is scrolled by 1 or 2 pixels. Select callback is not called in this case. As a work around, I have placed a button into the list element. The button works because it is only required that the coordinates at release time needs to be only somewhere within the button.

Is it possible that the scroll list is only scrolled after the scroll distance is longer than 1 or 2 pixel?

This topic has been closed for replies.
Best answer by Alexandre RENOUX

Hello awiernie,

Yes this is possible. You need to detect the click and act upon a drag only if it's bigger than x pixels.

Here is a brief code example :

void Screen1View::handleClickEvent(const ClickEvent& evt)
{
 if (evt.getType() == ClickEvent::PRESSED)
 {
 if(scrollList.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
 {
 isScrollListClicked = true;
 }
 }
 else if(evt.getType() == ClickEvent::RELEASED)
 {
 isScrollListClicked = false;
 dragDistance = 0;
 }
 // ScrollList receives the event
 Screen1ViewBase::handleClickEvent(evt);
}
 
void Screen1View::handleDragEvent(const DragEvent& evt)
{
 if(isScrollListClicked)
 {
 dragDistance += abs(evt.getDeltaX()); //In the case of horizontal. Otherwise replace with evt.getDeltaY()
 
 if(dragDistance > 10) // The drag must be a certain length to really drag the List
 { 
 Screen1ViewBase::handleDragEvent(evt);
 }
 }
}

Hope this answers your question.

If your question is answered, please close this topic by choosing Select as Best.

/Alexandre

2 replies

Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
May 3, 2021

Hello awiernie,

Yes this is possible. You need to detect the click and act upon a drag only if it's bigger than x pixels.

Here is a brief code example :

void Screen1View::handleClickEvent(const ClickEvent& evt)
{
 if (evt.getType() == ClickEvent::PRESSED)
 {
 if(scrollList.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
 {
 isScrollListClicked = true;
 }
 }
 else if(evt.getType() == ClickEvent::RELEASED)
 {
 isScrollListClicked = false;
 dragDistance = 0;
 }
 // ScrollList receives the event
 Screen1ViewBase::handleClickEvent(evt);
}
 
void Screen1View::handleDragEvent(const DragEvent& evt)
{
 if(isScrollListClicked)
 {
 dragDistance += abs(evt.getDeltaX()); //In the case of horizontal. Otherwise replace with evt.getDeltaY()
 
 if(dragDistance > 10) // The drag must be a certain length to really drag the List
 { 
 Screen1ViewBase::handleDragEvent(evt);
 }
 }
}

Hope this answers your question.

If your question is answered, please close this topic by choosing Select as Best.

/Alexandre

awiernie
awiernieAuthor
Associate III
May 3, 2021

Thank you. It works perfectly.