Table fixes (when using big tables)

This commit is contained in:
Bertrand Songis
2020-12-14 21:15:35 +01:00
parent d5444f9467
commit d6612cd61e
2 changed files with 30 additions and 24 deletions
+9 -3
View File
@@ -191,13 +191,19 @@ class Table: public FormField
{ {
selection = index; selection = index;
if (scroll) { if (scroll) {
coord_t y = index * TABLE_LINE_HEIGHT;
Window * window = this;
while (window->getWindowFlags() & FORWARD_SCROLL) {
y += window->top();
window = window->getParent();
}
const rect_t rect = { const rect_t rect = {
0, 0,
index * TABLE_LINE_HEIGHT, y,
width(), width(),
TABLE_LINE_HEIGHT TABLE_LINE_HEIGHT
}; };
scrollTo(rect); window->scrollTo(rect);
} }
invalidate(); invalidate();
if (index >= 0) { if (index >= 0) {
@@ -288,10 +294,10 @@ class Table: public FormField
void setFocus(uint8_t flag) override void setFocus(uint8_t flag) override
{ {
body.setFocus(flag);
if (body.selection < 0 && !body.lines.empty()) { if (body.selection < 0 && !body.lines.empty()) {
select(flag == SET_FOCUS_BACKWARD ? body.lines.size() - 1 : 0); select(flag == SET_FOCUS_BACKWARD ? body.lines.size() - 1 : 0);
} }
body.setFocus(flag);
} }
void select(int index, bool scroll = true) void select(int index, bool scroll = true)
+21 -21
View File
@@ -130,22 +130,21 @@ void Window::setFocus(uint8_t flag)
TRACE_WINDOWS("%s setFocus()", getWindowDebugString().c_str()); TRACE_WINDOWS("%s setFocus()", getWindowDebugString().c_str());
if (focusWindow != this) { if (focusWindow != this) {
// scroll before calling focusHandler so that the window can adjust the scroll position if needed
Window * parent = this->parent;
while (parent && parent->getWindowFlags() & FORWARD_SCROLL) {
parent = parent->parent;
}
if (parent) {
parent->scrollTo(this);
invalidate();
}
clearFocus(); clearFocus();
focusWindow = this; focusWindow = this;
if (focusHandler) { if (focusHandler) {
focusHandler(true); focusHandler(true);
} }
} }
Window * parent = this->parent;
while (parent && parent->getWindowFlags() & FORWARD_SCROLL) {
parent = parent->parent;
}
if (parent) {
parent->scrollTo(this);
invalidate();
}
} }
void Window::setScrollPositionX(coord_t value) void Window::setScrollPositionX(coord_t value)
@@ -176,20 +175,21 @@ void Window::scrollTo(Window * child)
coord_t offsetX = 0; coord_t offsetX = 0;
coord_t offsetY = 0; coord_t offsetY = 0;
Window * parent = child->getParent(); Window * parentWindow = child->getParent();
while (parent && parent != this) { while (parentWindow && parentWindow != this) {
offsetX += parent->left(); offsetX += parentWindow->left();
offsetY += parent->top(); offsetY += parentWindow->top();
parent = parent->getParent(); parentWindow = parentWindow->getParent();
} }
const rect_t rect = { const rect_t scrollRect = {
offsetX + child->left(), offsetX + child->left(),
offsetY + child->top(), offsetY + child->top(),
child->width(), min(child->width(), width()),
child->height() min(child->height(), height())
}; };
scrollTo(rect);
scrollTo(scrollRect);
} }
void Window::scrollTo(const rect_t & rect) void Window::scrollTo(const rect_t & rect)