mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 07:07:38 +03:00
refaxtor: keyboard activity
This commit is contained in:
parent
91313d8505
commit
a6b4ed5cf9
@ -138,37 +138,24 @@ void KeyboardEntryActivity::handleKeyPress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardEntryActivity::loop() {
|
void KeyboardEntryActivity::loop() {
|
||||||
// Navigation
|
// Handle navigation
|
||||||
if (mappedInput.wasPressed(MappedInputManager::Button::Up)) {
|
const auto upButtonCallback = [this] {
|
||||||
if (selectedRow > 0) {
|
selectedRow = ButtonNavigator::previousIndex(selectedRow, NUM_ROWS);
|
||||||
selectedRow--;
|
|
||||||
// Clamp column to valid range for new row
|
|
||||||
const int maxCol = getRowLength(selectedRow) - 1;
|
|
||||||
if (selectedCol > maxCol) selectedCol = maxCol;
|
|
||||||
} else {
|
|
||||||
// Wrap to bottom row
|
|
||||||
selectedRow = NUM_ROWS - 1;
|
|
||||||
const int maxCol = getRowLength(selectedRow) - 1;
|
|
||||||
if (selectedCol > maxCol) selectedCol = maxCol;
|
|
||||||
}
|
|
||||||
updateRequired = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mappedInput.wasPressed(MappedInputManager::Button::Down)) {
|
const int maxCol = getRowLength(selectedRow) - 1;
|
||||||
if (selectedRow < NUM_ROWS - 1) {
|
if (selectedCol > maxCol) selectedCol = maxCol;
|
||||||
selectedRow++;
|
|
||||||
const int maxCol = getRowLength(selectedRow) - 1;
|
|
||||||
if (selectedCol > maxCol) selectedCol = maxCol;
|
|
||||||
} else {
|
|
||||||
// Wrap to top row
|
|
||||||
selectedRow = 0;
|
|
||||||
const int maxCol = getRowLength(selectedRow) - 1;
|
|
||||||
if (selectedCol > maxCol) selectedCol = maxCol;
|
|
||||||
}
|
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
};
|
||||||
|
|
||||||
if (mappedInput.wasPressed(MappedInputManager::Button::Left)) {
|
const auto downButtonCallback = [this] {
|
||||||
|
selectedRow = ButtonNavigator::nextIndex(selectedRow, NUM_ROWS);
|
||||||
|
|
||||||
|
const int maxCol = getRowLength(selectedRow) - 1;
|
||||||
|
if (selectedCol > maxCol) selectedCol = maxCol;
|
||||||
|
updateRequired = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto leftButtonCallback = [this] {
|
||||||
const int maxCol = getRowLength(selectedRow) - 1;
|
const int maxCol = getRowLength(selectedRow) - 1;
|
||||||
|
|
||||||
// Special bottom row case
|
// Special bottom row case
|
||||||
@ -187,20 +174,14 @@ void KeyboardEntryActivity::loop() {
|
|||||||
// At done button, move to backspace
|
// At done button, move to backspace
|
||||||
selectedCol = BACKSPACE_COL;
|
selectedCol = BACKSPACE_COL;
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedCol > 0) {
|
|
||||||
selectedCol--;
|
|
||||||
} else {
|
} else {
|
||||||
// Wrap to end of current row
|
selectedCol = ButtonNavigator::previousIndex(selectedCol, maxCol + 1);
|
||||||
selectedCol = maxCol;
|
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mappedInput.wasPressed(MappedInputManager::Button::Right)) {
|
updateRequired = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto rightButtonCallback = [this] {
|
||||||
const int maxCol = getRowLength(selectedRow) - 1;
|
const int maxCol = getRowLength(selectedRow) - 1;
|
||||||
|
|
||||||
// Special bottom row case
|
// Special bottom row case
|
||||||
@ -219,18 +200,28 @@ void KeyboardEntryActivity::loop() {
|
|||||||
// At done button, wrap to beginning of row
|
// At done button, wrap to beginning of row
|
||||||
selectedCol = SHIFT_COL;
|
selectedCol = SHIFT_COL;
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedCol < maxCol) {
|
|
||||||
selectedCol++;
|
|
||||||
} else {
|
} else {
|
||||||
// Wrap to beginning of current row
|
selectedCol = ButtonNavigator::nextIndex(selectedCol, maxCol + 1);
|
||||||
selectedCol = 0;
|
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
constexpr auto upButton = MappedInputManager::Button::Up;
|
||||||
|
constexpr auto downButton = MappedInputManager::Button::Down;
|
||||||
|
constexpr auto leftButton = MappedInputManager::Button::Left;
|
||||||
|
constexpr auto rightButton = MappedInputManager::Button::Right;
|
||||||
|
|
||||||
|
buttonNavigator.onPress({upButton}, upButtonCallback);
|
||||||
|
buttonNavigator.onContinuous({upButton}, upButtonCallback);
|
||||||
|
|
||||||
|
buttonNavigator.onPress({downButton}, downButtonCallback);
|
||||||
|
buttonNavigator.onContinuous({downButton}, downButtonCallback);
|
||||||
|
|
||||||
|
buttonNavigator.onPress({leftButton}, leftButtonCallback);
|
||||||
|
buttonNavigator.onContinuous({leftButton}, leftButtonCallback);
|
||||||
|
|
||||||
|
buttonNavigator.onPress({rightButton}, rightButtonCallback);
|
||||||
|
buttonNavigator.onContinuous({rightButton}, rightButtonCallback);
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "../Activity.h"
|
#include "../Activity.h"
|
||||||
|
#include "util/ButtonNavigator.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reusable keyboard entry activity for text input.
|
* Reusable keyboard entry activity for text input.
|
||||||
@ -65,6 +66,7 @@ class KeyboardEntryActivity : public Activity {
|
|||||||
bool isPassword;
|
bool isPassword;
|
||||||
TaskHandle_t displayTaskHandle = nullptr;
|
TaskHandle_t displayTaskHandle = nullptr;
|
||||||
SemaphoreHandle_t renderingMutex = nullptr;
|
SemaphoreHandle_t renderingMutex = nullptr;
|
||||||
|
ButtonNavigator buttonNavigator;
|
||||||
bool updateRequired = false;
|
bool updateRequired = false;
|
||||||
|
|
||||||
// Keyboard state
|
// Keyboard state
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user