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();
}
coord_t left = offsetX + child->left();
coord_t right = offsetX + child->right();
coord_t top = offsetY + child->top();
coord_t bottom = offsetY + child->bottom();
const rect_t rect = {
offsetX + child->left(),
offsetY + child->top(),
child->width(),
child->height()
};
scrollTo(rect);
}
if (top < scrollPositionY) {
setScrollPositionY(pageHeight ? top - (top % pageHeight) : top - 5);
void Window::scrollTo(const rect_t & rect)
{
if (rect.top() < scrollPositionY) {
setScrollPositionY(pageHeight ? rect.top() - (rect.top() % pageHeight) : rect.top() - 5);
}
else if (bottom > scrollPositionY + height() - 5) {
setScrollPositionY(pageHeight ? top - (top % pageHeight) : bottom - height() + 5);
else if (rect.bottom() > scrollPositionY + height() - 5) {
setScrollPositionY(pageHeight ? rect.top() - (rect.top() % pageHeight) : rect.bottom() - height() + 5);
}
if (left < scrollPositionX) {
setScrollPositionX(pageWidth ? left - (left % pageWidth) : left - 5);
if (rect.left() < scrollPositionX) {
setScrollPositionX(pageWidth ? rect.left() - (rect.left() % pageWidth) : rect.left() - 5);
}
else if (right > scrollPositionX + width() - 5) {
setScrollPositionX(pageWidth ? left - (left % pageWidth) : right - width() + 5);
else if (rect.right() > scrollPositionX + width() - 5) {
setScrollPositionX(pageWidth ? rect.left() - (rect.left() % pageWidth) : rect.right() - width() + 5);
}
}
+2
View File
@@ -144,6 +144,8 @@ class Window {
return focusWindow;
}
void scrollTo(const rect_t & rect);
void scrollTo(Window * child);
static void clearFocus();