#pragma once #include #include #include #include #include #include #include #include #include "../Activity.h" /** * EpubWordSelectionActivity allows selecting a word from the current EPUB page. * Displays the page with a cursor that can navigate between words. */ class EpubWordSelectionActivity final : public Activity { // Word info for selection struct WordInfo { std::string text; // Named 'text' to avoid Arduino's 'word' macro int16_t x; int16_t y; int16_t width; int16_t height; EpdFontFamily::Style style; }; TaskHandle_t displayTaskHandle = nullptr; SemaphoreHandle_t renderingMutex = nullptr; bool updateRequired = false; const std::unique_ptr page; const int fontId; const int xOffset; const int yOffset; const std::function onWordSelected; const std::function onCancel; // Word navigation state std::vector allWords; int selectedWordIndex = 0; int currentLineIndex = 0; static void taskTrampoline(void* param); [[noreturn]] void displayTaskLoop(); void render() const; void buildWordList(); int findWordIndexForLine(int lineIndex) const; int findLineForWordIndex(int wordIndex) const; public: /** * Constructor * @param renderer Graphics renderer * @param mappedInput Input manager * @param page The current page to select words from (ownership transferred) * @param fontId Font ID used for rendering * @param xOffset X offset for rendering * @param yOffset Y offset for rendering * @param onWordSelected Callback when a word is selected * @param onCancel Callback when selection is cancelled */ explicit EpubWordSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr page, int fontId, int xOffset, int yOffset, const std::function& onWordSelected, const std::function& onCancel) : Activity("EpubWordSelection", renderer, mappedInput), page(std::move(page)), fontId(fontId), xOffset(xOffset), yOffset(yOffset), onWordSelected(onWordSelected), onCancel(onCancel) {} void onEnter() override; void onExit() override; void loop() override; };