From 0491587df8cabadd6a2409095952d8ec0fd71e2c Mon Sep 17 00:00:00 2001 From: pablohc Date: Tue, 14 Apr 2026 23:43:18 +0200 Subject: [PATCH] feat(keyboard): add password mode with toggle, cursor visual improvements, and layout unification --- .../network/WifiSelectionActivity.cpp | 26 +- .../settings/CalibreSettingsActivity.cpp | 6 +- .../settings/KOReaderSettingsActivity.cpp | 38 ++- src/activities/util/KeyboardEntryActivity.cpp | 253 +++++++++++------- src/activities/util/KeyboardEntryActivity.h | 16 +- src/components/themes/BaseTheme.cpp | 60 +++-- src/components/themes/BaseTheme.h | 7 +- src/components/themes/lyra/Lyra3CoversTheme.h | 2 +- src/components/themes/lyra/LyraTheme.cpp | 27 +- src/components/themes/lyra/LyraTheme.h | 9 +- 10 files changed, 278 insertions(+), 166 deletions(-) diff --git a/src/activities/network/WifiSelectionActivity.cpp b/src/activities/network/WifiSelectionActivity.cpp index d4f15315..66eed43f 100644 --- a/src/activities/network/WifiSelectionActivity.cpp +++ b/src/activities/network/WifiSelectionActivity.cpp @@ -220,20 +220,18 @@ void WifiSelectionActivity::selectNetwork(const int index) { // Show password entry state = WifiSelectionState::PASSWORD_ENTRY; // Don't allow screen updates while changing activity - startActivityForResult( - std::make_unique(renderer, mappedInput, tr(STR_ENTER_WIFI_PASSWORD), - "", // No initial text - 64, // Max password length - false // Show password by default (hard keyboard to use) - ), - [this](const ActivityResult& result) { - if (result.isCancelled) { - state = WifiSelectionState::NETWORK_LIST; - } else { - enteredPassword = std::get(result.data).text; - // state will be updated in next loop iteration - } - }); + startActivityForResult(std::make_unique(renderer, mappedInput, tr(STR_ENTER_WIFI_PASSWORD), + "", // No initial text + 64, // Max password length + InputType::Password), + [this](const ActivityResult& result) { + if (result.isCancelled) { + state = WifiSelectionState::NETWORK_LIST; + } else { + enteredPassword = std::get(result.data).text; + // state will be updated in next loop iteration + } + }); } else { // Connect directly for open networks attemptConnection(); diff --git a/src/activities/settings/CalibreSettingsActivity.cpp b/src/activities/settings/CalibreSettingsActivity.cpp index ec635861..24fe2b83 100644 --- a/src/activities/settings/CalibreSettingsActivity.cpp +++ b/src/activities/settings/CalibreSettingsActivity.cpp @@ -52,7 +52,7 @@ void CalibreSettingsActivity::handleSelection() { if (selectedIndex == 0) { // OPDS Server URL startActivityForResult(std::make_unique(renderer, mappedInput, tr(STR_CALIBRE_WEB_URL), - SETTINGS.opdsServerUrl, 127, false), + SETTINGS.opdsServerUrl, 127, InputType::Url), [this](const ActivityResult& result) { if (!result.isCancelled) { const auto& kb = std::get(result.data); @@ -64,7 +64,7 @@ void CalibreSettingsActivity::handleSelection() { } else if (selectedIndex == 1) { // Username startActivityForResult(std::make_unique(renderer, mappedInput, tr(STR_USERNAME), - SETTINGS.opdsUsername, 63, false), + SETTINGS.opdsUsername, 63, InputType::Text), [this](const ActivityResult& result) { if (!result.isCancelled) { const auto& kb = std::get(result.data); @@ -76,7 +76,7 @@ void CalibreSettingsActivity::handleSelection() { } else if (selectedIndex == 2) { // Password startActivityForResult(std::make_unique(renderer, mappedInput, tr(STR_PASSWORD), - SETTINGS.opdsPassword, 63, false), + SETTINGS.opdsPassword, 63, InputType::Password), [this](const ActivityResult& result) { if (!result.isCancelled) { const auto& kb = std::get(result.data); diff --git a/src/activities/settings/KOReaderSettingsActivity.cpp b/src/activities/settings/KOReaderSettingsActivity.cpp index de554e32..44ab333c 100644 --- a/src/activities/settings/KOReaderSettingsActivity.cpp +++ b/src/activities/settings/KOReaderSettingsActivity.cpp @@ -63,7 +63,7 @@ void KOReaderSettingsActivity::onActionSelected(int index) { if (item.nameId == StrId::STR_USERNAME) { startActivityForResult(std::make_unique(renderer, mappedInput, tr(STR_KOREADER_USERNAME), - KOREADER_STORE.getUsername(), 64, false), + KOREADER_STORE.getUsername(), 64, InputType::Text), [this](const ActivityResult& result) { if (!result.isCancelled) { const auto& kb = std::get(result.data); @@ -73,6 +73,40 @@ void KOReaderSettingsActivity::onActionSelected(int index) { }); } else if (item.nameId == StrId::STR_PASSWORD) { startActivityForResult(std::make_unique(renderer, mappedInput, tr(STR_KOREADER_PASSWORD), + KOREADER_STORE.getPassword(), 64, InputType::Password), + [this](const ActivityResult& result) { + if (!result.isCancelled) { + const auto& kb = std::get(result.data); + KOREADER_STORE.setCredentials(KOREADER_STORE.getUsername(), kb.text); + KOREADER_STORE.saveToFile(); + } + }); + } else if (item.nameId == StrId::STR_SYNC_SERVER_URL) { + const std::string currentUrl = KOREADER_STORE.getServerUrl(); + const std::string prefillUrl = currentUrl.empty() ? "https://" : currentUrl; + startActivityForResult( + std::make_unique(renderer, mappedInput, tr(STR_SYNC_SERVER_URL), prefillUrl, 128, InputType::Url), + [this](const ActivityResult& result) { + if (!result.isCancelled) { + const auto& kb = std::get(result.data); + const std::string urlToSave = (kb.text == "https://" || kb.text == "http://") ? "" : kb.text; + KOREADER_STORE.setServerUrl(urlToSave); + KOREADER_STORE.saveToFile(); + } + }); + } else if (item.nameId == StrId::STR_AUTHENTICATE) { + if (!KOREADER_STORE.hasCredentials()) return; + startActivityForResult( + std::make_unique(renderer, mappedInput, KOReaderAuthActivity::Mode::LOGIN), + [](const ActivityResult&) {}); + } else if (item.nameId == StrId::STR_REGISTER) { + if (!KOREADER_STORE.hasCredentials()) return; + startActivityForResult( + std::make_unique(renderer, mappedInput, KOReaderAuthActivity::Mode::REGISTER), + [](const ActivityResult&) {}); + } +} + KOREADER_STORE.getPassword(), 64, true), [this](const ActivityResult& result) { if (!result.isCancelled) { @@ -85,7 +119,7 @@ void KOReaderSettingsActivity::onActionSelected(int index) { const std::string currentUrl = KOREADER_STORE.getServerUrl(); const std::string prefillUrl = currentUrl.empty() ? "https://" : currentUrl; startActivityForResult( - std::make_unique(renderer, mappedInput, tr(STR_SYNC_SERVER_URL), prefillUrl, 128, false), + std::make_unique(renderer, mappedInput, tr(STR_SYNC_SERVER_URL), prefillUrl, 128, InputType::Url), [this](const ActivityResult& result) { if (!result.isCancelled) { const auto& kb = std::get(result.data); diff --git a/src/activities/util/KeyboardEntryActivity.cpp b/src/activities/util/KeyboardEntryActivity.cpp index 36d288c9..7e405567 100644 --- a/src/activities/util/KeyboardEntryActivity.cpp +++ b/src/activities/util/KeyboardEntryActivity.cpp @@ -2,12 +2,12 @@ #include -#include - #include "MappedInputManager.h" #include "components/UITheme.h" #include "fontIds.h" +const char* const KeyboardEntryActivity::shiftString[2] = {"shift", "SHIFT"}; + void KeyboardEntryActivity::onEnter() { Activity::onEnter(); cursorPos = text.length(); @@ -20,15 +20,8 @@ int KeyboardEntryActivity::getContentRowCount() const { return ABC_ROWS; } int KeyboardEntryActivity::getTotalRowCount() const { return getContentRowCount() + 1; } -int KeyboardEntryActivity::getBottomKeyCount() const { return isPassword ? 6 : 5; } - bool KeyboardEntryActivity::isBottomRow(const int row) const { return row == getContentRowCount(); } -const char* KeyboardEntryActivity::getShiftLabel() const { - const StrId labelId = shiftState > 0 ? StrId::STR_SHIFT_CAPS : StrId::STR_SHIFT; - return I18n::getInstance().get(labelId); -} - char KeyboardEntryActivity::getSelectedChar() const { const KeyDef(*layout)[COLS] = symMode ? symLayout : abcLayout; @@ -36,8 +29,7 @@ char KeyboardEntryActivity::getSelectedChar() const { if (selectedCol < 0 || selectedCol >= COLS) return '\0'; const KeyDef& key = layout[selectedRow][selectedCol]; - const bool useSecondary = !symMode && shiftState > 0 && key.secondary != '\0'; - return useSecondary ? key.secondary : key.primary; + return (shiftState > 0 && key.secondary != '\0') ? key.secondary : key.primary; } char KeyboardEntryActivity::getAlternativeChar() const { @@ -64,43 +56,9 @@ bool KeyboardEntryActivity::insertChar(char c) { return true; } -SpecialKeyType KeyboardEntryActivity::getBottomSpecialKey(int index) const { - if (isPassword) { - switch (index) { - case 0: - return SpecShift; - case 1: - return SpecMode; - case 2: - return SpecReveal; - case 3: - return SpecSpace; - case 4: - return SpecDel; - case 5: - default: - return SpecOk; - } - } - - switch (index) { - case 0: - return SpecShift; - case 1: - return SpecMode; - case 2: - return SpecSpace; - case 3: - return SpecDel; - case 4: - default: - return SpecOk; - } -} - bool KeyboardEntryActivity::handleKeyPress() { if (isBottomRow(selectedRow)) { - switch (getBottomSpecialKey(selectedCol)) { + switch (static_cast(selectedCol)) { case SpecShift: if (symMode) return true; shiftState = (shiftState + 1) % 2; @@ -110,16 +68,12 @@ bool KeyboardEntryActivity::handleKeyPress() { int maxRow = getTotalRowCount() - 1; if (selectedRow > maxRow) selectedRow = maxRow; if (isBottomRow(selectedRow)) { - int bottomCount = getBottomKeyCount(); - if (selectedCol >= bottomCount) selectedCol = bottomCount - 1; + if (selectedCol >= BOTTOM_KEY_COUNT) selectedCol = BOTTOM_KEY_COUNT - 1; } else { if (selectedCol >= COLS) selectedCol = COLS - 1; } return true; } - case SpecReveal: - passwordVisible = !passwordVisible; - return true; case SpecSpace: return insertChar(' '); case SpecDel: @@ -163,7 +117,7 @@ void KeyboardEntryActivity::loop() { } else if (!wasBottom && isBottomRow(selectedRow)) { selectedCol = selectedCol / 2; } - int maxCol = isBottomRow(selectedRow) ? getBottomKeyCount() - 1 : COLS - 1; + int maxCol = isBottomRow(selectedRow) ? BOTTOM_KEY_COUNT - 1 : COLS - 1; if (selectedCol > maxCol) selectedCol = maxCol; requestUpdate(); } @@ -174,6 +128,10 @@ void KeyboardEntryActivity::loop() { if (mappedInput.wasPressed(MappedInputManager::Button::Down)) { downHeld = true; if (cursorMode) { + if (cursorPos > text.length()) { + cursorPos = text.length(); + } + passwordVisible = false; cursorMode = false; downLongHandled = true; requestUpdate(); @@ -191,7 +149,7 @@ void KeyboardEntryActivity::loop() { } else if (!wasBottom && isBottomRow(selectedRow)) { selectedCol = selectedCol / 2; } - int maxCol = isBottomRow(selectedRow) ? getBottomKeyCount() - 1 : COLS - 1; + int maxCol = isBottomRow(selectedRow) ? BOTTOM_KEY_COUNT - 1 : COLS - 1; if (selectedCol > maxCol) selectedCol = maxCol; requestUpdate(); } @@ -207,7 +165,7 @@ void KeyboardEntryActivity::loop() { } return; } - int maxCol = isBottomRow(selectedRow) ? getBottomKeyCount() - 1 : COLS - 1; + int maxCol = isBottomRow(selectedRow) ? BOTTOM_KEY_COUNT - 1 : COLS - 1; selectedCol = ButtonNavigator::previousIndex(selectedCol, maxCol + 1); requestUpdate(); }); @@ -217,10 +175,13 @@ void KeyboardEntryActivity::loop() { if (cursorPos < text.length()) { cursorPos++; requestUpdate(); + } else if (cursorPos == text.length() && inputType == InputType::Password) { + cursorPos = text.length() + 1; + requestUpdate(); } return; } - int maxCol = isBottomRow(selectedRow) ? getBottomKeyCount() - 1 : COLS - 1; + int maxCol = isBottomRow(selectedRow) ? BOTTOM_KEY_COUNT - 1 : COLS - 1; selectedCol = ButtonNavigator::nextIndex(selectedCol, maxCol + 1); requestUpdate(); }); @@ -230,6 +191,14 @@ void KeyboardEntryActivity::loop() { confirmLongHandled = false; } + if (confirmHeld && !confirmLongHandled && mappedInput.isPressed(MappedInputManager::Button::Confirm) && + mappedInput.getHeldTime() > DEL_LONG_PRESS_MS && isBottomRow(selectedRow) && selectedCol == SpecDel) { + text.clear(); + cursorPos = 0; + confirmLongHandled = true; + requestUpdate(); + } + if (confirmHeld && !confirmLongHandled && mappedInput.isPressed(MappedInputManager::Button::Confirm) && mappedInput.getHeldTime() > LONG_PRESS_MS) { char alt = getAlternativeChar(); @@ -241,10 +210,14 @@ void KeyboardEntryActivity::loop() { } if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { - if (confirmHeld && !confirmLongHandled) { + if (confirmHeld && !confirmLongHandled && !cursorMode) { if (handleKeyPress()) { requestUpdate(); } + } else if (confirmHeld && !confirmLongHandled && cursorMode && inputType == InputType::Password && + cursorPos > text.length()) { + passwordVisible = !passwordVisible; + requestUpdate(); } confirmHeld = false; confirmLongHandled = false; @@ -261,10 +234,8 @@ void KeyboardEntryActivity::render(RenderLock&&) { const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); const auto& metrics = UITheme::getInstance().getMetrics(); - const Rect contentRect = UITheme::getContentRect(renderer, true, true); - GUI.drawHeader(renderer, Rect{contentRect.x, metrics.topPadding, contentRect.width, metrics.headerHeight}, - title.c_str()); + GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, title.c_str()); const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID); const int inputStartY = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing + @@ -272,12 +243,43 @@ void KeyboardEntryActivity::render(RenderLock&&) { int inputHeight = 0; std::string displayText; - if (isPassword && !passwordVisible) { - displayText = std::string(text.length(), '*'); + if (inputType == InputType::Password && !passwordVisible) { + size_t revealPos; + if (cursorMode) { + revealPos = text.length(); // no reveal in displayText; block draws actual char directly + } else { + revealPos = (text.length() > 0 && cursorPos > 0) ? cursorPos - 1 : 0; + } + displayText = text; + for (size_t i = 0; i < displayText.length(); i++) { + if (i != revealPos) { + displayText[i] = '*'; + } + } } else { displayText = text; } + const bool isPassword = (inputType == InputType::Password); + const int margin = metrics.contentSidePadding; + const int extraMargin = 10; + const int effectiveMargin = margin + extraMargin; + const int toggleGap = isPassword ? 8 : 0; + const int toggleReserve = isPassword ? std::max(renderer.getTextWidth(UI_12_FONT_ID, "[abc]"), + renderer.getTextWidth(UI_12_FONT_ID, "[***]")) + + toggleGap + : 0; + const int textAreaWidth = pageWidth - 2 * effectiveMargin - toggleReserve; + const int maxLineWidth = textAreaWidth; + const bool centerText = metrics.keyboardCenteredText; + + int cursorCharWidth; + if (cursorPos < text.length()) { + cursorCharWidth = renderer.getTextWidth(UI_12_FONT_ID, text.substr(cursorPos, 1).c_str()); + } else { + cursorCharWidth = 6; + } + int lineStartIdx = 0; int lineEndIdx = displayText.length(); int textWidth = 0; @@ -288,25 +290,45 @@ void KeyboardEntryActivity::render(RenderLock&&) { while (true) { std::string lineText = displayText.substr(lineStartIdx, lineEndIdx - lineStartIdx); textWidth = renderer.getTextWidth(UI_12_FONT_ID, lineText.c_str()); - if (textWidth <= pageWidth - 2 * metrics.contentSidePadding) { - if (!cursorDrawn && cursorPos >= lineStartIdx && cursorPos <= lineEndIdx) { - std::string beforeCursor = displayText.substr(lineStartIdx, cursorPos - lineStartIdx); - int beforeWidth = renderer.getTextWidth(UI_12_FONT_ID, beforeCursor.c_str()); - if (metrics.keyboardCenteredText) { - cursorPixelX = (pageWidth - textWidth) / 2 + beforeWidth; + if (textWidth <= maxLineWidth) { + const bool isLastLine = (lineEndIdx == static_cast(displayText.length())); + bool isCursorLine = false; + if (!cursorDrawn && cursorPos >= lineStartIdx && + (isLastLine ? cursorPos <= lineEndIdx : cursorPos < lineEndIdx)) { + std::string beforeCursor; + if (isPassword && !passwordVisible && cursorMode) { + beforeCursor = std::string(cursorPos - lineStartIdx, '*'); } else { - cursorPixelX = metrics.contentSidePadding + beforeWidth; + beforeCursor = displayText.substr(lineStartIdx, cursorPos - lineStartIdx); + } + int beforeWidth = renderer.getTextWidth(UI_12_FONT_ID, beforeCursor.c_str()); + if (centerText) { + cursorPixelX = effectiveMargin + (maxLineWidth - textWidth) / 2 + beforeWidth; + } else { + cursorPixelX = effectiveMargin + beforeWidth; } cursorLineY = inputStartY + inputHeight; cursorDrawn = true; + isCursorLine = true; } - if (metrics.keyboardCenteredText) { - const int centeredX = contentRect.x + (contentRect.width - textWidth) / 2; - renderer.drawText(UI_12_FONT_ID, centeredX, inputStartY + inputHeight, lineText.c_str()); + const int lineStartX = centerText ? effectiveMargin + (maxLineWidth - textWidth) / 2 : effectiveMargin; + if (isCursorLine && cursorMode && isPassword && !passwordVisible) { + // Draw text in 3 parts to avoid block cursor overflowing onto next char. + // displayText uses '*' for all chars; actual char may be wider than '*'. + // Part 1: chars before cursor position + const std::string part1 = displayText.substr(lineStartIdx, cursorPos - lineStartIdx); + renderer.drawText(UI_12_FONT_ID, lineStartX, inputStartY + inputHeight, part1.c_str()); + // Part 2: skip cursor slot (block + actual char drawn later) + // Part 3: chars after cursor position (skip char under cursor), starting at cursorPixelX + cursorCharWidth + const int afterStart = static_cast(cursorPos) + (cursorPos < text.length() ? 1 : 0); + const int afterEnd = lineEndIdx; + if (afterStart < afterEnd) { + const std::string part3 = displayText.substr(afterStart, afterEnd - afterStart); + renderer.drawText(UI_12_FONT_ID, cursorPixelX + cursorCharWidth, inputStartY + inputHeight, part3.c_str()); + } } else { - renderer.drawText(UI_12_FONT_ID, contentRect.x + metrics.contentSidePadding, inputStartY + inputHeight, - lineText.c_str()); + renderer.drawText(UI_12_FONT_ID, lineStartX, inputStartY + inputHeight, lineText.c_str()); } if (lineEndIdx == displayText.length()) { break; @@ -320,18 +342,43 @@ void KeyboardEntryActivity::render(RenderLock&&) { } } - GUI.drawTextField(renderer, Rect{contentRect.x, inputStartY, contentRect.width, inputHeight}, textWidth); + const int fieldWidth = (inputHeight > 0) ? maxLineWidth : textWidth; + const int lineMargin = margin + extraMargin - 5; + GUI.drawTextField(renderer, Rect{0, inputStartY, pageWidth, inputHeight}, fieldWidth, cursorMode, lineMargin, + pageWidth - 2 * lineMargin); - const int cursorCharWidth = renderer.getTextWidth(UI_12_FONT_ID, "_"); - if (cursorMode) { - renderer.fillRect(cursorPixelX, cursorLineY, cursorCharWidth, lineHeight, true); - if (cursorPos < displayText.length()) { - const char buf[2] = {displayText[cursorPos], '\0'}; + if (cursorMode && cursorPos <= displayText.length()) { + static constexpr int blockPadding = 1; + renderer.fillRect(cursorPixelX - blockPadding, cursorLineY, cursorCharWidth + blockPadding * 2, lineHeight, true); + if (cursorPos < text.length()) { + const char buf[2] = {text[cursorPos], '\0'}; renderer.drawText(UI_12_FONT_ID, cursorPixelX, cursorLineY, buf, false); } - } else { - renderer.drawLine(cursorPixelX, cursorLineY + lineHeight - 1, cursorPixelX + cursorCharWidth, - cursorLineY + lineHeight - 1, 2, true); + } else if (!cursorMode && cursorPos <= displayText.length()) { + static constexpr int serifW = 3; + const int cX = cursorPixelX; + const int cY = cursorLineY; + const int cBottom = cursorLineY + lineHeight - 1; + renderer.fillRect(cX, cY, 2, lineHeight, true); + renderer.drawLine(cX - serifW, cY, cX - 1, cY, 2, true); + renderer.drawLine(cX + 1, cY, cX + serifW, cY, 2, true); + renderer.drawLine(cX - serifW, cBottom, cX - 1, cBottom, 2, true); + renderer.drawLine(cX + 1, cBottom, cX + serifW, cBottom, 2, true); + } + + if (isPassword) { + const char* toggleLabel = passwordVisible ? "[***]" : "[abc]"; + const int toggleWidth = renderer.getTextWidth(UI_12_FONT_ID, toggleLabel); + const int toggleX = pageWidth - effectiveMargin - toggleWidth; + const int toggleY = inputStartY + inputHeight; + const bool toggleSelected = cursorMode && cursorPos > text.length(); + + if (toggleSelected) { + renderer.fillRect(toggleX - 2, toggleY, toggleWidth + 5, lineHeight + 3, true); + renderer.drawText(UI_12_FONT_ID, toggleX, toggleY, toggleLabel, false); + } else { + renderer.drawText(UI_12_FONT_ID, toggleX, toggleY, toggleLabel, true); + } } const int keyHeight = metrics.keyboardKeyHeight; @@ -346,6 +393,7 @@ void KeyboardEntryActivity::render(RenderLock&&) { (keyHeight + keySpacing) * getContentRowCount() - bottomKeyHeight - bottomRowGap + metrics.keyboardVerticalOffset : inputStartY + inputHeight + lineHeight + metrics.verticalSpacing; + const KeyDef(*layout)[COLS] = symMode ? symLayout : abcLayout; const int contentRows = getContentRowCount(); @@ -377,27 +425,22 @@ void KeyboardEntryActivity::render(RenderLock&&) { const int bottomRowY = keyboardStartY + contentRows * (keyHeight + keySpacing) + bottomRowGap; const int bkSpacing = metrics.keyboardBottomKeySpacing; const int contentTotalWidth = COLS * keyWidth + (COLS - 1) * keySpacing; - const int bottomKeyCount = getBottomKeyCount(); - const int bottomKeyWidth = (contentTotalWidth - (bottomKeyCount - 1) * bkSpacing) / bottomKeyCount; + const int bottomKeyWidth = (contentTotalWidth - (BOTTOM_KEY_COUNT - 1) * bkSpacing) / BOTTOM_KEY_COUNT; const bool bottomSelected = isBottomRow(selectedRow); struct BottomKeyInfo { KeyboardKeyType themeType; const char* label; }; + const BottomKeyInfo bottomKeys[BOTTOM_KEY_COUNT] = { + {KeyboardKeyType::Shift, symMode ? shiftString[0] : shiftString[shiftState]}, + {KeyboardKeyType::Mode, symMode ? "abc" : "#@!"}, + {KeyboardKeyType::Space, nullptr}, + {KeyboardKeyType::Del, nullptr}, + {KeyboardKeyType::Ok, tr(STR_OK_BUTTON)}, + }; - std::vector bottomKeys; - bottomKeys.reserve(6); - bottomKeys.push_back({KeyboardKeyType::Shift, getShiftLabel()}); - bottomKeys.push_back({KeyboardKeyType::Mode, symMode ? tr(STR_ABC) : "#@!"}); - if (isPassword) { - bottomKeys.push_back({KeyboardKeyType::Reveal, passwordVisible ? tr(STR_HIDE) : tr(STR_SHOW)}); - } - bottomKeys.push_back({KeyboardKeyType::Space, nullptr}); - bottomKeys.push_back({KeyboardKeyType::Del, nullptr}); - bottomKeys.push_back({KeyboardKeyType::Ok, tr(STR_OK_BUTTON)}); - - for (int i = 0; i < bottomKeyCount; i++) { + for (int i = 0; i < BOTTOM_KEY_COUNT; i++) { const int keyX = leftMargin + i * (bottomKeyWidth + bkSpacing); const bool isSelected = bottomSelected && i == selectedCol; @@ -419,7 +462,23 @@ void KeyboardEntryActivity::render(RenderLock&&) { selKeyW = keyWidth; selKeyH = keyHeight; } - renderer.drawRect(selKeyX - 1, selKeyY - 1, selKeyW + 2, selKeyH + 2, 2, true); + if (isBottomRow(selectedRow)) { + GUI.drawKeyboardKey(renderer, Rect{selKeyX, selKeyY, selKeyW, selKeyH}, bottomKeys[selectedCol].label, true, + nullptr, bottomKeys[selectedCol].themeType, true); + } else { + const KeyDef& selKey = layout[selectedRow][selectedCol]; + char selPrimary = selKey.primary; + char selSecondary = selKey.secondary; + if (!symMode && shiftState > 0 && selKey.secondary != '\0') { + selPrimary = selKey.secondary; + selSecondary = selKey.primary; + } + const char selPrimaryBuf[2] = {selPrimary, '\0'}; + const char selSecondaryBuf[2] = {selSecondary, '\0'}; + const bool selShowSecondary = !symMode && selectedRow == 0 && selSecondary != '\0'; + GUI.drawKeyboardKey(renderer, Rect{selKeyX, selKeyY, selKeyW, selKeyH}, selPrimaryBuf, true, + selShowSecondary ? selSecondaryBuf : nullptr, KeyboardKeyType::Normal, true); + } } const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_DIR_LEFT), tr(STR_DIR_RIGHT)); diff --git a/src/activities/util/KeyboardEntryActivity.h b/src/activities/util/KeyboardEntryActivity.h index b811ceb9..76edb7d1 100644 --- a/src/activities/util/KeyboardEntryActivity.h +++ b/src/activities/util/KeyboardEntryActivity.h @@ -14,18 +14,20 @@ struct KeyDef { char secondary; }; -enum SpecialKeyType { SpecShift, SpecMode, SpecReveal, SpecSpace, SpecDel, SpecOk }; +enum SpecialKeyType { SpecShift, SpecMode, SpecSpace, SpecDel, SpecOk }; + +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, const bool isPassword = false) + const size_t maxLength = 0, InputType inputType = InputType::Text) : Activity("KeyboardEntry", renderer, mappedInput), title(std::move(title)), text(std::move(initialText)), maxLength(maxLength), - isPassword(isPassword) {} + inputType(inputType) {} void onEnter() override; void onExit() override; @@ -36,7 +38,7 @@ class KeyboardEntryActivity : public Activity { std::string title; std::string text; size_t maxLength; - bool isPassword; + InputType inputType; bool passwordVisible = false; ButtonNavigator buttonNavigator; @@ -59,10 +61,12 @@ class KeyboardEntryActivity : public Activity { 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] = { {{'0', ')'}, @@ -150,12 +154,10 @@ class KeyboardEntryActivity : public Activity { {'`', '\0'}}, }; - const char* getShiftLabel() const; + static const char* const shiftString[2]; int getContentRowCount() const; int getTotalRowCount() const; - int getBottomKeyCount() const; - SpecialKeyType getBottomSpecialKey(int index) const; bool isBottomRow(int row) const; char getSelectedChar() const; char getAlternativeChar() const; diff --git a/src/components/themes/BaseTheme.cpp b/src/components/themes/BaseTheme.cpp index 863eac45..51d0212f 100644 --- a/src/components/themes/BaseTheme.cpp +++ b/src/components/themes/BaseTheme.cpp @@ -878,40 +878,50 @@ void BaseTheme::drawHelpText(const GfxRenderer& renderer, Rect rect, const char* renderer.drawCenteredText(SMALL_FONT_ID, rect.y, truncatedLabel.c_str()); } -void BaseTheme::drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth) const { +void BaseTheme::drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth, bool cursorMode, + int contentStartX, int contentWidth) const { (void)textWidth; + (void)contentStartX; + (void)contentWidth; const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID); const int bracketHeight = lineHeight; - const int fieldLeft = rect.x + 10; + const int fieldLeft = rect.x + 15; const int fieldRight = rect.x + rect.width - 15; - const int topY = rect.y - 5; - const int bottomY = rect.y + rect.height + lineHeight + 5; + const int topY = rect.y - 7; + const int bottomY = rect.y + rect.height + lineHeight + 7; const int tickLen = bracketHeight / 2; + const int thickness = cursorMode ? 3 : 1; - renderer.drawLine(fieldLeft, topY, fieldLeft, bottomY); - renderer.drawLine(fieldLeft, topY, fieldLeft + tickLen, topY); - renderer.drawLine(fieldLeft, bottomY, fieldLeft + tickLen, bottomY); + renderer.fillRect(fieldLeft, topY, thickness, bottomY - topY + 1, true); + renderer.drawLine(fieldLeft, topY, fieldLeft + tickLen, topY, thickness, true); + renderer.drawLine(fieldLeft, bottomY, fieldLeft + tickLen, bottomY, thickness, true); - renderer.drawLine(fieldRight, topY, fieldRight, bottomY); - renderer.drawLine(fieldRight, topY, fieldRight - tickLen, topY); - renderer.drawLine(fieldRight, bottomY, fieldRight - tickLen, bottomY); + renderer.fillRect(fieldRight - thickness + 1, topY, thickness, bottomY - topY + 1, true); + renderer.drawLine(fieldRight, topY, fieldRight - tickLen, topY, thickness, true); + renderer.drawLine(fieldRight, bottomY, fieldRight - tickLen, bottomY, thickness, true); } void BaseTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const char* label, const bool isSelected, - const char* secondaryLabel, const KeyboardKeyType keyType) const { + const char* secondaryLabel, const KeyboardKeyType keyType, + const bool inactiveSelection) const { if (isSelected) { - renderer.fillRect(rect.x, rect.y, rect.width, rect.height, true); - } else if (keyType == KeyboardKeyType::Shift || keyType == KeyboardKeyType::Mode || - keyType == KeyboardKeyType::Reveal || keyType == KeyboardKeyType::Space || - keyType == KeyboardKeyType::Del || keyType == KeyboardKeyType::Ok) { + if (inactiveSelection) { + renderer.drawRect(rect.x, rect.y, rect.width, rect.height, 2, true); + } else { + renderer.fillRect(rect.x, rect.y, rect.width, rect.height, true); + } + } else if (keyType == KeyboardKeyType::Shift || keyType == KeyboardKeyType::Mode || keyType == KeyboardKeyType::Del || + keyType == KeyboardKeyType::Space || keyType == KeyboardKeyType::Ok) { renderer.drawRect(rect.x, rect.y, rect.width, rect.height); } + const bool invert = isSelected && !inactiveSelection; + if (keyType == KeyboardKeyType::Space) { const int lineHalfWidth = rect.width * 3 / 10; const int centerX = rect.x + rect.width / 2; const int lineY = rect.y + rect.height / 2 + 3; - renderer.drawLine(centerX - lineHalfWidth, lineY, centerX + lineHalfWidth, lineY, 3, !isSelected); + renderer.drawLine(centerX - lineHalfWidth, lineY, centerX + lineHalfWidth, lineY, 3, !invert); return; } @@ -920,28 +930,24 @@ void BaseTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const ch const int centerY = rect.y + rect.height / 2; const int arrowLen = rect.width / 4; const int arrowHead = arrowLen / 2; - renderer.drawLine(centerX - arrowLen / 2, centerY, centerX + arrowLen / 2, centerY, 3, !isSelected); + renderer.drawLine(centerX - arrowLen / 2, centerY, centerX + arrowLen / 2, centerY, 3, !invert); renderer.drawLine(centerX - arrowLen / 2, centerY, centerX - arrowLen / 2 + arrowHead, centerY - arrowHead, 3, - !isSelected); + !invert); renderer.drawLine(centerX - arrowLen / 2, centerY, centerX - arrowLen / 2 + arrowHead, centerY + arrowHead, 3, - !isSelected); + !invert); return; } const bool hasSecondary = secondaryLabel != nullptr && secondaryLabel[0] != '\0'; const int primaryOffset = 0; - const int fontId = (keyType == KeyboardKeyType::Shift || keyType == KeyboardKeyType::Mode || - keyType == KeyboardKeyType::Reveal || keyType == KeyboardKeyType::Ok) - ? UI_10_FONT_ID - : UI_12_FONT_ID; - const int itemWidth = renderer.getTextWidth(fontId, label); + const int itemWidth = renderer.getTextWidth(UI_12_FONT_ID, label); const int textX = rect.x + (rect.width - itemWidth) / 2; - const int textY = rect.y + (rect.height - renderer.getLineHeight(fontId)) / 2 + primaryOffset; + const int textY = rect.y + (rect.height - renderer.getLineHeight(UI_12_FONT_ID)) / 2 + primaryOffset; if (hasSecondary) { const int secWidth = renderer.getTextWidth(SMALL_FONT_ID, secondaryLabel); - renderer.drawText(SMALL_FONT_ID, rect.x + rect.width - secWidth - 1, rect.y, secondaryLabel, !isSelected); + renderer.drawText(SMALL_FONT_ID, rect.x + rect.width - secWidth - 1, rect.y, secondaryLabel, !invert); } - renderer.drawText(fontId, textX, textY, label, !isSelected); + renderer.drawText(UI_12_FONT_ID, textX, textY, label, !invert); } diff --git a/src/components/themes/BaseTheme.h b/src/components/themes/BaseTheme.h index 602f2b24..bb172499 100644 --- a/src/components/themes/BaseTheme.h +++ b/src/components/themes/BaseTheme.h @@ -149,10 +149,11 @@ class BaseTheme { const int pageCount, std::string title, const int paddingBottom = 0, const int textYOffset = 0, const bool isStarred = false) const; virtual void drawHelpText(const GfxRenderer& renderer, Rect rect, const char* label) const; - virtual void drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth) const; + virtual void drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth, bool cursorMode = false, + int contentStartX = 0, int contentWidth = 0) const; virtual void drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const char* label, const bool isSelected, - const char* secondaryLabel = nullptr, - KeyboardKeyType keyType = KeyboardKeyType::Normal) const; + const char* secondaryLabel = nullptr, KeyboardKeyType keyType = KeyboardKeyType::Normal, + bool inactiveSelection = false) const; virtual bool showsFileIcons() const { return false; } // Shared constants and helpers for battery drawing (used by all themes) diff --git a/src/components/themes/lyra/Lyra3CoversTheme.h b/src/components/themes/lyra/Lyra3CoversTheme.h index 958ced5a..b0f3d031 100644 --- a/src/components/themes/lyra/Lyra3CoversTheme.h +++ b/src/components/themes/lyra/Lyra3CoversTheme.h @@ -39,7 +39,7 @@ constexpr ThemeMetrics values = {.batteryWidth = 16, .keyboardBottomKeyHeight = 35, .keyboardBottomKeySpacing = 5, .keyboardBottomAligned = true, - .keyboardCenteredText = true, + .keyboardCenteredText = false, .keyboardVerticalOffset = -7}; } diff --git a/src/components/themes/lyra/LyraTheme.cpp b/src/components/themes/lyra/LyraTheme.cpp index 36fd800b..d51b633e 100644 --- a/src/components/themes/lyra/LyraTheme.cpp +++ b/src/components/themes/lyra/LyraTheme.cpp @@ -790,23 +790,34 @@ void LyraTheme::fillPopupProgress(const GfxRenderer& renderer, const Rect& layou renderer.displayBuffer(HalDisplay::FAST_REFRESH); } -void LyraTheme::drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth) const { +void LyraTheme::drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth, bool cursorMode, + int contentStartX, int contentWidth) const { int lineY = rect.y + rect.height + renderer.getLineHeight(UI_12_FONT_ID) + LyraMetrics::values.verticalSpacing; - int lineW = textWidth + hPaddingInSelection * 2; - renderer.drawLine(rect.x + (rect.width - lineW) / 2, lineY, rect.x + (rect.width + lineW) / 2, lineY, 3); + const int thickness = cursorMode ? 3 : 2; + if (contentWidth > 0) { + renderer.drawLine(rect.x + contentStartX, lineY, rect.x + contentStartX + contentWidth, lineY, thickness, true); + } else { + int lineW = textWidth + hPaddingInSelection * 2; + renderer.drawLine(rect.x + (rect.width - lineW) / 2, lineY, rect.x + (rect.width + lineW) / 2, lineY, thickness, + true); + } } void LyraTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const char* label, const bool isSelected, - const char* secondaryLabel, const KeyboardKeyType keyType) const { + const char* secondaryLabel, const KeyboardKeyType keyType, + const bool inactiveSelection) const { if (isSelected) { - renderer.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, cornerRadius, Color::Black); - } else if (keyType == KeyboardKeyType::Shift || keyType == KeyboardKeyType::Mode || - keyType == KeyboardKeyType::Reveal || keyType == KeyboardKeyType::Del || + if (inactiveSelection) { + renderer.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, cornerRadius, Color::LightGray); + } else { + renderer.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, cornerRadius, Color::Black); + } + } else if (keyType == KeyboardKeyType::Shift || keyType == KeyboardKeyType::Mode || keyType == KeyboardKeyType::Del || keyType == KeyboardKeyType::Space || keyType == KeyboardKeyType::Ok) { renderer.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 1, cornerRadius, true); } - const bool invert = isSelected; + const bool invert = isSelected && !inactiveSelection; if (keyType == KeyboardKeyType::Space) { const int lineHalfWidth = rect.width * 3 / 10; diff --git a/src/components/themes/lyra/LyraTheme.h b/src/components/themes/lyra/LyraTheme.h index 6caf05c4..4ad4b82d 100644 --- a/src/components/themes/lyra/LyraTheme.h +++ b/src/components/themes/lyra/LyraTheme.h @@ -37,7 +37,7 @@ constexpr ThemeMetrics values = {.batteryWidth = 16, .keyboardBottomKeyHeight = 35, .keyboardBottomKeySpacing = 5, .keyboardBottomAligned = true, - .keyboardCenteredText = true, + .keyboardCenteredText = false, .keyboardVerticalOffset = -7}; } @@ -69,10 +69,11 @@ class LyraTheme : public BaseTheme { void drawEmptyRecents(const GfxRenderer& renderer, const Rect rect) const; Rect drawPopup(const GfxRenderer& renderer, const char* message) const override; void fillPopupProgress(const GfxRenderer& renderer, const Rect& layout, const int progress) const override; - void drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth) const override; + void drawTextField(const GfxRenderer& renderer, Rect rect, const int textWidth, bool cursorMode = false, + int contentStartX = 0, int contentWidth = 0) const override; void drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const char* label, const bool isSelected, - const char* secondaryLabel = nullptr, - KeyboardKeyType keyType = KeyboardKeyType::Normal) const override; + const char* secondaryLabel = nullptr, KeyboardKeyType keyType = KeyboardKeyType::Normal, + bool inactiveSelection = false) const override; bool showsFileIcons() const override { return true; } protected: