diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-05-11 23:53:03 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-05-11 23:53:03 +0300 |
commit | 846c9aae0298c65e455213e06e44ec10eed71187 (patch) | |
tree | b42029253762ca25deb00bf9d10cef68daeb660f | |
parent | f644c77d62cb59e162313f01ef48643127341a84 (diff) |
Tidied up display menu code to save flash memory
-rw-r--r-- | src/Display/Menu.cpp | 29 | ||||
-rw-r--r-- | src/Display/MenuItem.cpp | 26 | ||||
-rw-r--r-- | src/Display/MenuItem.h | 16 |
3 files changed, 25 insertions, 46 deletions
diff --git a/src/Display/Menu.cpp b/src/Display/Menu.cpp index 964565a6..15f52a46 100644 --- a/src/Display/Menu.cpp +++ b/src/Display/Menu.cpp @@ -195,9 +195,6 @@ void Menu::ClearMessageBox() noexcept void Menu::Pop() noexcept { - // currentMargin = 0; - lcd.Clear(); - rowOffset = 0; --numNestedMenus; Reload(); } @@ -418,26 +415,8 @@ void Menu::ResetCache() noexcept void Menu::Reload() noexcept { displayingFixedMenu = false; - if (numNestedMenus == 1) - { - currentMargin = 0; - lcd.Clear(); - } - else - { - currentMargin = 0; - const PixelNumber right = lcd.GetNumCols(); - const PixelNumber bottom = lcd.GetNumRows(); - lcd.Clear(currentMargin, currentMargin, bottom, right); - - // Draw the outline - // lcd.Line(currentMargin, currentMargin, bottom, currentMargin, PixelMode::PixelSet); - // lcd.Line(currentMargin, currentMargin, currentMargin, right, PixelMode::PixelSet); - // lcd.Line(bottom, currentMargin, bottom, right, PixelMode::PixelSet); - // lcd.Line(currentMargin, right, bottom, right, PixelMode::PixelSet); - - // currentMargin += InnerMargin; - } + currentMargin = rowOffset = 0; + lcd.Clear(); ResetCache(); displayingErrorMessage = false; @@ -700,12 +679,12 @@ void Menu::DrawAll() noexcept const PixelNumber rightMargin = lcd.GetNumCols() - currentMargin; for (MenuItem *item = selectableItems; item != nullptr; item = item->GetNext()) { - item->Draw(lcd, rightMargin, (item == highlightedItem), rowOffset); + item->Draw(lcd, rightMargin, (item == highlightedItem)); } for (MenuItem *item = unSelectableItems; item != nullptr; item = item->GetNext()) { - item->Draw(lcd, rightMargin, false, rowOffset); + item->Draw(lcd, rightMargin, false); } } diff --git a/src/Display/MenuItem.cpp b/src/Display/MenuItem.cpp index 147fe221..ea3d69f5 100644 --- a/src/Display/MenuItem.cpp +++ b/src/Display/MenuItem.cpp @@ -40,7 +40,7 @@ MenuItem::MenuItem(PixelNumber r, PixelNumber c, PixelNumber w, Alignment a, Fon } // Print the item at the correct place with the correct alignment -void MenuItem::PrintAligned(Lcd& lcd, PixelNumber tOffset, PixelNumber rightMargin) noexcept +void MenuItem::PrintAligned(Lcd& lcd, PixelNumber rightMargin) noexcept { PixelNumber colsToSkip = 0; lcd.SetFont(fontNumber); @@ -58,7 +58,7 @@ void MenuItem::PrintAligned(Lcd& lcd, PixelNumber tOffset, PixelNumber rightMarg } } - lcd.SetCursor(row - tOffset, column); + lcd.SetCursor(row, column); lcd.SetRightMargin(min<PixelNumber>(rightMargin, column + width)); lcd.TextInvert(highlighted); if (colsToSkip != 0) @@ -141,12 +141,12 @@ void TextMenuItem::CorePrint(Lcd& lcd) noexcept lcd.printf("%s", text); } -void TextMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept +void TextMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept { // We ignore the 'highlight' parameter because text items are not selectable if (IsVisible() && (!drawn || itemChanged)) { - PrintAligned(lcd, tOffset, rightMargin); + PrintAligned(lcd, rightMargin); itemChanged = false; drawn = true; } @@ -186,12 +186,12 @@ void ButtonMenuItem::CorePrint(Lcd& lcd) noexcept lcd.WriteSpaces(1); // space at end to allow for highlighting } -void ButtonMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept +void ButtonMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept { if (IsVisible() && (itemChanged || !drawn || highlight != highlighted) && column < lcd.GetNumCols()) { highlighted = highlight; - PrintAligned(lcd, tOffset, rightMargin); + PrintAligned(lcd, rightMargin); itemChanged = false; drawn = true; } @@ -318,7 +318,7 @@ void ValueMenuItem::CorePrint(Lcd& lcd) noexcept } } -void ValueMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept +void ValueMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept { if (IsVisible()) { @@ -494,7 +494,7 @@ void ValueMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, Pixe if (itemChanged || !drawn || (highlight != highlighted)) { highlighted = highlight; - PrintAligned(lcd, tOffset, rightMargin); + PrintAligned(lcd, rightMargin); itemChanged = false; drawn = true; } @@ -764,7 +764,7 @@ unsigned int FilesMenuItem::uListingEntries() const noexcept return bInSubdirectory() ? (1 + m_uHardItemsInDirectory) : m_uHardItemsInDirectory; } -void FilesMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept +void FilesMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept { // The 'highlight' parameter is not used to highlight this item, but it is still used to tell whether this item is selected or not if (!IsVisible()) @@ -818,7 +818,7 @@ void FilesMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, Pixe break; case mounted: - ListFiles(lcd, rightMargin, highlight, tOffset); + ListFiles(lcd, rightMargin, highlight); break; case error: @@ -827,7 +827,7 @@ void FilesMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, Pixe } } -void FilesMenuItem::ListFiles(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept +void FilesMenuItem::ListFiles(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept { lcd.SetFont(fontNumber); lcd.SetRightMargin(rightMargin); @@ -1103,7 +1103,7 @@ ImageMenuItem::ImageMenuItem(PixelNumber r, PixelNumber c, Visibility vis, const fileName.copy(pFileName); } -void ImageMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept +void ImageMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept { if (IsVisible() && (!drawn || itemChanged || highlight != highlighted)) { @@ -1125,7 +1125,7 @@ void ImageMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, Pixe { break; } - lcd.BitmapRow(row - tOffset + irow, column, cols, buffer, highlight); + lcd.BitmapRow(row + irow, column, cols, buffer, highlight); } } } diff --git a/src/Display/MenuItem.h b/src/Display/MenuItem.h index a5d6a383..260a0c6c 100644 --- a/src/Display/MenuItem.h +++ b/src/Display/MenuItem.h @@ -28,7 +28,7 @@ public: static constexpr Visibility AlwaysVisible = 0; // Draw this element on the LCD respecting 'maxWidth' and 'highlight' - virtual void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight, PixelNumber tOffset) noexcept = 0; + virtual void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight) noexcept = 0; // Select this element with a push of the encoder. // If it returns nullptr false go into adjustment mode, if we can adjust the item. @@ -79,7 +79,7 @@ protected: virtual void CorePrint(Lcd& lcd) noexcept { } // Print the item at the correct place with the correct alignment - void PrintAligned(Lcd& lcd, PixelNumber tOffset, PixelNumber rightMargin) noexcept; + void PrintAligned(Lcd& lcd, PixelNumber rightMargin) noexcept; const PixelNumber row, column; PixelNumber width, height; @@ -102,7 +102,7 @@ public: void operator delete(void* p) noexcept { FreelistManager::Release<TextMenuItem>(p); } TextMenuItem(PixelNumber r, PixelNumber c, PixelNumber w, Alignment a, FontNumber fn, Visibility vis, const char *t) noexcept; - void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight, PixelNumber tOffset) noexcept override; + void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight) noexcept override; void UpdateWidthAndHeight(Lcd& lcd) noexcept override; protected: @@ -119,7 +119,7 @@ public: void operator delete(void* p) noexcept { FreelistManager::Release<ButtonMenuItem>(p); } ButtonMenuItem(PixelNumber r, PixelNumber c, PixelNumber w, FontNumber fn, Visibility vis, const char *t, const char *cmd, const char *acFile) noexcept; - void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight, PixelNumber tOffset) noexcept override; + void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight) noexcept override; void UpdateWidthAndHeight(Lcd& lcd) noexcept override; bool Select(const StringRef& cmd) noexcept override; @@ -141,7 +141,7 @@ public: void operator delete(void* p) noexcept { FreelistManager::Release<ValueMenuItem>(p); } ValueMenuItem(PixelNumber r, PixelNumber c, PixelNumber w, Alignment a, FontNumber fn, Visibility vis, bool adj, unsigned int v, unsigned int d) noexcept; - void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight, PixelNumber tOffset) noexcept override; + void Draw(Lcd& lcd, PixelNumber maxWidth, bool highlight) noexcept override; bool Select(const StringRef& cmd) noexcept override; bool CanAdjust() const noexcept override { return true; } bool Adjust(int clicks) noexcept override; @@ -189,7 +189,7 @@ public: void operator delete(void* p) noexcept { FreelistManager::Release<FilesMenuItem>(p); } FilesMenuItem(PixelNumber r, PixelNumber c, PixelNumber w, FontNumber fn, Visibility vis, const char *cmd, const char *dir, const char *acFile, unsigned int nf) noexcept; - void Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept override; + void Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept override; void Enter(bool bForwardDirection) noexcept override; int Advance(int nCounts) noexcept override; bool Select(const StringRef& cmd) noexcept override; @@ -203,7 +203,7 @@ protected: void vResetViewState() noexcept; private: - void ListFiles(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept; + void ListFiles(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept; uint8_t GetDirectoryNesting() const noexcept; const unsigned int numDisplayLines; @@ -238,7 +238,7 @@ public: ImageMenuItem(PixelNumber r, PixelNumber c, Visibility vis, const char *pFileName) noexcept; - void Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept override; + void Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight) noexcept override; void UpdateWidthAndHeight(Lcd& lcd) noexcept override; private: |