47 lines
1.6 KiB
C
47 lines
1.6 KiB
C
|
|
#pragma once
|
||
|
|
#include <freertos/FreeRTOS.h>
|
||
|
|
#include <freertos/semphr.h>
|
||
|
|
#include <freertos/task.h>
|
||
|
|
|
||
|
|
#include <functional>
|
||
|
|
|
||
|
|
#include "../Activity.h"
|
||
|
|
|
||
|
|
// Enum for quick menu selection
|
||
|
|
enum class QuickMenuAction { DICTIONARY, ADD_BOOKMARK, CLEAR_CACHE, GO_TO_SETTINGS };
|
||
|
|
|
||
|
|
/**
|
||
|
|
* QuickMenuActivity presents a quick access menu triggered by short power button press.
|
||
|
|
* Options:
|
||
|
|
* - "Dictionary" - Look up a word
|
||
|
|
* - "Add/Remove Bookmark" - Toggle bookmark on current page
|
||
|
|
*
|
||
|
|
* The onActionSelected callback is called with the user's choice.
|
||
|
|
* The onCancel callback is called if the user presses back.
|
||
|
|
*/
|
||
|
|
class QuickMenuActivity final : public Activity {
|
||
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
||
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
||
|
|
int selectedIndex = 0;
|
||
|
|
bool updateRequired = false;
|
||
|
|
const std::function<void(QuickMenuAction)> onActionSelected;
|
||
|
|
const std::function<void()> onCancel;
|
||
|
|
const bool isPageBookmarked; // True if current page already has a bookmark
|
||
|
|
|
||
|
|
static void taskTrampoline(void* param);
|
||
|
|
[[noreturn]] void displayTaskLoop();
|
||
|
|
void render() const;
|
||
|
|
|
||
|
|
public:
|
||
|
|
explicit QuickMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||
|
|
const std::function<void(QuickMenuAction)>& onActionSelected,
|
||
|
|
const std::function<void()>& onCancel, bool isPageBookmarked = false)
|
||
|
|
: Activity("QuickMenu", renderer, mappedInput),
|
||
|
|
onActionSelected(onActionSelected),
|
||
|
|
onCancel(onCancel),
|
||
|
|
isPageBookmarked(isPageBookmarked) {}
|
||
|
|
void onEnter() override;
|
||
|
|
void onExit() override;
|
||
|
|
void loop() override;
|
||
|
|
};
|