find the x/y location of a character, and remember info about the previous row in case we get a move-up event (for page up, we'll have to rescan)
| 514 | // find the x/y location of a character, and remember info about the previous row in |
| 515 | // case we get a move-up event (for page up, we'll have to rescan) |
| 516 | static void stb_textedit_find_charpos(StbFindState* find, STB_TEXTEDIT_STRING* str, int n, int single_line) |
| 517 | { |
| 518 | StbTexteditRow r; |
| 519 | int prev_start = 0; |
| 520 | int z = STB_TEXTEDIT_STRINGLEN(str); |
| 521 | int i = 0, first; |
| 522 | |
| 523 | if (n == z && single_line) { |
| 524 | // special case if it's at the end (may not be needed?) |
| 525 | STB_TEXTEDIT_LAYOUTROW(&r, str, 0); |
| 526 | find->y = 0; |
| 527 | find->first_char = 0; |
| 528 | find->length = z; |
| 529 | find->height = r.ymax - r.ymin; |
| 530 | find->x = r.x1; |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | // search rows to find the one that straddles character n |
| 535 | find->y = 0; |
| 536 | |
| 537 | for (;;) { |
| 538 | STB_TEXTEDIT_LAYOUTROW(&r, str, i); |
| 539 | if (n < i + r.num_chars) |
| 540 | break; |
| 541 | if (i + r.num_chars == z && z > 0 && STB_TEXTEDIT_GETCHAR(str, z - 1) != STB_TEXTEDIT_NEWLINE) // [DEAR IMGUI] special handling for last line |
| 542 | break; // [DEAR IMGUI] |
| 543 | prev_start = i; |
| 544 | i += r.num_chars; |
| 545 | find->y += r.baseline_y_delta; |
| 546 | if (i == z) // [DEAR IMGUI] |
| 547 | break; // [DEAR IMGUI] |
| 548 | } |
| 549 | |
| 550 | find->first_char = first = i; |
| 551 | find->length = r.num_chars; |
| 552 | find->height = r.ymax - r.ymin; |
| 553 | find->prev_first = prev_start; |
| 554 | |
| 555 | // now scan to find xpos |
| 556 | find->x = r.x0; |
| 557 | for (i = 0; first + i < n; ++i) |
| 558 | find->x += STB_TEXTEDIT_GETWIDTH(str, first, i); |
| 559 | } |
| 560 | |
| 561 | #define STB_TEXT_HAS_SELECTION(s) ((s)->select_start != (s)->select_end) |
| 562 |
no test coverage detected