2019-02-04 03:09 AM
Hello,
I've created a scroll list that contains clickable items (the idea is to be able to edit them by keeping a given item selected for a certain period of time). The items received click events through a clickListener. However, it's now almost impossible to scroll the list as the click events are processed in place of the scroll function. How can I differenciate a slide action from a press action on the screen?
Thanks in advance for your help.
2019-02-04 04:45 AM
Hi @GMeur,
What you have to do is override handleClickEvent() and handleDragEvent() in your view and determine what you want to do (You will always receive a clickEvent before transitioning into a dragEvent). If you're just clicking (Receive a release event around the same coordinates) you can send the clickevent to the ScrollList (scrollList.handleClickEvent(event)). If you're in the process of dragging, do not send a handleClickEvent() message to the scroll List.
2019-09-10 12:49 AM
Hello,
I'm writing another message here to avoid creating a new thread. In a more complex setup, I've difficulties retransmitting a click event to lower containers. The setup is as such :
ViewScreen
|--- ScrollableContainer
|--- ItemContainer
|---Items
Where Item is a container itself containing an image and a text.
In the screen's handleClickEvent() function, I pass down the event when the user is not scrolling with ItemContainer.handleClickEvent(evt), and I was therefore expecting my Item elements to receive the click events but they don't. Why is it so? (Note that the items are ClickListener objects and should normally call a main view callback).
Thanks in advance for your help.
2019-09-12 11:52 PM
Hi, this is because it is difficult to figure out who the recipient should be and what the application should be doing if you simply assume that every child should handle those events. So when you pass the event to the itemContainer, it is the itemcontainer alone that receives the click. You have to distribute it from the itemContainer to the children, or simply to the children directly.
You can also try something like View::handleClickEvent(evt); from MyView::handleClickEvent() - This should propagate the event in the normal way without you having to evaluate who the recipient should be.
/Martin
2019-09-16 04:20 AM
Hej,
I'm not sure to get what's going on but it doesn't work.
void ImgSelectionScreenView::handleClickEvent(const ClickEvent& evt)
{
static int x, y;
/*if (evt.getY() < 50) {
//do smthing else
}
else {
if (evt.getType() == ClickEvent::ClickEventType::PRESSED) {
x = evt.getX();
y = evt.getY();
}
else if (evt.getType() == ClickEvent::ClickEventType::RELEASED) {
if (((abs(x - evt.getX())) < 5) && (abs(y - evt.getY()) < 5)) {
//ItemContainer.handleClickEvent(evt);
View::handleClickEvent(evt);
}
}
}*/
View::handleClickEvent(evt);
}
The uncommented View::handleClickEvent(evt) works juts fine. However, when the function is called from within the if condition, the evt is not propagated anymore…
2019-09-17 01:00 AM
Up (force to do so cuz there seems to be a pb with new msgs as the thread didn't appear updated)
2019-09-17 06:30 AM
Dumb question, but, you're sure you're hitting that line of code in your nested if ?
/Martin
2019-09-18 01:05 AM
Yes, I'm sure.
2019-09-20 12:01 AM
Just to expand a bit on my previous answer, the problem arises only when the released/pressed components of the event are filtered out. That is, when the event is propogated from within an if statement of the type:
if (evt.getType() == ClickEvent::ClickEventType::RELEASED)