64 lines
2.1 KiB
C
64 lines
2.1 KiB
C
|
|
#pragma once
|
||
|
|
#include <freertos/FreeRTOS.h>
|
||
|
|
#include <freertos/semphr.h>
|
||
|
|
#include <freertos/task.h>
|
||
|
|
|
||
|
|
#include <Epub/blocks/TextBlock.h>
|
||
|
|
|
||
|
|
#include <functional>
|
||
|
|
#include <memory>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
#include "../Activity.h"
|
||
|
|
|
||
|
|
/**
|
||
|
|
* DictionaryResultActivity displays a word definition with pagination.
|
||
|
|
* Supports multi-page definitions with navigation and rich text formatting.
|
||
|
|
*/
|
||
|
|
class DictionaryResultActivity final : public Activity {
|
||
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
||
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
||
|
|
bool updateRequired = false;
|
||
|
|
|
||
|
|
const std::string lookupWord; // Named to avoid Arduino's 'word' macro
|
||
|
|
const std::string rawDefinition;
|
||
|
|
const std::function<void()> onBack;
|
||
|
|
const std::function<void()> onSearchAnother;
|
||
|
|
|
||
|
|
// Pagination - each page contains TextBlocks with styled text
|
||
|
|
std::vector<std::vector<std::shared_ptr<TextBlock>>> pages;
|
||
|
|
int currentPage = 0;
|
||
|
|
bool notFound = false;
|
||
|
|
|
||
|
|
static void taskTrampoline(void* param);
|
||
|
|
[[noreturn]] void displayTaskLoop();
|
||
|
|
void render() const;
|
||
|
|
void paginateDefinition();
|
||
|
|
|
||
|
|
public:
|
||
|
|
/**
|
||
|
|
* Constructor
|
||
|
|
* @param renderer Graphics renderer
|
||
|
|
* @param mappedInput Input manager
|
||
|
|
* @param wordToLookup The word that was looked up
|
||
|
|
* @param definition The definition text (HTML will be stripped). Empty = not found.
|
||
|
|
* @param onBack Callback when user wants to go back to book
|
||
|
|
* @param onSearchAnother Callback when user wants to search another word
|
||
|
|
*/
|
||
|
|
explicit DictionaryResultActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||
|
|
const std::string& wordToLookup, const std::string& definition,
|
||
|
|
const std::function<void()>& onBack,
|
||
|
|
const std::function<void()>& onSearchAnother)
|
||
|
|
: Activity("DictionaryResult", renderer, mappedInput),
|
||
|
|
lookupWord(wordToLookup),
|
||
|
|
rawDefinition(definition),
|
||
|
|
onBack(onBack),
|
||
|
|
onSearchAnother(onSearchAnother),
|
||
|
|
notFound(definition.empty()) {}
|
||
|
|
|
||
|
|
void onEnter() override;
|
||
|
|
void onExit() override;
|
||
|
|
void loop() override;
|
||
|
|
};
|