MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / InputTextCalcTextSizeW

Function InputTextCalcTextSizeW

core/src/imgui/imgui_widgets.cpp:3535–3578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3533}
3534
3535static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining, ImVec2* out_offset, bool stop_on_new_line)
3536{
3537 ImGuiContext& g = *GImGui;
3538 ImFont* font = g.Font;
3539 const float line_height = g.FontSize;
3540 const float scale = line_height / font->FontSize;
3541
3542 ImVec2 text_size = ImVec2(0, 0);
3543 float line_width = 0.0f;
3544
3545 const ImWchar* s = text_begin;
3546 while (s < text_end)
3547 {
3548 unsigned int c = (unsigned int)(*s++);
3549 if (c == '\n')
3550 {
3551 text_size.x = ImMax(text_size.x, line_width);
3552 text_size.y += line_height;
3553 line_width = 0.0f;
3554 if (stop_on_new_line)
3555 break;
3556 continue;
3557 }
3558 if (c == '\r')
3559 continue;
3560
3561 const float char_width = font->GetCharAdvance((ImWchar)c) * scale;
3562 line_width += char_width;
3563 }
3564
3565 if (text_size.x < line_width)
3566 text_size.x = line_width;
3567
3568 if (out_offset)
3569 *out_offset = ImVec2(line_width, text_size.y + line_height); // offset allow for the possibility of sitting after a trailing \n
3570
3571 if (line_width > 0 || text_size.y == 0.0f) // whereas size.y will ignore the trailing \n
3572 text_size.y += line_height;
3573
3574 if (remaining)
3575 *remaining = s;
3576
3577 return text_size;
3578}
3579
3580// 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)
3581namespace 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