Skip to content

Commit

Permalink
Refactor scroll marking logic in MenuScreen & MenuRenderer
Browse files Browse the repository at this point in the history
Simplify scroll marking logic by updating functions for hidden items.
  • Loading branch information
forntoh committed Oct 6, 2024
1 parent 93f7368 commit 52a2436
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
14 changes: 3 additions & 11 deletions src/MenuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ void MenuScreen::draw(MenuRenderer* renderer) {
}
}

void MenuScreen::markScroll(uint8_t i, MenuRenderer* renderer) {
if (i == 0 && view > 0) {
renderer->flagHiddenItemsAbove();
} else {
renderer->unsetFlagHiddenItemsAbove();
}
if (i == renderer->maxRows - 1 && (view + renderer->maxRows) < itemCount) {
renderer->flagHiddenItemsBelow();
} else {
renderer->unsetFlagHiddenItemsBelow();
}
void MenuScreen::markScroll(uint8_t index, MenuRenderer* renderer) {
renderer->hasHiddenItemsAbove = index == 0 && view > 0;
renderer->hasHiddenItemsBelow = index == renderer->maxRows - 1 && (view + renderer->maxRows) < itemCount;
}

bool MenuScreen::process(LcdMenu* menu, const unsigned char command) {
Expand Down
8 changes: 0 additions & 8 deletions src/renderer/MenuRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,3 @@ uint8_t MenuRenderer::getMaxRows() const { return maxRows; }
uint8_t MenuRenderer::getMaxCols() const { return maxCols; }

uint8_t MenuRenderer::getActiveRow() const { return activeRow; }

void MenuRenderer::flagHiddenItemsAbove() { hasHiddenItemsAbove = true; }

void MenuRenderer::unsetFlagHiddenItemsAbove() { hasHiddenItemsAbove = false; }

void MenuRenderer::flagHiddenItemsBelow() { hasHiddenItemsBelow = true; }

void MenuRenderer::unsetFlagHiddenItemsBelow() { hasHiddenItemsBelow = false; }
20 changes: 0 additions & 20 deletions src/renderer/MenuRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,6 @@ class MenuRenderer {
* @return the active row.
*/
uint8_t getActiveRow() const;

/**
* @brief Flags that there are hidden items above the current view.
*/
void flagHiddenItemsAbove();

/**
* @brief Unsets the flag indicating hidden items above the current view.
*/
void unsetFlagHiddenItemsAbove();

/**
* @brief Flags that there are hidden items below the current view.
*/
void flagHiddenItemsBelow();

/**
* @brief Unsets the flag indicating hidden items below the current view.
*/
void unsetFlagHiddenItemsBelow();
};

#endif // MENU_RENDERER_H

0 comments on commit 52a2436

Please sign in to comment.