MCPcopy Create free account
hub / github.com/RenderKit/embree / InputTextCalcTextSizeW

Function InputTextCalcTextSizeW

tutorials/common/imgui/imgui_widgets.cpp:3567–3610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3565}
3566
3567static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining, ImVec2* out_offset, bool stop_on_new_line)
3568{
3569 ImGuiContext& g = *GImGui;
3570 ImFont* font = g.Font;
3571 const float line_height = g.FontSize;
3572 const float scale = line_height / font->FontSize;
3573
3574 ImVec2 text_size = ImVec2(0, 0);
3575 float line_width = 0.0f;
3576
3577 const ImWchar* s = text_begin;
3578 while (s < text_end)
3579 {
3580 unsigned int c = (unsigned int)(*s++);
3581 if (c == '\n')
3582 {
3583 text_size.x = ImMax(text_size.x, line_width);
3584 text_size.y += line_height;
3585 line_width = 0.0f;
3586 if (stop_on_new_line)
3587 break;
3588 continue;
3589 }
3590 if (c == '\r')
3591 continue;
3592
3593 const float char_width = font->GetCharAdvance((ImWchar)c) * scale;
3594 line_width += char_width;
3595 }
3596
3597 if (text_size.x < line_width)
3598 text_size.x = line_width;
3599
3600 if (out_offset)
3601 *out_offset = ImVec2(line_width, text_size.y + line_height); // offset allow for the possibility of sitting after a trailing \n
3602
3603 if (line_width > 0 || text_size.y == 0.0f) // whereas size.y will ignore the trailing \n
3604 text_size.y += line_height;
3605
3606 if (remaining)
3607 *remaining = s;
3608
3609 return text_size;
3610}
3611
3612// 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)
3613namespace 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