Merge pull request #28 from kevinkoenig/fix-slide-touch

Fix slide touch - merge commit to save grief with another PR
This commit is contained in:
Peter Feerick
2021-10-29 11:33:59 +10:00
committed by GitHub
3 changed files with 31 additions and 3 deletions
+3 -3
View File
@@ -79,9 +79,9 @@ void MainWindow::checkEvents()
touchState.lastDeltaY += SLIDE_SPEED_REDUCTION;
else
touchState.lastDeltaY = 0;
if (touchState.lastDeltaX || touchState.lastDeltaY) {
onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.lastDeltaX, touchState.lastDeltaY);
}
onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.lastDeltaX, touchState.lastDeltaY);
slidingWindow = nullptr;
}
#endif
+27
View File
@@ -22,6 +22,7 @@
Window * Window::focusWindow = nullptr;
Window * Window::slidingWindow = nullptr;
Window * Window::touchedWindow = nullptr;
std::list<Window *> Window::trash;
Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags):
@@ -411,6 +412,12 @@ bool Window::onTouchStart(coord_t x, coord_t y)
auto child = *it;
if (child->rect.contains(x, y)) {
if (child->onTouchStart(x - child->rect.x + child->scrollPositionX, y - child->rect.y + child->scrollPositionY)) {
// remember the first window that processed the touch start event. We will give that window
// the opportunity to process the touchend first, and also after a slide end so the touched window
// always gets a touchEnd if it processed the touch start.
if (touchedWindow == nullptr) {
touchedWindow = child;
}
return true;
}
}
@@ -421,6 +428,26 @@ bool Window::onTouchStart(coord_t x, coord_t y)
bool Window::forwardTouchEnd(coord_t x, coord_t y)
{
// give the touched window the opportunity to process the touch first before it is
// forwarded: See on touchstart
if (touchedWindow != nullptr) {
auto savedTouchWindow = touchedWindow;
touchedWindow = nullptr;
// transalte x and y through the parent hierarchy
auto myParent = savedTouchWindow->parent;
while(myParent != nullptr) {
x = x - myParent->rect.x + myParent->scrollPositionX;
y = y - myParent->rect.y + myParent->scrollPositionY;
myParent = myParent->parent;
}
if (savedTouchWindow->onTouchEnd(
x - savedTouchWindow->rect.x + savedTouchWindow->scrollPositionX,
y - savedTouchWindow->rect.y + savedTouchWindow->scrollPositionY)) {
return true;
}
}
for (auto it = children.rbegin(); it != children.rend(); ++it) {
auto child = *it;
if (child->rect.contains(x, y)) {
+1
View File
@@ -395,6 +395,7 @@ class Window
static Window * focusWindow;
static Window * slidingWindow;
static Window * touchedWindow;
static std::list<Window *> trash;
std::function<void()> closeHandler;