From 113d654d864a9ef33ab10525a0f90719643e73d9 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Tue, 28 Apr 2026 15:33:51 +0200 Subject: [PATCH] Review changes --- src/activities/util/KeyboardEntryActivity.cpp | 43 +++++++++---------- src/components/themes/BaseTheme.cpp | 2 +- src/components/themes/lyra/LyraTheme.cpp | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/activities/util/KeyboardEntryActivity.cpp b/src/activities/util/KeyboardEntryActivity.cpp index 7e5e1a7e..9d6a3285 100644 --- a/src/activities/util/KeyboardEntryActivity.cpp +++ b/src/activities/util/KeyboardEntryActivity.cpp @@ -9,8 +9,6 @@ #include "components/UITheme.h" #include "fontIds.h" -const char* const KeyboardEntryActivity::shiftString[2] = {"shift", "SHIFT"}; - void KeyboardEntryActivity::onEnter() { Activity::onEnter(); cursorPos = text.length(); @@ -362,14 +360,16 @@ void KeyboardEntryActivity::loop() { void KeyboardEntryActivity::render(RenderLock&&) { renderer.clearScreen(); - const auto pageWidth = renderer.getScreenWidth(); - const auto pageHeight = renderer.getScreenHeight(); + const Rect contentRect = UITheme::getContentRect(renderer, true, gpio.deviceIsX3()); + const int pageWidth = contentRect.width; + const int pageHeight = contentRect.height; + const int contentX = contentRect.x; const auto& metrics = UITheme::getInstance().getMetrics(); - GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, title.c_str()); + GUI.drawHeader(renderer, Rect{contentX, 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 + + const int inputStartY = contentRect.y + metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing + metrics.verticalSpacing * 4 + metrics.keyboardVerticalOffset; int inputHeight = 0; @@ -392,17 +392,14 @@ void KeyboardEntryActivity::render(RenderLock&&) { } const bool isPassword = (inputType == InputType::Password); - int availableWidth = pageWidth; - if (gpio.deviceIsX3()) { - availableWidth -= 2 * metrics.sideButtonHintsWidth; - } - const int effectiveMargin = (pageWidth - availableWidth * metrics.keyboardTextFieldWidthPercent / 100) / 2; + const int usableWidth = pageWidth; + const int effectiveMargin = (pageWidth - usableWidth * metrics.keyboardTextFieldWidthPercent / 100) / 2; const int toggleGap = isPassword ? 4 : 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 textAreaWidth = usableWidth - 2 * effectiveMargin - toggleReserve; const int maxLineWidth = textAreaWidth; const bool centerText = metrics.keyboardCenteredText; @@ -415,7 +412,7 @@ void KeyboardEntryActivity::render(RenderLock&&) { int lineStartIdx = 0; int lineEndIdx = displayText.length(); int textWidth = 0; - int cursorPixelX = effectiveMargin; + int cursorPixelX = contentX + effectiveMargin; int cursorLineY = inputStartY; bool cursorDrawn = false; @@ -444,16 +441,17 @@ void KeyboardEntryActivity::render(RenderLock&&) { kernOffset = beforeAndCursorWidth - beforeWidth - charAdvance; } if (centerText) { - cursorPixelX = effectiveMargin + (maxLineWidth - textWidth) / 2 + beforeWidth + kernOffset; + cursorPixelX = contentX + effectiveMargin + (maxLineWidth - textWidth) / 2 + beforeWidth + kernOffset; } else { - cursorPixelX = effectiveMargin + beforeWidth + kernOffset; + cursorPixelX = contentX + effectiveMargin + beforeWidth + kernOffset; } cursorLineY = inputStartY + inputHeight; cursorDrawn = true; isCursorLine = true; } - const int lineStartX = centerText ? effectiveMargin + (maxLineWidth - textWidth) / 2 : effectiveMargin; + const int lineStartX = + contentX + (centerText ? effectiveMargin + (maxLineWidth - textWidth) / 2 : effectiveMargin); if (isCursorLine && cursorMode && isPassword && !passwordVisible && !togglePos) { // Draw text in 3 parts to avoid block cursor overflowing onto next char. // displayText uses '*' for all chars; actual char may be wider than '*'. @@ -485,7 +483,7 @@ void KeyboardEntryActivity::render(RenderLock&&) { const int fieldWidth = (inputHeight > 0) ? maxLineWidth : textWidth; const int lineMargin = effectiveMargin; - GUI.drawTextField(renderer, Rect{0, inputStartY, pageWidth, inputHeight}, fieldWidth, cursorMode, lineMargin, + GUI.drawTextField(renderer, Rect{contentX, inputStartY, pageWidth, inputHeight}, fieldWidth, cursorMode, lineMargin, pageWidth - 2 * lineMargin); if (cursorMode && !togglePos && cursorPos <= displayText.length()) { @@ -510,7 +508,7 @@ void KeyboardEntryActivity::render(RenderLock&&) { 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 toggleX = contentX + pageWidth - effectiveMargin - toggleWidth; const int toggleY = inputStartY + inputHeight; const bool toggleSelected = cursorMode && togglePos; @@ -553,11 +551,11 @@ void KeyboardEntryActivity::render(RenderLock&&) { const int contentCols = getContentColCount(); const int keyboardWidth = pageWidth * metrics.keyboardWidthPercent / 100; const int keyWidth = (keyboardWidth - (contentCols - 1) * keySpacing) / contentCols; - const int leftMargin = (pageWidth - (contentCols * keyWidth + (contentCols - 1) * keySpacing)) / 2; + const int leftMargin = contentX + (pageWidth - (contentCols * keyWidth + (contentCols - 1) * keySpacing)) / 2; const int bottomRowGap = metrics.keyboardBottomKeySpacing > 0 ? 4 : 0; const int keyboardStartY = metrics.keyboardBottomAligned - ? pageHeight - metrics.buttonHintsHeight - metrics.verticalSpacing - + ? contentRect.y + pageHeight - metrics.verticalSpacing - (keyHeight + keySpacing) * getContentRowCount() - bottomKeyHeight - bottomRowGap + metrics.keyboardVerticalOffset : inputStartY + inputHeight + lineHeight + metrics.verticalSpacing; @@ -619,7 +617,7 @@ void KeyboardEntryActivity::render(RenderLock&&) { const int contentTotalWidth = COLS * abcKeyWidth + (COLS - 1) * keySpacing; const int bottomKeyWidth = (contentTotalWidth - (BOTTOM_KEY_COUNT - 1) * bkSpacing) / BOTTOM_KEY_COUNT; const int bottomLeftMargin = - (pageWidth - (BOTTOM_KEY_COUNT * bottomKeyWidth + (BOTTOM_KEY_COUNT - 1) * bkSpacing)) / 2; + contentX + (pageWidth - (BOTTOM_KEY_COUNT * bottomKeyWidth + (BOTTOM_KEY_COUNT - 1) * bkSpacing)) / 2; int urlLeftMargin = leftMargin; if (urlMode) { @@ -676,7 +674,8 @@ void KeyboardEntryActivity::render(RenderLock&&) { }; const BottomKeyInfo bottomKeys[BOTTOM_KEY_COUNT] = { {(symMode || urlMode || inputType == InputType::Url) ? KeyboardKeyType::Disabled : KeyboardKeyType::Shift, - (symMode || urlMode || inputType == InputType::Url) ? shiftString[0] : shiftString[shiftState]}, + (symMode || urlMode || inputType == InputType::Url) ? tr(STR_SHIFT) + : (shiftState == 0 ? tr(STR_SHIFT) : tr(STR_SHIFT_CAPS))}, {KeyboardKeyType::Mode, urlMode ? "abc" : (symMode ? "abc" : "#@!")}, {inputType == InputType::Url ? KeyboardKeyType::Mode : KeyboardKeyType::Space, inputType == InputType::Url ? "URL" : nullptr}, diff --git a/src/components/themes/BaseTheme.cpp b/src/components/themes/BaseTheme.cpp index 11441bcb..27d402ef 100644 --- a/src/components/themes/BaseTheme.cpp +++ b/src/components/themes/BaseTheme.cpp @@ -918,7 +918,7 @@ void BaseTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const ch renderer.drawRect(rect.x, rect.y, rect.width, rect.height); } - const bool invert = isSelected && !inactiveSelection; + const bool invert = isSelected && !inactiveSelection && keyType != KeyboardKeyType::Disabled; if (keyType == KeyboardKeyType::Space) { const int lineHalfWidth = rect.width * 3 / 10; diff --git a/src/components/themes/lyra/LyraTheme.cpp b/src/components/themes/lyra/LyraTheme.cpp index 069e65f7..49b8ac52 100644 --- a/src/components/themes/lyra/LyraTheme.cpp +++ b/src/components/themes/lyra/LyraTheme.cpp @@ -770,7 +770,7 @@ void LyraTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const ch renderer.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 1, cornerRadius, true); } - const bool invert = isSelected && !inactiveSelection; + const bool invert = isSelected && !inactiveSelection && keyType != KeyboardKeyType::Disabled; if (keyType == KeyboardKeyType::Space) { const int lineHalfWidth = rect.width * 3 / 10;