New automatic scroll function
This commit is contained in:
+18
-12
@@ -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
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user