Skip to content

Commit

Permalink
Feat/multitouch clicks (#315)
Browse files Browse the repository at this point in the history
* non blocking clicks views

* docs fix
  • Loading branch information
IlyaZavalov committed Jul 26, 2024
1 parent 948b5a0 commit cbf564c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
7 changes: 6 additions & 1 deletion aui.views/src/AUI/Platform/ABaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,13 @@ void ABaseWindow::onPointerReleased(const APointerReleasedEvent& event) {
AWindow::getWindowManager().watchdog().runOperation([&] {
#endif
APointerReleasedEvent copy = event;
auto nonBlockingClicksPointers = std::count_if(pointerEventsMapping().begin(), pointerEventsMapping().end(),
[](const auto &event) {
return !event.isBlockClicksWhenPressed;
});
// in case of multitouch, we should not treat pointer release event as a click.
copy.triggerClick = pointerEventsMapping().size() < 2 && !mPreventClickOnPointerRelease.valueOr(true);
copy.triggerClick = pointerEventsMapping().size() - nonBlockingClicksPointers < 2 &&
!mPreventClickOnPointerRelease.valueOr(true);
mPreventClickOnPointerRelease.reset();

#if AUI_SHOW_TOUCHES
Expand Down
14 changes: 14 additions & 0 deletions aui.views/src/AUI/View/AView.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ class API_AUI_VIEWS AView: public AObject
*/
bool mMouseEntered = false;

/**
* @brief Determines if pressing the view allows triggering click on other views
* @note By default on mobile platforms AUI will block clicks if there more than one pointer on screen,
* if this flag is set to false, allows to click on others views without releasing pointer from this view
*/
bool mBlockClicksWhenPressed = true;

protected:
/**
* @brief Parent AView.
Expand Down Expand Up @@ -631,6 +638,13 @@ class API_AUI_VIEWS AView: public AObject
setGeometry(position.x, position.y, size.x, size.y);
}

bool isBlockClicksWhenPressed() const noexcept {
return mBlockClicksWhenPressed;
}

void setBlockClicksWhenPressed(bool value) noexcept {
mBlockClicksWhenPressed = value;
}

/**
* @brief Fixed size.
Expand Down
14 changes: 13 additions & 1 deletion aui.views/src/AUI/View/AViewContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ void AViewContainer::onPointerPressed(const APointerPressedEvent& event) {

auto p = getViewAt(event.position);
if (p && p->isEnabled()) {
mPointerEventsMapping.push_back({event.pointerIndex, p});
mPointerEventsMapping.push_back({event.pointerIndex, p, isBlockClicksWhenPressed() && p->isBlockClicksWhenPressed()});
auto& pointerEvent = mPointerEventsMapping.back();
pointerEvent.isBlockClicksWhenPressed &= isBlockClicksWhenPressed();
if (p->capturesFocus()) {
p->focus(false);

Expand All @@ -253,6 +255,16 @@ void AViewContainer::onPointerPressed(const APointerPressedEvent& event) {
auto copy = event;
copy.position -= p->getPosition();
p->onPointerPressed(copy);
pointerEvent.isBlockClicksWhenPressed &= p->isBlockClicksWhenPressed();
if (auto parent = getParent(); parent && !pointerEvent.isBlockClicksWhenPressed) {
auto it = std::find_if(parent->mPointerEventsMapping.begin(), parent->mPointerEventsMapping.end(),
[&](const auto &parentPointerEvent) {
return parentPointerEvent.pointerIndex == pointerEvent.pointerIndex;
});
if (it != parent->mPointerEventsMapping.end()) {
it->isBlockClicksWhenPressed = false;
}
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions aui.views/src/AUI/View/AViewContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class API_AUI_VIEWS AViewContainer : public AView {
struct PointerEventsMapping {
APointerIndex pointerIndex;
_weak<AView> targetView;
/**
* @brief true if the view or any child (direct or indirect) of the view blocks clicks when pressed
* @see mBlockClicksWhenPressed
*/
bool isBlockClicksWhenPressed = true;
};

AViewContainer();
Expand Down

0 comments on commit cbf564c

Please sign in to comment.