MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / InputTextCalcTextSizeW

Function InputTextCalcTextSizeW

plugins/Cardinal/src/DearImGui/imgui_widgets.cpp:3625–3668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3623}
3624
3625static 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)
3671namespace ImStb

Callers 2

STB_TEXTEDIT_LAYOUTROWFunction · 0.85
InputTextExMethod · 0.85

Calls 3

ImVec2Function · 0.85
ImMaxFunction · 0.85
GetCharAdvanceMethod · 0.80

Tested by

no test coverage detected