mirror of
https://github.com/crosspoint-reader/crosspoint-reader.git
synced 2026-04-29 10:26:52 -07:00
## Summary
* **What is the goal of this PR?**
Fix the visual keyboard cursor not advancing when typing a space. Typing
one space leaves the cursor at position 0; typing two spaces advances it
only by one space width. This affects all input types except URL.
* **What changes are included?**
Replace `getTextWidth()` with `getTextAdvanceX()` in four locations
within `KeyboardEntryActivity::render()` for cursor positioning and
line-wrapping calculations.
## Additional Context
* **Root cause**: `getTextWidth()` returns the bounding-box width of the
drawn glyphs. The space glyph has `width=0` and `height=0` (it's
invisible), so `getTextWidth(" ") == 0`. The trailing `advanceX` of the
last character is only flushed when the *next* character is processed,
so a string ending in space reports zero width. `getTextAdvanceX()`
correctly includes the final glyph's advance, matching how `drawText()`
actually positions characters.
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**YES**_
This commit is contained in:
@@ -421,7 +421,7 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
||||
|
||||
while (true) {
|
||||
std::string lineText = displayText.substr(lineStartIdx, lineEndIdx - lineStartIdx);
|
||||
textWidth = renderer.getTextWidth(UI_12_FONT_ID, lineText.c_str());
|
||||
textWidth = renderer.getTextAdvanceX(UI_12_FONT_ID, lineText.c_str(), EpdFontFamily::REGULAR);
|
||||
if (textWidth <= maxLineWidth) {
|
||||
const bool isLastLine = (lineEndIdx == static_cast<int>(displayText.length()));
|
||||
bool isCursorLine = false;
|
||||
@@ -433,12 +433,14 @@ void KeyboardEntryActivity::render(RenderLock&&) {
|
||||
} else {
|
||||
beforeCursor = displayText.substr(lineStartIdx, cursorPos - lineStartIdx);
|
||||
}
|
||||
int beforeWidth = renderer.getTextWidth(UI_12_FONT_ID, beforeCursor.c_str());
|
||||
int beforeWidth = renderer.getTextAdvanceX(UI_12_FONT_ID, beforeCursor.c_str(), EpdFontFamily::REGULAR);
|
||||
int kernOffset = 0;
|
||||
if (cursorPos < displayText.length()) {
|
||||
std::string beforeAndCursor = beforeCursor + displayText.substr(cursorPos, 1);
|
||||
int beforeAndCursorWidth = renderer.getTextWidth(UI_12_FONT_ID, beforeAndCursor.c_str());
|
||||
int charAdvance = renderer.getTextWidth(UI_12_FONT_ID, displayText.substr(cursorPos, 1).c_str());
|
||||
int beforeAndCursorWidth =
|
||||
renderer.getTextAdvanceX(UI_12_FONT_ID, beforeAndCursor.c_str(), EpdFontFamily::REGULAR);
|
||||
int charAdvance =
|
||||
renderer.getTextAdvanceX(UI_12_FONT_ID, displayText.substr(cursorPos, 1).c_str(), EpdFontFamily::REGULAR);
|
||||
kernOffset = beforeAndCursorWidth - beforeWidth - charAdvance;
|
||||
}
|
||||
if (centerText) {
|
||||
|
||||
Reference in New Issue
Block a user