MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / InputTextLineIndexBuild

Function InputTextLineIndexBuild

imgui_tiny_app/imgui/imgui_widgets.cpp:4607–4656  ·  view source on GitHub ↗

FIXME-WORDWRAP: Bundle some of this into ImGuiTextIndex and/or extract as a different tool? 'max_output_buffer_size' happens to be a meaningful optimization to avoid writing the full line_index when not necessarily needed (e.g. very large buffer, scrolled up, inactive)

Source from the content-addressed store, hash-verified

4605// FIXME-WORDWRAP: Bundle some of this into ImGuiTextIndex and/or extract as a different tool?
4606// 'max_output_buffer_size' happens to be a meaningful optimization to avoid writing the full line_index when not necessarily needed (e.g. very large buffer, scrolled up, inactive)
4607static int InputTextLineIndexBuild(ImGuiInputTextFlags flags, ImGuiTextIndex* line_index, const char* buf, const char* buf_end, float wrap_width, int max_output_buffer_size, const char** out_buf_end)
4608{
4609 ImGuiContext& g = *GImGui;
4610 int size = 0;
4611 const char* s;
4612 bool trailing_line_already_counted = false;
4613 if (flags & ImGuiInputTextFlags_WordWrap)
4614 {
4615 for (s = buf; s < buf_end; s = (*s == '\n') ? s + 1 : s)
4616 {
4617 if (size++ <= max_output_buffer_size)
4618 line_index->Offsets.push_back((int)(s - buf));
4619 s = ImFontCalcWordWrapPositionEx(g.Font, g.FontSize, s, buf_end, wrap_width, ImDrawTextFlags_WrapKeepBlanks);
4620 }
4621 }
4622 else if (buf_end != NULL)
4623 {
4624 for (s = buf; s < buf_end; s = s ? s + 1 : buf_end)
4625 {
4626 if (size++ <= max_output_buffer_size)
4627 line_index->Offsets.push_back((int)(s - buf));
4628 s = (const char*)ImMemchr(s, '\n', buf_end - s);
4629 }
4630 }
4631 else
4632 {
4633 // Inactive path: we don't know buf_end ahead of time.
4634 const char* s_eol;
4635 for (s = buf; ; s = s_eol + 1)
4636 {
4637 if (size++ <= max_output_buffer_size)
4638 line_index->Offsets.push_back((int)(s - buf));
4639 if ((s_eol = strchr(s, '\n')) != NULL)
4640 continue;
4641 s += strlen(s);
4642 trailing_line_already_counted = true;
4643 break;
4644 }
4645 }
4646 if (out_buf_end != NULL)
4647 *out_buf_end = buf_end = s;
4648 if (size == 0)
4649 {
4650 line_index->Offsets.push_back(0);
4651 size++;
4652 }
4653 if (buf_end > buf && buf_end[-1] == '\n' && !trailing_line_already_counted && size++ <= max_output_buffer_size)
4654 line_index->Offsets.push_back((int)(buf_end - buf));
4655 return size;
4656}
4657
4658static ImVec2 InputTextLineIndexGetPosOffset(ImGuiContext& g, ImGuiInputTextState* state, ImGuiTextIndex* line_index, const char* buf, const char* buf_end, int cursor_n)
4659{

Callers 1

InputTextExMethod · 0.85

Calls 2

push_backMethod · 0.45

Tested by

no test coverage detected