| 3623 | } |
| 3624 | |
| 3625 | static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining, ImVec2* out_offset, bool stop_on_new_line) |
| 3626 | { |
| 3627 | ImGuiContext& g = *GImGui; |
| 3628 | ImFont* font = g.Font; |
| 3629 | const float line_height = g.FontSize; |
| 3630 | const float scale = line_height / font->FontSize; |
| 3631 | |
| 3632 | ImVec2 text_size = ImVec2(0, 0); |
| 3633 | float line_width = 0.0f; |
| 3634 | |
| 3635 | const ImWchar* s = text_begin; |
| 3636 | while (s < text_end) |
| 3637 | { |
| 3638 | unsigned int c = (unsigned int)(*s++); |
| 3639 | if (c == '\n') |
| 3640 | { |
| 3641 | text_size.x = ImMax(text_size.x, line_width); |
| 3642 | text_size.y += line_height; |
| 3643 | line_width = 0.0f; |
| 3644 | if (stop_on_new_line) |
| 3645 | break; |
| 3646 | continue; |
| 3647 | } |
| 3648 | if (c == '\r') |
| 3649 | continue; |
| 3650 | |
| 3651 | const float char_width = font->GetCharAdvance((ImWchar)c) * scale; |
| 3652 | line_width += char_width; |
| 3653 | } |
| 3654 | |
| 3655 | if (text_size.x < line_width) |
| 3656 | text_size.x = line_width; |
| 3657 | |
| 3658 | if (out_offset) |
| 3659 | *out_offset = ImVec2(line_width, text_size.y + line_height); // offset allow for the possibility of sitting after a trailing \n |
| 3660 | |
| 3661 | if (line_width > 0 || text_size.y == 0.0f) // whereas size.y will ignore the trailing \n |
| 3662 | text_size.y += line_height; |
| 3663 | |
| 3664 | if (remaining) |
| 3665 | *remaining = s; |
| 3666 | |
| 3667 | return text_size; |
| 3668 | } |
| 3669 | |
| 3670 | // Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, wchar characters. InputText converts between UTF-8 and wchar) |
| 3671 | namespace ImStb |
no test coverage detected