sort of working dictionary

This commit is contained in:
cottongin
2026-01-22 12:42:01 -05:00
parent ff22a82563
commit 9493fb1f18
24 changed files with 2887 additions and 11 deletions

View File

@@ -11,6 +11,9 @@
#include "MappedInputManager.h"
#include "RecentBooksStore.h"
#include "ScreenComponents.h"
#include "activities/dictionary/DictionaryMenuActivity.h"
#include "activities/dictionary/DictionarySearchActivity.h"
#include "activities/dictionary/EpubWordSelectionActivity.h"
#include "fontIds.h"
namespace {
@@ -163,6 +166,89 @@ void EpubReaderActivity::loop() {
return;
}
// Dictionary power button press
if (SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::DICTIONARY &&
mappedInput.wasReleased(MappedInputManager::Button::Power)) {
xSemaphoreTake(renderingMutex, portMAX_DELAY);
exitActivity();
enterNewActivity(new DictionaryMenuActivity(
renderer, mappedInput,
[this](DictionaryMode mode) {
// CRITICAL: Cache all needed values BEFORE exitActivity() destroys the lambda's owner
// The lambda is stored in DictionaryMenuActivity, so exitActivity() destroys it
GfxRenderer& cachedRenderer = renderer;
MappedInputManager& cachedMappedInput = mappedInput;
Section* cachedSection = section.get();
SemaphoreHandle_t cachedMutex = renderingMutex;
EpubReaderActivity* self = this;
// Handle dictionary mode selection - exitActivity deletes DictionaryMenuActivity
exitActivity();
if (mode == DictionaryMode::ENTER_WORD) {
// Enter word mode - show keyboard and search
self->enterNewActivity(new DictionarySearchActivity(cachedRenderer, cachedMappedInput,
[self]() {
// On back from dictionary
self->exitActivity();
self->updateRequired = true;
},
"")); // Empty string = show keyboard
} else {
// Select from screen mode - show word selection on current page
if (cachedSection) {
xSemaphoreTake(cachedMutex, portMAX_DELAY);
auto page = cachedSection->loadPageFromSectionFile();
if (page) {
// Get margins for word selection positioning
int orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft;
cachedRenderer.getOrientedViewableTRBL(&orientedMarginTop, &orientedMarginRight, &orientedMarginBottom,
&orientedMarginLeft);
orientedMarginTop += SETTINGS.screenMargin;
orientedMarginLeft += SETTINGS.screenMargin;
// Cache the font ID before creating activity
const int cachedFontId = SETTINGS.getReaderFontId();
self->enterNewActivity(new EpubWordSelectionActivity(
cachedRenderer, cachedMappedInput, std::move(page), cachedFontId, orientedMarginLeft,
orientedMarginTop,
[self](const std::string& selectedWord) {
// Word selected - look it up
self->exitActivity();
self->enterNewActivity(new DictionarySearchActivity(self->renderer, self->mappedInput,
[self]() {
self->exitActivity();
self->updateRequired = true;
},
selectedWord));
},
[self]() {
// Cancelled word selection
self->exitActivity();
self->updateRequired = true;
}));
xSemaphoreGive(cachedMutex);
} else {
xSemaphoreGive(cachedMutex);
self->updateRequired = true;
}
} else {
self->updateRequired = true;
}
}
},
[this]() {
// Cancelled dictionary menu - cache self before exitActivity destroys the lambda
EpubReaderActivity* self = this;
exitActivity();
self->updateRequired = true;
},
section != nullptr)); // Word selection only available if section is loaded
xSemaphoreGive(renderingMutex);
return;
}
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
mappedInput.wasReleased(MappedInputManager::Button::Left);
const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::PageForward) ||