This PR unifies navigation handling & adds system-wide support for continuous navigation. ## Summary Holding down a navigation button now continuously advances through items until the button is released. This removes the need for repeated press-and-release actions and makes navigation faster and smoother, especially in long menus or documents. When page-based navigation is available, it will navigate through pages. If not, it will progress through menu items or similar list-based UI elements. Additionally, this PR fixes inconsistencies in wrap-around behavior and navigation index calculations. Places where the navigation system was updated: - Home Page - Settings Pages - My Library Page - WiFi Selection Page - OPDS Browser Page - Keyboard - File Transfer Page - XTC Chapter Selector Page - EPUB Chapter Selector Page I’ve tested this on the device as much as possible and tried to match the existing behavior. Please let me know if I missed anything. Thanks 🙏  --- Following the request from @osteotek and @daveallie for system-wide support, the old PR (#379) has been closed in favor of this consolidated, system-wide implementation. --- ### AI Usage Did you use AI tools to help write this code? _**PARTIALLY**_ --------- Co-authored-by: Dave Allie <dave@daveallie.com>
67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
#pragma once
|
|
#include <Epub.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
|
#include "util/ButtonNavigator.h"
|
|
|
|
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
|
public:
|
|
// Menu actions available from the reader menu.
|
|
enum class MenuAction { SELECT_CHAPTER, GO_TO_PERCENT, ROTATE_SCREEN, GO_HOME, SYNC, DELETE_CACHE };
|
|
|
|
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
|
const int currentPage, const int totalPages, const int bookProgressPercent,
|
|
const uint8_t currentOrientation, const std::function<void(uint8_t)>& onBack,
|
|
const std::function<void(MenuAction)>& onAction)
|
|
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
|
title(title),
|
|
pendingOrientation(currentOrientation),
|
|
currentPage(currentPage),
|
|
totalPages(totalPages),
|
|
bookProgressPercent(bookProgressPercent),
|
|
onBack(onBack),
|
|
onAction(onAction) {}
|
|
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
|
|
private:
|
|
struct MenuItem {
|
|
MenuAction action;
|
|
std::string label;
|
|
};
|
|
|
|
// Fixed menu layout (order matters for up/down navigation).
|
|
const std::vector<MenuItem> menuItems = {
|
|
{MenuAction::SELECT_CHAPTER, "Go to Chapter"}, {MenuAction::ROTATE_SCREEN, "Reading Orientation"},
|
|
{MenuAction::GO_TO_PERCENT, "Go to %"}, {MenuAction::GO_HOME, "Go Home"},
|
|
{MenuAction::SYNC, "Sync Progress"}, {MenuAction::DELETE_CACHE, "Delete Book Cache"}};
|
|
|
|
int selectedIndex = 0;
|
|
bool updateRequired = false;
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
|
ButtonNavigator buttonNavigator;
|
|
std::string title = "Reader Menu";
|
|
uint8_t pendingOrientation = 0;
|
|
const std::vector<const char*> orientationLabels = {"Portrait", "Landscape CW", "Inverted", "Landscape CCW"};
|
|
int currentPage = 0;
|
|
int totalPages = 0;
|
|
int bookProgressPercent = 0;
|
|
|
|
const std::function<void(uint8_t)> onBack;
|
|
const std::function<void(MenuAction)> onAction;
|
|
|
|
static void taskTrampoline(void* param);
|
|
[[noreturn]] void displayTaskLoop();
|
|
void renderScreen();
|
|
};
|