Use standard themed list

This commit is contained in:
jpirnay
2026-04-15 09:51:09 +02:00
parent 2d69b0fefa
commit 920b3c0b32
2 changed files with 33 additions and 64 deletions
+33 -63
View File
@@ -8,17 +8,6 @@
#include "components/UITheme.h"
#include "fontIds.h"
int StarredPagesActivity::getPageItems() const {
constexpr int lineHeight = 30;
const int screenHeight = renderer.getScreenHeight();
const auto orientation = renderer.getOrientation();
const bool isPortraitInverted = orientation == GfxRenderer::Orientation::PortraitInverted;
const int hintGutterHeight = isPortraitInverted ? 50 : 0;
const int startY = 60 + hintGutterHeight;
const int availableHeight = screenHeight - startY - lineHeight;
return std::max(1, availableHeight / lineHeight);
}
std::string StarredPagesActivity::getDefaultLabel(int index) const {
const auto& bm = bookmarkStore.getAll()[index];
char buf[64];
@@ -76,7 +65,6 @@ void StarredPagesActivity::deleteSelected() {
bookmarkStore.removeAt(selectorIndex);
const int remaining = static_cast<int>(bookmarkStore.getAll().size());
if (remaining == 0) {
// Nothing left — drop back to the reader.
ActivityResult result;
result.isCancelled = true;
setResult(std::move(result));
@@ -89,16 +77,6 @@ void StarredPagesActivity::deleteSelected() {
void StarredPagesActivity::loop() {
const int totalItems = static_cast<int>(bookmarkStore.getAll().size());
const int pageItems = getPageItems();
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
if (totalItems > 0) {
const auto& bm = bookmarkStore.getAll()[selectorIndex];
setResult(StarredPageResult{bm.spineIndex, bm.pageNumber});
finish();
}
return;
}
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
ActivityResult result;
@@ -108,6 +86,15 @@ void StarredPagesActivity::loop() {
return;
}
if (totalItems == 0) return;
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
const auto& bm = bookmarkStore.getAll()[selectorIndex];
setResult(StarredPageResult{bm.spineIndex, bm.pageNumber});
finish();
return;
}
if (mappedInput.wasReleased(MappedInputManager::Button::Left)) {
startRename();
return;
@@ -118,23 +105,24 @@ void StarredPagesActivity::loop() {
return;
}
// Side buttons (Up/Down) drive list navigation; Left/Right are reserved for rename/delete.
buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this, totalItems] {
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false);
buttonNavigator.onNextRelease([this, totalItems] {
selectorIndex = ButtonNavigator::nextIndex(selectorIndex, totalItems);
requestUpdate();
});
buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this, totalItems] {
buttonNavigator.onPreviousRelease([this, totalItems] {
selectorIndex = ButtonNavigator::previousIndex(selectorIndex, totalItems);
requestUpdate();
});
buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, totalItems, pageItems] {
buttonNavigator.onNextContinuous([this, totalItems, pageItems] {
selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, totalItems, pageItems);
requestUpdate();
});
buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, totalItems, pageItems] {
buttonNavigator.onPreviousContinuous([this, totalItems, pageItems] {
selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, totalItems, pageItems);
requestUpdate();
});
@@ -143,48 +131,30 @@ void StarredPagesActivity::loop() {
void StarredPagesActivity::render(RenderLock&&) {
renderer.clearScreen();
const auto& metrics = UITheme::getInstance().getMetrics();
const Rect contentRect = UITheme::getContentRect(renderer, true, true);
GUI.drawHeader(renderer, Rect{contentRect.x, metrics.topPadding, contentRect.width, metrics.headerHeight},
tr(STR_STARRED_PAGES));
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentHeight = contentRect.height - contentTop - metrics.verticalSpacing;
const int totalItems = static_cast<int>(bookmarkStore.getAll().size());
if (totalItems == 0) {
renderer.drawCenteredText(UI_12_FONT_ID, 300, tr(STR_NO_STARRED_PAGES), true, EpdFontFamily::BOLD);
renderer.displayBuffer();
return;
renderer.drawText(UI_10_FONT_ID, contentRect.x + metrics.contentSidePadding, contentTop + 20,
tr(STR_NO_STARRED_PAGES));
} else {
GUI.drawList(renderer, Rect{contentRect.x, contentTop, contentRect.width, contentHeight}, totalItems, selectorIndex,
[this](int index) { return getItemLabel(index); });
}
const auto pageWidth = renderer.getScreenWidth();
const auto orientation = renderer.getOrientation();
const bool isLandscapeCw = orientation == GfxRenderer::Orientation::LandscapeClockwise;
const bool isLandscapeCcw = orientation == GfxRenderer::Orientation::LandscapeCounterClockwise;
const bool isPortraitInverted = orientation == GfxRenderer::Orientation::PortraitInverted;
const int hintGutterWidth = (isLandscapeCw || isLandscapeCcw) ? 30 : 0;
const int contentX = isLandscapeCw ? hintGutterWidth : 0;
const int contentWidth = pageWidth - hintGutterWidth;
const int hintGutterHeight = isPortraitInverted ? 50 : 0;
const int contentY = hintGutterHeight;
const int pageItems = getPageItems();
// Title
const int titleX =
contentX + (contentWidth - renderer.getTextWidth(UI_12_FONT_ID, tr(STR_STARRED_PAGES), EpdFontFamily::BOLD)) / 2;
renderer.drawText(UI_12_FONT_ID, titleX, 15 + contentY, tr(STR_STARRED_PAGES), true, EpdFontFamily::BOLD);
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
// Highlight selection
renderer.fillRect(contentX, 60 + contentY + (selectorIndex % pageItems) * 30 - 2, contentWidth - 1, 30);
for (int i = 0; i < pageItems; i++) {
int itemIndex = pageStartIndex + i;
if (itemIndex >= totalItems) break;
const int displayY = 60 + contentY + i * 30;
const bool isSelected = (itemIndex == selectorIndex);
const std::string label = renderer.truncatedText(UI_10_FONT_ID, getItemLabel(itemIndex).c_str(), contentWidth - 40);
renderer.drawText(UI_10_FONT_ID, contentX + 20, displayY, label.c_str(), !isSelected);
}
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_RENAME), tr(STR_DELETE));
const bool hasItems = totalItems > 0;
const auto labels = mappedInput.mapLabels(tr(STR_BACK), hasItems ? tr(STR_SELECT) : "",
hasItems ? tr(STR_RENAME) : "", hasItems ? tr(STR_DELETE) : "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
GUI.drawSideButtonHints(renderer, tr(STR_DIR_UP), tr(STR_DIR_DOWN));
renderer.displayBuffer();
}
@@ -15,7 +15,6 @@ class StarredPagesActivity final : public Activity {
ButtonNavigator buttonNavigator;
int selectorIndex = 0;
int getPageItems() const;
std::string getItemLabel(int index) const;
std::string getDefaultLabel(int index) const;
void startRename();