diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-06 07:04:29 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-06 07:04:29 +0300 |
commit | e1ff98965a4aec72418165424a0183e596df1ecb (patch) | |
tree | e01f245348ba39d2a2eb5fdffe5a8600e5928b96 /src/ui/inputwidget.c | |
parent | 5915a8509827bbad99731b0e8451f484bff1ac61 (diff) |
Text run measurement API change; bug fixes
The distinction between measure_Text and advance_Text was not very clear. Now there are only measure_Text functions that return both the bounds and the cursor position advancement, and the appropriate metrics are used by the caller.
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 8ea21cff..e65af417 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -211,7 +211,7 @@ static void updateSizeForFixedLength_InputWidget_(iInputWidget *d) { | |||
211 | int extraHeight = (flags_Widget(as_Widget(d)) & extraPadding_WidgetFlag ? extraPaddingHeight_ : 0); | 211 | int extraHeight = (flags_Widget(as_Widget(d)) & extraPadding_WidgetFlag ? extraPaddingHeight_ : 0); |
212 | setFixedSize_Widget( | 212 | setFixedSize_Widget( |
213 | as_Widget(d), | 213 | as_Widget(d), |
214 | add_I2(measure_Text(d->font, cstr_Block(content)), | 214 | add_I2(measure_Text(d->font, cstr_Block(content)).bounds.size, |
215 | init_I2(6 * gap_UI + d->leftPadding + d->rightPadding, | 215 | init_I2(6 * gap_UI + d->leftPadding + d->rightPadding, |
216 | 2 * gap_UI + extraHeight))); | 216 | 2 * gap_UI + extraHeight))); |
217 | delete_Block(content); | 217 | delete_Block(content); |
@@ -747,7 +747,7 @@ static size_t indexForRelativeX_InputWidget_(const iInputWidget *d, int x, const | |||
747 | 747 | ||
748 | static iBool moveCursorByLine_InputWidget_(iInputWidget *d, int dir) { | 748 | static iBool moveCursorByLine_InputWidget_(iInputWidget *d, int dir) { |
749 | const iInputLine *line = line_InputWidget_(d, d->cursorLine); | 749 | const iInputLine *line = line_InputWidget_(d, d->cursorLine); |
750 | int xPos = advanceN_Text(d->font, cstr_String(&line->text), d->cursor - line->offset).x; | 750 | int xPos = measureN_Text(d->font, cstr_String(&line->text), d->cursor - line->offset).advance.x; |
751 | size_t newCursor = iInvalidPos; | 751 | size_t newCursor = iInvalidPos; |
752 | const size_t numLines = size_Array(&d->lines); | 752 | const size_t numLines = size_Array(&d->lines); |
753 | if (dir < 0 && d->cursorLine > 0) { | 753 | if (dir < 0 && d->cursorLine > 0) { |
@@ -1400,14 +1400,14 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1400 | /* Draw the selected range. */ | 1400 | /* Draw the selected range. */ |
1401 | const iRanges mark = mark_InputWidget_(d); | 1401 | const iRanges mark = mark_InputWidget_(d); |
1402 | if (mark.start < lineRange.end && mark.end > lineRange.start) { | 1402 | if (mark.start < lineRange.end && mark.end > lineRange.start) { |
1403 | const int m1 = advanceN_Text(d->font, | 1403 | const int m1 = measureN_Text(d->font, |
1404 | cstr_String(&line->text), | 1404 | cstr_String(&line->text), |
1405 | iMax(lineRange.start, mark.start) - line->offset) | 1405 | iMax(lineRange.start, mark.start) - line->offset) |
1406 | .x; | 1406 | .advance.x; |
1407 | const int m2 = advanceN_Text(d->font, | 1407 | const int m2 = measureN_Text(d->font, |
1408 | cstr_String(&line->text), | 1408 | cstr_String(&line->text), |
1409 | iMin(lineRange.end, mark.end) - line->offset) | 1409 | iMin(lineRange.end, mark.end) - line->offset) |
1410 | .x; | 1410 | .advance.x; |
1411 | fillRect_Paint(&p, | 1411 | fillRect_Paint(&p, |
1412 | (iRect){ addX_I2(drawPos, iMin(m1, m2)), | 1412 | (iRect){ addX_I2(drawPos, iMin(m1, m2)), |
1413 | init_I2(iMax(gap_UI / 3, iAbs(m2 - m1)), | 1413 | init_I2(iMax(gap_UI / 3, iAbs(m2 - m1)), |
@@ -1437,7 +1437,8 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1437 | else { | 1437 | else { |
1438 | initCStr_String(&cur, " "); | 1438 | initCStr_String(&cur, " "); |
1439 | } | 1439 | } |
1440 | curSize = addX_I2(advance_Text(d->font, cstr_String(&cur)), iMin(2, gap_UI / 4)); | 1440 | curSize = addX_I2(measure_Text(d->font, cstr_String(&cur)).bounds.size, |
1441 | iMin(2, gap_UI / 4)); | ||
1441 | } | 1442 | } |
1442 | else { | 1443 | else { |
1443 | /* Bar cursor. */ | 1444 | /* Bar cursor. */ |
@@ -1447,7 +1448,7 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
1447 | const iString * text = &curLine->text; | 1448 | const iString * text = &curLine->text; |
1448 | /* The `gap_UI` offsets below are a hack. They are used because for some reason the | 1449 | /* The `gap_UI` offsets below are a hack. They are used because for some reason the |
1449 | cursor rect and the glyph inside don't quite position like during `run_Text_()`. */ | 1450 | cursor rect and the glyph inside don't quite position like during `run_Text_()`. */ |
1450 | const iInt2 prefixSize = advanceN_Text(d->font, cstr_String(text), d->cursor - curLine->offset); | 1451 | const iInt2 prefixSize = measureN_Text(d->font, cstr_String(text), d->cursor - curLine->offset).bounds.size; |
1451 | const iInt2 curPos = addX_I2(addY_I2(contentBounds.pos, lineHeight_Text(d->font) * d->cursorLine), | 1452 | const iInt2 curPos = addX_I2(addY_I2(contentBounds.pos, lineHeight_Text(d->font) * d->cursorLine), |
1452 | prefixSize.x + | 1453 | prefixSize.x + |
1453 | (d->mode == insert_InputMode ? -curSize.x / 2 : 0)); | 1454 | (d->mode == insert_InputMode ? -curSize.x / 2 : 0)); |