MCPcopy Create free account
hub / github.com/ShenCiao/CialloResearch / InputTextCalcTextSizeW

Function InputTextCalcTextSizeW

imgui/imgui_widgets.cpp:3574–3617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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