Review changes
This commit is contained in:
@@ -9,8 +9,6 @@
|
|||||||
#include "components/UITheme.h"
|
#include "components/UITheme.h"
|
||||||
#include "fontIds.h"
|
#include "fontIds.h"
|
||||||
|
|
||||||
const char* const KeyboardEntryActivity::shiftString[2] = {"shift", "SHIFT"};
|
|
||||||
|
|
||||||
void KeyboardEntryActivity::onEnter() {
|
void KeyboardEntryActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
cursorPos = text.length();
|
cursorPos = text.length();
|
||||||
@@ -362,14 +360,16 @@ void KeyboardEntryActivity::loop() {
|
|||||||
void KeyboardEntryActivity::render(RenderLock&&) {
|
void KeyboardEntryActivity::render(RenderLock&&) {
|
||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
const auto pageWidth = renderer.getScreenWidth();
|
const Rect contentRect = UITheme::getContentRect(renderer, true, gpio.deviceIsX3());
|
||||||
const auto pageHeight = renderer.getScreenHeight();
|
const int pageWidth = contentRect.width;
|
||||||
|
const int pageHeight = contentRect.height;
|
||||||
|
const int contentX = contentRect.x;
|
||||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
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 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;
|
metrics.verticalSpacing * 4 + metrics.keyboardVerticalOffset;
|
||||||
int inputHeight = 0;
|
int inputHeight = 0;
|
||||||
|
|
||||||
@@ -392,17 +392,14 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool isPassword = (inputType == InputType::Password);
|
const bool isPassword = (inputType == InputType::Password);
|
||||||
int availableWidth = pageWidth;
|
const int usableWidth = pageWidth;
|
||||||
if (gpio.deviceIsX3()) {
|
const int effectiveMargin = (pageWidth - usableWidth * metrics.keyboardTextFieldWidthPercent / 100) / 2;
|
||||||
availableWidth -= 2 * metrics.sideButtonHintsWidth;
|
|
||||||
}
|
|
||||||
const int effectiveMargin = (pageWidth - availableWidth * metrics.keyboardTextFieldWidthPercent / 100) / 2;
|
|
||||||
const int toggleGap = isPassword ? 4 : 0;
|
const int toggleGap = isPassword ? 4 : 0;
|
||||||
const int toggleReserve = isPassword ? std::max(renderer.getTextWidth(UI_12_FONT_ID, "[abc]"),
|
const int toggleReserve = isPassword ? std::max(renderer.getTextWidth(UI_12_FONT_ID, "[abc]"),
|
||||||
renderer.getTextWidth(UI_12_FONT_ID, "[***]")) +
|
renderer.getTextWidth(UI_12_FONT_ID, "[***]")) +
|
||||||
toggleGap
|
toggleGap
|
||||||
: 0;
|
: 0;
|
||||||
const int textAreaWidth = pageWidth - 2 * effectiveMargin - toggleReserve;
|
const int textAreaWidth = usableWidth - 2 * effectiveMargin - toggleReserve;
|
||||||
const int maxLineWidth = textAreaWidth;
|
const int maxLineWidth = textAreaWidth;
|
||||||
const bool centerText = metrics.keyboardCenteredText;
|
const bool centerText = metrics.keyboardCenteredText;
|
||||||
|
|
||||||
@@ -415,7 +412,7 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
int lineStartIdx = 0;
|
int lineStartIdx = 0;
|
||||||
int lineEndIdx = displayText.length();
|
int lineEndIdx = displayText.length();
|
||||||
int textWidth = 0;
|
int textWidth = 0;
|
||||||
int cursorPixelX = effectiveMargin;
|
int cursorPixelX = contentX + effectiveMargin;
|
||||||
int cursorLineY = inputStartY;
|
int cursorLineY = inputStartY;
|
||||||
bool cursorDrawn = false;
|
bool cursorDrawn = false;
|
||||||
|
|
||||||
@@ -444,16 +441,17 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
kernOffset = beforeAndCursorWidth - beforeWidth - charAdvance;
|
kernOffset = beforeAndCursorWidth - beforeWidth - charAdvance;
|
||||||
}
|
}
|
||||||
if (centerText) {
|
if (centerText) {
|
||||||
cursorPixelX = effectiveMargin + (maxLineWidth - textWidth) / 2 + beforeWidth + kernOffset;
|
cursorPixelX = contentX + effectiveMargin + (maxLineWidth - textWidth) / 2 + beforeWidth + kernOffset;
|
||||||
} else {
|
} else {
|
||||||
cursorPixelX = effectiveMargin + beforeWidth + kernOffset;
|
cursorPixelX = contentX + effectiveMargin + beforeWidth + kernOffset;
|
||||||
}
|
}
|
||||||
cursorLineY = inputStartY + inputHeight;
|
cursorLineY = inputStartY + inputHeight;
|
||||||
cursorDrawn = true;
|
cursorDrawn = true;
|
||||||
isCursorLine = 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) {
|
if (isCursorLine && cursorMode && isPassword && !passwordVisible && !togglePos) {
|
||||||
// Draw text in 3 parts to avoid block cursor overflowing onto next char.
|
// Draw text in 3 parts to avoid block cursor overflowing onto next char.
|
||||||
// displayText uses '*' for all chars; actual char may be wider than '*'.
|
// 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 fieldWidth = (inputHeight > 0) ? maxLineWidth : textWidth;
|
||||||
const int lineMargin = effectiveMargin;
|
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);
|
pageWidth - 2 * lineMargin);
|
||||||
|
|
||||||
if (cursorMode && !togglePos && cursorPos <= displayText.length()) {
|
if (cursorMode && !togglePos && cursorPos <= displayText.length()) {
|
||||||
@@ -510,7 +508,7 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
if (isPassword) {
|
if (isPassword) {
|
||||||
const char* toggleLabel = passwordVisible ? "[***]" : "[abc]";
|
const char* toggleLabel = passwordVisible ? "[***]" : "[abc]";
|
||||||
const int toggleWidth = renderer.getTextWidth(UI_12_FONT_ID, toggleLabel);
|
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 int toggleY = inputStartY + inputHeight;
|
||||||
const bool toggleSelected = cursorMode && togglePos;
|
const bool toggleSelected = cursorMode && togglePos;
|
||||||
|
|
||||||
@@ -553,11 +551,11 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
const int contentCols = getContentColCount();
|
const int contentCols = getContentColCount();
|
||||||
const int keyboardWidth = pageWidth * metrics.keyboardWidthPercent / 100;
|
const int keyboardWidth = pageWidth * metrics.keyboardWidthPercent / 100;
|
||||||
const int keyWidth = (keyboardWidth - (contentCols - 1) * keySpacing) / contentCols;
|
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 bottomRowGap = metrics.keyboardBottomKeySpacing > 0 ? 4 : 0;
|
||||||
const int keyboardStartY = metrics.keyboardBottomAligned
|
const int keyboardStartY = metrics.keyboardBottomAligned
|
||||||
? pageHeight - metrics.buttonHintsHeight - metrics.verticalSpacing -
|
? contentRect.y + pageHeight - metrics.verticalSpacing -
|
||||||
(keyHeight + keySpacing) * getContentRowCount() - bottomKeyHeight -
|
(keyHeight + keySpacing) * getContentRowCount() - bottomKeyHeight -
|
||||||
bottomRowGap + metrics.keyboardVerticalOffset
|
bottomRowGap + metrics.keyboardVerticalOffset
|
||||||
: inputStartY + inputHeight + lineHeight + metrics.verticalSpacing;
|
: inputStartY + inputHeight + lineHeight + metrics.verticalSpacing;
|
||||||
@@ -619,7 +617,7 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
const int contentTotalWidth = COLS * abcKeyWidth + (COLS - 1) * keySpacing;
|
const int contentTotalWidth = COLS * abcKeyWidth + (COLS - 1) * keySpacing;
|
||||||
const int bottomKeyWidth = (contentTotalWidth - (BOTTOM_KEY_COUNT - 1) * bkSpacing) / BOTTOM_KEY_COUNT;
|
const int bottomKeyWidth = (contentTotalWidth - (BOTTOM_KEY_COUNT - 1) * bkSpacing) / BOTTOM_KEY_COUNT;
|
||||||
const int bottomLeftMargin =
|
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;
|
int urlLeftMargin = leftMargin;
|
||||||
if (urlMode) {
|
if (urlMode) {
|
||||||
@@ -676,7 +674,8 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
|||||||
};
|
};
|
||||||
const BottomKeyInfo bottomKeys[BOTTOM_KEY_COUNT] = {
|
const BottomKeyInfo bottomKeys[BOTTOM_KEY_COUNT] = {
|
||||||
{(symMode || urlMode || inputType == InputType::Url) ? KeyboardKeyType::Disabled : KeyboardKeyType::Shift,
|
{(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" : "#@!")},
|
{KeyboardKeyType::Mode, urlMode ? "abc" : (symMode ? "abc" : "#@!")},
|
||||||
{inputType == InputType::Url ? KeyboardKeyType::Mode : KeyboardKeyType::Space,
|
{inputType == InputType::Url ? KeyboardKeyType::Mode : KeyboardKeyType::Space,
|
||||||
inputType == InputType::Url ? "URL" : nullptr},
|
inputType == InputType::Url ? "URL" : nullptr},
|
||||||
|
|||||||
@@ -918,7 +918,7 @@ void BaseTheme::drawKeyboardKey(const GfxRenderer& renderer, Rect rect, const ch
|
|||||||
renderer.drawRect(rect.x, rect.y, rect.width, rect.height);
|
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) {
|
if (keyType == KeyboardKeyType::Space) {
|
||||||
const int lineHalfWidth = rect.width * 3 / 10;
|
const int lineHalfWidth = rect.width * 3 / 10;
|
||||||
|
|||||||
@@ -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);
|
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) {
|
if (keyType == KeyboardKeyType::Space) {
|
||||||
const int lineHalfWidth = rect.width * 3 / 10;
|
const int lineHalfWidth = rect.width * 3 / 10;
|
||||||
|
|||||||
Reference in New Issue
Block a user