summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-21 11:40:35 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-21 11:40:35 +0300
commit059d19065e613412cb9fccc06e23fd0685484905 (patch)
tree8e80a3fa8c400f2791ee6a6d6e71465bfb008376 /src
parent9ab619bd3c57d681a3906abf0dc10d5376d01319 (diff)
InputWidget: Fixed coord-based positioning
Diffstat (limited to 'src')
-rw-r--r--src/ui/inputwidget.c13
-rw-r--r--src/ui/text.c4
2 files changed, 11 insertions, 6 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index f7d41a44..c60aa474 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -1119,8 +1119,12 @@ static iBool moveCursorByLine_InputWidget_(iInputWidget *d, int dir) {
1119 wrapText.text = range_String(&cursorLine_InputWidget_(d)->text); 1119 wrapText.text = range_String(&cursorLine_InputWidget_(d)->text);
1120 wrapText.hitPoint = addY_I2(relCoord, 1); //arelCddX_I2(relCoord, cursorWidth), 1120 wrapText.hitPoint = addY_I2(relCoord, 1); //arelCddX_I2(relCoord, cursorWidth),
1121 measure_WrapText(&wrapText, d->font); 1121 measure_WrapText(&wrapText, d->font);
1122 iAssert(wrapText.hitChar_out); 1122 if (wrapText.hitChar_out) {
1123 d->cursor.x = wrapText.hitChar_out - wrapText.text.start; 1123 d->cursor.x = wrapText.hitChar_out - wrapText.text.start;
1124 }
1125 else {
1126 d->cursor.x = endX_InputWidget_(d, d->cursor.y);
1127 }
1124 /* 1128 /*
1125 if (wrapText.hitGlyphNormX_out > 0.5f && d->cursor.x < endX_InputWidget_(d, d->cursor.y)) { 1129 if (wrapText.hitGlyphNormX_out > 0.5f && d->cursor.x < endX_InputWidget_(d, d->cursor.y)) {
1126 iChar ch; 1130 iChar ch;
@@ -1392,19 +1396,20 @@ static iInt2 coordCursor_InputWidget_(const iInputWidget *d, iInt2 coord) {
1392 const iRangei visLines = visibleLineRange_InputWidget_(d); 1396 const iRangei visLines = visibleLineRange_InputWidget_(d);
1393 for (size_t y = visLines.start; y < visLines.end; y++) { 1397 for (size_t y = visLines.start; y < visLines.end; y++) {
1394 wrapText.text = range_String(lineString_InputWidget_(d, y)); 1398 wrapText.text = range_String(lineString_InputWidget_(d, y));
1395 measure_WrapText(&wrapText, d->font); 1399 const iTextMetrics tm = measure_WrapText(&wrapText, d->font);
1396 if (wrapText.hitChar_out) { 1400 if (wrapText.hitChar_out) {
1397 const char *pos = wrapText.hitChar_out; 1401 const char *pos = wrapText.hitChar_out;
1398 /* Cursor is between characters, so jump to next character if halfway there. */ 1402 /* Cursor is between characters, so jump to next character if halfway there. */
1399 if (wrapText.hitGlyphNormX_out > 0.5f) { 1403 if (wrapText.hitGlyphNormX_out > 0.5f) {
1400 iChar ch; 1404 iChar ch;
1401 int n = decodeBytes_MultibyteChar(pos, wrapText.text.end, &ch); 1405 int n = decodeBytes_MultibyteChar(pos, wrapText.text.end, &ch);
1402 if (n > 0) { 1406 if (ch != '\n' && n > 0) {
1403 pos += n; 1407 pos += n;
1404 } 1408 }
1405 } 1409 }
1406 return init_I2(iMin(pos - wrapText.text.start, endX_InputWidget_(d, y)), y); 1410 return init_I2(iMin(pos - wrapText.text.start, endX_InputWidget_(d, y)), y);
1407 } 1411 }
1412 wrapText.hitPoint.y -= tm.advance.y;
1408 } 1413 }
1409 return cursorMax_InputWidget_(d); 1414 return cursorMax_InputWidget_(d);
1410} 1415}
diff --git a/src/ui/text.c b/src/ui/text.c
index ce383ccf..8a82690f 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -1440,8 +1440,8 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1440 float wrapAdvance = 0.0f; 1440 float wrapAdvance = 0.0f;
1441 /* First we need to figure out how much text fits on the current line. */ 1441 /* First we need to figure out how much text fits on the current line. */
1442 if (wrap && (wrap->maxWidth > 0 || checkHitPoint)) { 1442 if (wrap && (wrap->maxWidth > 0 || checkHitPoint)) {
1443 const iBool isHitPointOnThisLine = (checkHitPoint && wrap->hitPoint.y >= yCursor && 1443 const iBool isHitPointOnThisLine = (checkHitPoint && wrap->hitPoint.y >= orig.y + yCursor &&
1444 wrap->hitPoint.y < yCursor + d->height); 1444 wrap->hitPoint.y < orig.y + yCursor + d->height);
1445 float breakAdvance = -1.0f; 1445 float breakAdvance = -1.0f;
1446 iAssert(wrapPosRange.end == textLen); 1446 iAssert(wrapPosRange.end == textLen);
1447 /* Determine ends of wrapRuns and wrapVisRange. */ 1447 /* Determine ends of wrapRuns and wrapVisRange. */