From d6612cd61ee5f09b678da8ee1e617a24c0677c75 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 14 Dec 2020 21:15:35 +0100 Subject: [PATCH] Table fixes (when using big tables) --- radio/src/thirdparty/libopenui/src/table.h | 12 ++++-- radio/src/thirdparty/libopenui/src/window.cpp | 42 +++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/table.h b/radio/src/thirdparty/libopenui/src/table.h index 136622ef1..200ea9141 100644 --- a/radio/src/thirdparty/libopenui/src/table.h +++ b/radio/src/thirdparty/libopenui/src/table.h @@ -191,13 +191,19 @@ class Table: public FormField { selection = index; 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 = { 0, - index * TABLE_LINE_HEIGHT, + y, width(), TABLE_LINE_HEIGHT }; - scrollTo(rect); + window->scrollTo(rect); } invalidate(); if (index >= 0) { @@ -288,10 +294,10 @@ class Table: public FormField void setFocus(uint8_t flag) override { + body.setFocus(flag); if (body.selection < 0 && !body.lines.empty()) { select(flag == SET_FOCUS_BACKWARD ? body.lines.size() - 1 : 0); } - body.setFocus(flag); } void select(int index, bool scroll = true) diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 548bbac32..0c76aa00e 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -130,22 +130,21 @@ void Window::setFocus(uint8_t flag) TRACE_WINDOWS("%s setFocus()", getWindowDebugString().c_str()); 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(); focusWindow = this; if (focusHandler) { 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) @@ -176,20 +175,21 @@ void Window::scrollTo(Window * child) coord_t offsetX = 0; coord_t offsetY = 0; - Window * parent = child->getParent(); - while (parent && parent != this) { - offsetX += parent->left(); - offsetY += parent->top(); - parent = parent->getParent(); + Window * parentWindow = child->getParent(); + while (parentWindow && parentWindow != this) { + offsetX += parentWindow->left(); + offsetY += parentWindow->top(); + parentWindow = parentWindow->getParent(); } - const rect_t rect = { - offsetX + child->left(), - offsetY + child->top(), - child->width(), - child->height() + const rect_t scrollRect = { + offsetX + child->left(), + offsetY + child->top(), + min(child->width(), width()), + min(child->height(), height()) }; - scrollTo(rect); + + scrollTo(scrollRect); } void Window::scrollTo(const rect_t & rect)