Migrate 5 mod Activity subclasses from old polling-based display task pattern to the upstream render() super-class pattern with freeRTOS notification: - EpubReaderBookmarkSelectionActivity - DictionaryWordSelectActivity - DictionarySuggestionsActivity - DictionaryDefinitionActivity - LookedUpWordsActivity Changes: remove own TaskHandle/SemaphoreHandle/updateRequired, use requestUpdate() + render(RenderLock&&) override, fix potential deadlocks around enterNewActivity() calls. Also fix stale conflict marker in EpubReaderMenuActivity.h. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
#pragma once
|
|
#include <Epub/Page.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
|
|
|
class DictionaryWordSelectActivity final : public ActivityWithSubactivity {
|
|
public:
|
|
explicit DictionaryWordSelectActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
std::unique_ptr<Page> page, int fontId, int marginLeft, int marginTop,
|
|
const std::string& cachePath, uint8_t orientation,
|
|
const std::function<void()>& onBack,
|
|
const std::string& nextPageFirstWord = "")
|
|
: ActivityWithSubactivity("DictionaryWordSelect", renderer, mappedInput),
|
|
page(std::move(page)),
|
|
fontId(fontId),
|
|
marginLeft(marginLeft),
|
|
marginTop(marginTop),
|
|
cachePath(cachePath),
|
|
orientation(orientation),
|
|
onBack(onBack),
|
|
nextPageFirstWord(nextPageFirstWord) {}
|
|
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
void render(Activity::RenderLock&&) override;
|
|
|
|
private:
|
|
struct WordInfo {
|
|
std::string text;
|
|
std::string lookupText;
|
|
int16_t screenX;
|
|
int16_t screenY;
|
|
int16_t width;
|
|
int16_t row;
|
|
int continuationIndex;
|
|
int continuationOf;
|
|
WordInfo(const std::string& t, int16_t x, int16_t y, int16_t w, int16_t r)
|
|
: text(t), lookupText(t), screenX(x), screenY(y), width(w), row(r), continuationIndex(-1), continuationOf(-1) {}
|
|
};
|
|
|
|
struct Row {
|
|
int16_t yPos;
|
|
std::vector<int> wordIndices;
|
|
};
|
|
|
|
std::unique_ptr<Page> page;
|
|
int fontId;
|
|
int marginLeft;
|
|
int marginTop;
|
|
std::string cachePath;
|
|
uint8_t orientation;
|
|
const std::function<void()> onBack;
|
|
std::string nextPageFirstWord;
|
|
|
|
std::vector<WordInfo> words;
|
|
std::vector<Row> rows;
|
|
int currentRow = 0;
|
|
int currentWordInRow = 0;
|
|
bool pendingBackFromDef = false;
|
|
bool pendingExitToReader = false;
|
|
|
|
bool isLandscape() const;
|
|
bool isInverted() const;
|
|
void extractWords();
|
|
void mergeHyphenatedWords();
|
|
void drawHints();
|
|
};
|