cancel
Showing results for 
Search instead for 
Did you mean: 

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

awiernie
Senior II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

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

View solution in original post

2 REPLIES 2
Alexandre RENOUX
Principal

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
Senior II

Thank you. It works perfectly.