crosspoint-reader/src/activities/dictionary/DictionaryMenuActivity.h

46 lines
1.6 KiB
C
Raw Normal View History

2026-01-22 12:42:01 -05:00
#pragma once
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include <functional>
#include "../Activity.h"
// Enum for dictionary mode selection
enum class DictionaryMode { ENTER_WORD, SELECT_FROM_SCREEN };
/**
* DictionaryMenuActivity presents the user with a choice:
* - "Enter a Word" - Manually type a word to look up
* - "Select from Screen" - Select a word from the current page
*
* The onModeSelected callback is called with the user's choice.
* The onCancel callback is called if the user presses back.
*/
class DictionaryMenuActivity final : public Activity {
TaskHandle_t displayTaskHandle = nullptr;
SemaphoreHandle_t renderingMutex = nullptr;
int selectedIndex = 0;
bool updateRequired = false;
const std::function<void(DictionaryMode)> onModeSelected;
const std::function<void()> onCancel;
const bool wordSelectionAvailable; // True if we can select from screen (e.g., in EPUB reader)
static void taskTrampoline(void* param);
[[noreturn]] void displayTaskLoop();
void render() const;
public:
explicit DictionaryMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void(DictionaryMode)>& onModeSelected,
const std::function<void()>& onCancel, bool wordSelectionAvailable = true)
: Activity("DictionaryMenu", renderer, mappedInput),
onModeSelected(onModeSelected),
onCancel(onCancel),
wordSelectionAvailable(wordSelectionAvailable) {}
void onEnter() override;
void onExit() override;
void loop() override;
};