Change touch end processing (#45)

1. removed the generic touchedWindow processing
2. replaced it with an implicit capture processing
3. therefore it works like normal in all instances except ListBox() which explicitely captures the up.
This commit is contained in:
Kevin Koenig
2021-12-13 08:39:44 +11:00
committed by GitHub
parent 580849386b
commit f81fa679d7
3 changed files with 14 additions and 28 deletions
+2 -2
View File
@@ -150,8 +150,8 @@ void MainWindow::checkEvents()
touchState.lastDeltaY += SLIDE_SPEED_REDUCTION; touchState.lastDeltaY += SLIDE_SPEED_REDUCTION;
else else
touchState.lastDeltaY = 0; touchState.lastDeltaY = 0;
touchedWindow = nullptr; // this is also an end of a touch so reset the touched window. Fixes scroll and touch bug Window::capturedWindow = nullptr;
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);
} else if (touchState.event == TE_SLIDE_END && slidingWindow == nullptr) { } else if (touchState.event == TE_SLIDE_END && slidingWindow == nullptr) {
+6 -25
View File
@@ -22,7 +22,7 @@
Window * Window::focusWindow = nullptr; Window * Window::focusWindow = nullptr;
Window * Window::slidingWindow = nullptr; Window * Window::slidingWindow = nullptr;
Window * Window::touchedWindow = nullptr; Window * Window::capturedWindow = nullptr;
std::list<Window *> Window::trash; std::list<Window *> Window::trash;
Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags): Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags):
@@ -412,12 +412,6 @@ bool Window::onTouchStart(coord_t x, coord_t y)
auto child = *it; auto child = *it;
if (child->rect.contains(x, y)) { if (child->rect.contains(x, y)) {
if (child->onTouchStart(x - child->rect.x + child->scrollPositionX, y - child->rect.y + child->scrollPositionY)) { 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; return true;
} }
} }
@@ -428,24 +422,11 @@ bool Window::onTouchStart(coord_t x, coord_t y)
bool Window::forwardTouchEnd(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 if (capturedWindow != nullptr)
// forwarded: See on touchstart {
if (touchedWindow != nullptr) { capturedWindow->onTouchEnd(x, y);
auto savedTouchWindow = touchedWindow; capturedWindow = nullptr;
touchedWindow = nullptr; return true;
// 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) { for (auto it = children.rbegin(); it != children.rend(); ++it) {
+6 -1
View File
@@ -321,6 +321,11 @@ class Window
return scrollPositionX; return scrollPositionX;
} }
void captureWindow(Window *window)
{
capturedWindow = window;
}
coord_t getScrollPositionY() const coord_t getScrollPositionY() const
{ {
return scrollPositionY; return scrollPositionY;
@@ -395,7 +400,7 @@ class Window
static Window * focusWindow; static Window * focusWindow;
static Window * slidingWindow; static Window * slidingWindow;
static Window * touchedWindow; static Window * capturedWindow;
static std::list<Window *> trash; static std::list<Window *> trash;
std::function<void()> closeHandler; std::function<void()> closeHandler;