2021-05-01 12:49 PM
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?
Solved! Go to Solution.
2021-05-03 12:56 AM
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
2021-05-03 12:56 AM
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
2021-05-03 12:03 PM
Thank you. It works perfectly.