Optimise menu to only redrew necessary parts
This commit is contained in:
parent
0a59564d25
commit
b5dc059b2f
2 changed files with 45 additions and 13 deletions
38
src/Menu.cpp
38
src/Menu.cpp
|
@ -9,6 +9,7 @@ RTC_DATA_ATTR uint8_t Menu::m_numPages = 0;
|
||||||
RTC_DATA_ATTR uint8_t Menu::m_currentPage = 0;
|
RTC_DATA_ATTR uint8_t Menu::m_currentPage = 0;
|
||||||
RTC_DATA_ATTR uint8_t Menu::m_numMenuItemsinCurrentPage = 0;
|
RTC_DATA_ATTR uint8_t Menu::m_numMenuItemsinCurrentPage = 0;
|
||||||
RTC_DATA_ATTR uint8_t Menu::m_currentMenuItem = 0;
|
RTC_DATA_ATTR uint8_t Menu::m_currentMenuItem = 0;
|
||||||
|
RTC_DATA_ATTR uint8_t Menu::m_prevMenuItem = 0;
|
||||||
|
|
||||||
Menu::Menu()
|
Menu::Menu()
|
||||||
{
|
{
|
||||||
|
@ -110,8 +111,22 @@ void Menu::Redraw(bool partialRefresh)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasTitle = false;
|
||||||
|
bool hasBody = false;
|
||||||
|
|
||||||
|
if (m_pages[m_currentPage].title.length() > 0) {
|
||||||
|
hasTitle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_pages[m_currentPage].body.length() > 0) {
|
||||||
|
hasBody = true;
|
||||||
|
}
|
||||||
|
|
||||||
m_display->setFullWindow();
|
m_display->setFullWindow();
|
||||||
|
|
||||||
|
if (!partialRefresh) {
|
||||||
m_display->fillScreen(GxEPD_WHITE);
|
m_display->fillScreen(GxEPD_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_pages.size() > 0) {
|
if (m_pages.size() > 0) {
|
||||||
bool hasTitle = false;
|
bool hasTitle = false;
|
||||||
|
@ -120,10 +135,8 @@ void Menu::Redraw(bool partialRefresh)
|
||||||
uint16_t top = 5;
|
uint16_t top = 5;
|
||||||
|
|
||||||
if (m_pages[m_currentPage].title.length() > 0) {
|
if (m_pages[m_currentPage].title.length() > 0) {
|
||||||
hasTitle = true;
|
|
||||||
|
|
||||||
m_display->setFont(&FreeSansBold9pt7b);
|
|
||||||
m_display->setTextColor(GxEPD_BLACK);
|
m_display->setTextColor(GxEPD_BLACK);
|
||||||
|
m_display->setFont(&FreeSansBold9pt7b);
|
||||||
int16_t x, y;
|
int16_t x, y;
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
|
|
||||||
|
@ -139,8 +152,10 @@ void Menu::Redraw(bool partialRefresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_display->setCursor(x, 15);
|
m_display->setCursor(x, 15);
|
||||||
|
if (!partialRefresh) {
|
||||||
m_display->print(m_pages[m_currentPage].title.c_str());
|
m_display->print(m_pages[m_currentPage].title.c_str());
|
||||||
m_display->drawLine(5, 20, m_display->width() - 10, 20, GxEPD_BLACK);
|
m_display->drawLine(5, 20, m_display->width() - 10, 20, GxEPD_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
top += 35;
|
top += 35;
|
||||||
}
|
}
|
||||||
|
@ -154,9 +169,14 @@ void Menu::Redraw(bool partialRefresh)
|
||||||
m_display->setTextWrap(false);
|
m_display->setTextWrap(false);
|
||||||
m_display->getTextBounds(m_pages[m_currentPage].body.c_str(), 0, 0, &x, &y, &w, &h);
|
m_display->getTextBounds(m_pages[m_currentPage].body.c_str(), 0, 0, &x, &y, &w, &h);
|
||||||
m_display->setCursor(5, top);
|
m_display->setCursor(5, top);
|
||||||
|
|
||||||
|
if (!partialRefresh) {
|
||||||
m_display->print(m_pages[m_currentPage].body.c_str());
|
m_display->print(m_pages[m_currentPage].body.c_str());
|
||||||
|
}
|
||||||
top += h - 5;
|
top += h - 5;
|
||||||
|
if (!partialRefresh) {
|
||||||
m_display->drawLine(5, top, m_display->width() - 10, top, GxEPD_BLACK);
|
m_display->drawLine(5, top, m_display->width() - 10, top, GxEPD_BLACK);
|
||||||
|
}
|
||||||
top += 5;
|
top += 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,19 +185,30 @@ void Menu::Redraw(bool partialRefresh)
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
m_display->getTextBounds(m_pages[m_currentPage].menuItems[i].title.c_str(), 5, top, &x, &y, &w, &h);
|
m_display->getTextBounds(m_pages[m_currentPage].menuItems[i].title.c_str(), 5, top, &x, &y, &w, &h);
|
||||||
|
|
||||||
|
bool draw = false;
|
||||||
|
|
||||||
if (i == m_currentMenuItem) {
|
if (i == m_currentMenuItem) {
|
||||||
m_display->fillRect(5, top, m_display->width() - 15, h + 6, GxEPD_BLACK);
|
m_display->fillRect(5, top, m_display->width() - 15, h + 6, GxEPD_BLACK);
|
||||||
m_display->setTextColor(GxEPD_WHITE);
|
m_display->setTextColor(GxEPD_WHITE);
|
||||||
|
draw = true;
|
||||||
} else {
|
} else {
|
||||||
|
if (!partialRefresh || (m_prevMenuItem != m_currentMenuItem && i == m_prevMenuItem)) {
|
||||||
|
m_display->fillRect(5, top, m_display->width() - 15, h + 6, GxEPD_WHITE);
|
||||||
m_display->setTextColor(GxEPD_BLACK);
|
m_display->setTextColor(GxEPD_BLACK);
|
||||||
|
draw = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (draw) {
|
||||||
m_display->setFont(&FreeSans9pt7b);
|
m_display->setFont(&FreeSans9pt7b);
|
||||||
m_display->setCursor(x, top + 15);
|
m_display->setCursor(x, top + 15);
|
||||||
m_display->print(m_pages[m_currentPage].menuItems[i].title.c_str());
|
m_display->print(m_pages[m_currentPage].menuItems[i].title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
top += h + 5;
|
top += h + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_prevMenuItem = m_currentMenuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_display->display(partialRefresh);
|
m_display->display(partialRefresh);
|
||||||
|
@ -187,6 +218,7 @@ void Menu::Reset()
|
||||||
{
|
{
|
||||||
m_currentPage = 0;
|
m_currentPage = 0;
|
||||||
m_currentMenuItem = 0;
|
m_currentMenuItem = 0;
|
||||||
|
m_prevMenuItem = 0;
|
||||||
m_numPages = m_pages.size();
|
m_numPages = m_pages.size();
|
||||||
|
|
||||||
if (m_numPages) {
|
if (m_numPages) {
|
||||||
|
|
|
@ -45,6 +45,6 @@ private:
|
||||||
|
|
||||||
static RTC_DATA_ATTR WatchyDisplay * m_display;
|
static RTC_DATA_ATTR WatchyDisplay * m_display;
|
||||||
static RTC_DATA_ATTR std::function<void()> m_exitCallback;
|
static RTC_DATA_ATTR std::function<void()> m_exitCallback;
|
||||||
static RTC_DATA_ATTR uint8_t m_numPages, m_currentPage, m_numMenuItemsinCurrentPage, m_currentMenuItem;
|
static RTC_DATA_ATTR uint8_t m_numPages, m_currentPage, m_numMenuItemsinCurrentPage, m_currentMenuItem, m_prevMenuItem;
|
||||||
std::vector<MenuPage> m_pages;
|
std::vector<MenuPage> m_pages;
|
||||||
};
|
};
|
Loading…
Reference in a new issue