Something went wrong. Try again.
A fork of https://github.com/crosspoint-reader/crosspoint-reader
Something went wrong. Try again.
5.2 kB · 226 lines
C
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227#pragma once#include <GfxRenderer.h>
#include <cstdint>#include <functional>#include <string>#include <utility>
#include "../Activity.h"#include "util/ButtonNavigator.h"
struct KeyDef { char primary; char secondary;};
enum class SpecialKeyType { Shift, Mode, Space, Del, Ok };
enum class InputType { Text, Password, Url };
class KeyboardEntryActivity : public Activity { public: explicit KeyboardEntryActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string title = "Enter Text", std::string initialText = "", const size_t maxLength = 0, InputType inputType = InputType::Text) : Activity("KeyboardEntry", renderer, mappedInput), title(std::move(title)), text(std::move(initialText)), maxLength(maxLength), inputType(inputType) {}
void onEnter() override; void onExit() override; void loop() override; void render(RenderLock&&) override;
private: std::string title; std::string text; size_t maxLength; InputType inputType; bool passwordVisible = false;
ButtonNavigator buttonNavigator;
int selectedRow = 0; int selectedCol = 0; int shiftState = 0; bool symMode = false; bool confirmHeld = false; bool confirmLongHandled = false;
bool cursorMode = false; bool togglePos = false; size_t cursorPos = 0; bool upHeld = false; bool upLongHandled = false; bool downHeld = false; bool downLongHandled = false; bool rightHeld = false; bool rightLongHandled = false; size_t savedCursorPos = 0; size_t rightStartCursorPos = 0;
bool urlMode = false; static constexpr int URL_SNIPPET_COUNT = 9; static constexpr const char* const urlSnippets[URL_SNIPPET_COUNT] = { "https://", "www.", ".com", "http://", "192.168.", ".org", "/opds", ":8080", ".net"};
int delPressCount = 0; bool hintVisible = false; unsigned long hintShowTime = 0;
void onComplete(std::string text); void onCancel();
static constexpr uint16_t LONG_PRESS_MS = 500; static constexpr uint16_t DEL_LONG_PRESS_MS = 1500;
static constexpr int COLS = 10; static constexpr int ABC_ROWS = 4; static constexpr int SYM_ROWS = 4; static constexpr int BOTTOM_KEY_COUNT = 5;
static constexpr KeyDef abcLayout[ABC_ROWS][COLS] = { {{'1', '!'}, {'2', '@'}, {'3', '#'}, {'4', '$'}, {'5', '%'}, {'6', '^'}, {'7', '&'}, {'8', '*'}, {'9', '('}, {'0', ')'}}, {{'q', 'Q'}, {'w', 'W'}, {'e', 'E'}, {'r', 'R'}, {'t', 'T'}, {'y', 'Y'}, {'u', 'U'}, {'i', 'I'}, {'o', 'O'}, {'p', 'P'}}, {{'a', 'A'}, {'s', 'S'}, {'d', 'D'}, {'f', 'F'}, {'g', 'G'}, {'h', 'H'}, {'j', 'J'}, {'k', 'K'}, {'l', 'L'}, {'-', '_'}}, {{'z', 'Z'}, {'x', 'X'}, {'c', 'C'}, {'v', 'V'}, {'b', 'B'}, {'n', 'N'}, {'m', 'M'}, {'=', '+'}, {'.', '>'}, {',', '<'}}, };
static constexpr KeyDef urlLayout[ABC_ROWS][COLS] = { {{'1', '!'}, {'2', '@'}, {'3', '#'}, {'4', '$'}, {'5', '%'}, {'6', '^'}, {'7', '&'}, {'8', '*'}, {'9', '('}, {'0', ')'}}, {{'q', 'Q'}, {'w', 'W'}, {'e', 'E'}, {'r', 'R'}, {'t', 'T'}, {'y', 'Y'}, {'u', 'U'}, {'i', 'I'}, {'o', 'O'}, {'p', 'P'}}, {{'a', 'A'}, {'s', 'S'}, {'d', 'D'}, {'f', 'F'}, {'g', 'G'}, {'h', 'H'}, {'j', 'J'}, {'k', 'K'}, {'l', 'L'}, {'-', '_'}}, {{'z', 'Z'}, {'x', 'X'}, {'c', 'C'}, {'v', 'V'}, {'b', 'B'}, {'n', 'N'}, {'m', 'M'}, {':', '+'}, {'.', '>'}, {'/', '<'}}, };
static constexpr KeyDef symLayout[SYM_ROWS][COLS] = { {{'1', '\0'}, {'2', '\0'}, {'3', '\0'}, {'4', '\0'}, {'5', '\0'}, {'6', '\0'}, {'7', '\0'}, {'8', '\0'}, {'9', '\0'}, {'0', '\0'}}, {{'!', '\0'}, {'@', '\0'}, {'#', '\0'}, {'$', '\0'}, {'%', '\0'}, {'^', '\0'}, {'&', '\0'}, {'*', '\0'}, {'(', '\0'}, {')', '\0'}}, {{'-', '\0'}, {'_', '\0'}, {'=', '\0'}, {'+', '\0'}, {'[', '\0'}, {']', '\0'}, {'{', '\0'}, {'}', '\0'}, {';', '\0'}, {':', '\0'}}, {{'\'', '\0'}, {'"', '\0'}, {'/', '\0'}, {'\\', '\0'}, {'|', '\0'}, {'?', '\0'}, {'.', '\0'}, {',', '\0'}, {'~', '\0'}, {'`', '\0'}}, };
static const char* const shiftString[2];
int getContentRowCount() const; int getContentColCount() const; int getTotalRowCount() const; bool isBottomRow(int row) const; char getSelectedChar() const; char getAlternativeChar() const; bool handleKeyPress(); bool insertChar(char c); void insertString(const std::string& str); void mapColContentBottom(int& col, bool goingUp) const;};