New automatic scroll function

This commit is contained in:
Bertrand Songis
2020-03-04 18:06:53 +01:00
parent 65f08451d5
commit 2957e54a04
2 changed files with 20 additions and 12 deletions
+18 -12
View File
@@ -165,23 +165,29 @@ void Window::scrollTo(Window * child)
parent = parent->getParent(); parent = parent->getParent();
} }
coord_t left = offsetX + child->left(); const rect_t rect = {
coord_t right = offsetX + child->right(); offsetX + child->left(),
coord_t top = offsetY + child->top(); offsetY + child->top(),
coord_t bottom = offsetY + child->bottom(); child->width(),
child->height()
};
scrollTo(rect);
}
if (top < scrollPositionY) { void Window::scrollTo(const rect_t & rect)
setScrollPositionY(pageHeight ? top - (top % pageHeight) : top - 5); {
if (rect.top() < scrollPositionY) {
setScrollPositionY(pageHeight ? rect.top() - (rect.top() % pageHeight) : rect.top() - 5);
} }
else if (bottom > scrollPositionY + height() - 5) { else if (rect.bottom() > scrollPositionY + height() - 5) {
setScrollPositionY(pageHeight ? top - (top % pageHeight) : bottom - height() + 5); setScrollPositionY(pageHeight ? rect.top() - (rect.top() % pageHeight) : rect.bottom() - height() + 5);
} }
if (left < scrollPositionX) { if (rect.left() < scrollPositionX) {
setScrollPositionX(pageWidth ? left - (left % pageWidth) : left - 5); setScrollPositionX(pageWidth ? rect.left() - (rect.left() % pageWidth) : rect.left() - 5);
} }
else if (right > scrollPositionX + width() - 5) { else if (rect.right() > scrollPositionX + width() - 5) {
setScrollPositionX(pageWidth ? left - (left % pageWidth) : right - width() + 5); setScrollPositionX(pageWidth ? rect.left() - (rect.left() % pageWidth) : rect.right() - width() + 5);
} }
} }
+2
View File
@@ -144,6 +144,8 @@ class Window {
return focusWindow; return focusWindow;
} }
void scrollTo(const rect_t & rect);
void scrollTo(Window * child); void scrollTo(Window * child);
static void clearFocus(); static void clearFocus();