Use standard themed list
This commit is contained in:
@@ -8,17 +8,6 @@
|
|||||||
#include "components/UITheme.h"
|
#include "components/UITheme.h"
|
||||||
#include "fontIds.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 {
|
std::string StarredPagesActivity::getDefaultLabel(int index) const {
|
||||||
const auto& bm = bookmarkStore.getAll()[index];
|
const auto& bm = bookmarkStore.getAll()[index];
|
||||||
char buf[64];
|
char buf[64];
|
||||||
@@ -76,7 +65,6 @@ void StarredPagesActivity::deleteSelected() {
|
|||||||
bookmarkStore.removeAt(selectorIndex);
|
bookmarkStore.removeAt(selectorIndex);
|
||||||
const int remaining = static_cast<int>(bookmarkStore.getAll().size());
|
const int remaining = static_cast<int>(bookmarkStore.getAll().size());
|
||||||
if (remaining == 0) {
|
if (remaining == 0) {
|
||||||
// Nothing left — drop back to the reader.
|
|
||||||
ActivityResult result;
|
ActivityResult result;
|
||||||
result.isCancelled = true;
|
result.isCancelled = true;
|
||||||
setResult(std::move(result));
|
setResult(std::move(result));
|
||||||
@@ -89,16 +77,6 @@ void StarredPagesActivity::deleteSelected() {
|
|||||||
|
|
||||||
void StarredPagesActivity::loop() {
|
void StarredPagesActivity::loop() {
|
||||||
const int totalItems = static_cast<int>(bookmarkStore.getAll().size());
|
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)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||||
ActivityResult result;
|
ActivityResult result;
|
||||||
@@ -108,6 +86,15 @@ void StarredPagesActivity::loop() {
|
|||||||
return;
|
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)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Left)) {
|
||||||
startRename();
|
startRename();
|
||||||
return;
|
return;
|
||||||
@@ -118,23 +105,24 @@ void StarredPagesActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Side buttons (Up/Down) drive list navigation; Left/Right are reserved for rename/delete.
|
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false);
|
||||||
buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this, totalItems] {
|
|
||||||
|
buttonNavigator.onNextRelease([this, totalItems] {
|
||||||
selectorIndex = ButtonNavigator::nextIndex(selectorIndex, totalItems);
|
selectorIndex = ButtonNavigator::nextIndex(selectorIndex, totalItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this, totalItems] {
|
buttonNavigator.onPreviousRelease([this, totalItems] {
|
||||||
selectorIndex = ButtonNavigator::previousIndex(selectorIndex, totalItems);
|
selectorIndex = ButtonNavigator::previousIndex(selectorIndex, totalItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, totalItems, pageItems] {
|
buttonNavigator.onNextContinuous([this, totalItems, pageItems] {
|
||||||
selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, totalItems, pageItems);
|
selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, totalItems, pageItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, totalItems, pageItems] {
|
buttonNavigator.onPreviousContinuous([this, totalItems, pageItems] {
|
||||||
selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, totalItems, pageItems);
|
selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, totalItems, pageItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
@@ -143,48 +131,30 @@ void StarredPagesActivity::loop() {
|
|||||||
void StarredPagesActivity::render(RenderLock&&) {
|
void StarredPagesActivity::render(RenderLock&&) {
|
||||||
renderer.clearScreen();
|
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());
|
const int totalItems = static_cast<int>(bookmarkStore.getAll().size());
|
||||||
|
|
||||||
if (totalItems == 0) {
|
if (totalItems == 0) {
|
||||||
renderer.drawCenteredText(UI_12_FONT_ID, 300, tr(STR_NO_STARRED_PAGES), true, EpdFontFamily::BOLD);
|
renderer.drawText(UI_10_FONT_ID, contentRect.x + metrics.contentSidePadding, contentTop + 20,
|
||||||
renderer.displayBuffer();
|
tr(STR_NO_STARRED_PAGES));
|
||||||
return;
|
} 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 bool hasItems = totalItems > 0;
|
||||||
const auto orientation = renderer.getOrientation();
|
const auto labels = mappedInput.mapLabels(tr(STR_BACK), hasItems ? tr(STR_SELECT) : "",
|
||||||
const bool isLandscapeCw = orientation == GfxRenderer::Orientation::LandscapeClockwise;
|
hasItems ? tr(STR_RENAME) : "", hasItems ? tr(STR_DELETE) : "");
|
||||||
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));
|
|
||||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||||
|
GUI.drawSideButtonHints(renderer, tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class StarredPagesActivity final : public Activity {
|
|||||||
ButtonNavigator buttonNavigator;
|
ButtonNavigator buttonNavigator;
|
||||||
int selectorIndex = 0;
|
int selectorIndex = 0;
|
||||||
|
|
||||||
int getPageItems() const;
|
|
||||||
std::string getItemLabel(int index) const;
|
std::string getItemLabel(int index) const;
|
||||||
std::string getDefaultLabel(int index) const;
|
std::string getDefaultLabel(int index) const;
|
||||||
void startRename();
|
void startRename();
|
||||||
|
|||||||
Reference in New Issue
Block a user