setSwallowTouches not working as expected

I have ui::ScrollView with few ui::Buttons inside.

When I touch the button first I can’t use the ScrollView.
setting:
button->setSwallowTouches(false);
should mean touch events will be propagated back to the scrollView (when I touch the button).
But they are not.

Only two things help:

  1. remove button->addTouchEventListener(...)
  2. disable touch in button button->setTouchEnabled(false)

I’ve found a slightly hacky solution to this problem:

Instead of using addTouchEventListener I use addClickEventListener. Then I can scroll and I can click the button. And by the way in this case, if I set setSwallowTouches to true it indeed blocks event propagation.

So the only combination that doesn’t work is:

button->setSwallowTouches(false);

button->addTouchEventListener(...)

I think it’s a bug.

This is definietly a bug!

But I’ve found a solution:

just

button->addTouchEventListener([&, button](Ref* ref, ui::Widget::TouchEventType eventType){
    button->setSwallowTouches(false);
});

if I setSwallowTouches(false) each time when event occurs it works. Without it works only with first touch. That means something is setting button->setSwallowTouches(true) over and over.

Interesting. But why would a button need to swallow touches? You either press it or you don’t.

The button can be a part of more complex node, which can move somehow itself, so you may want to move it (or not), by moving finger over button, depending on swallow touches mode.

1 Like

I see. That actually makes sense. I guess I never use buttons like this.

Yeah, I have a scrollView with many buttons inside. Then swallowTouches is false I should be able to click the button as well as use a scrollView. Not sure why I have to setSwallowTouches(false) over and over to make this working as expected.