MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / InputTextLineIndexBuild

Function InputTextLineIndexBuild

include/imgui/imgui_widgets.cpp:4624–4673  ·  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

4622// FIXME-WORDWRAP: Bundle some of this into ImGuiTextIndex and/or extract as a different tool?
4623// '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)
4624static 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)
4625{
4626 ImGuiContext& g = *GImGui;
4627 int size = 0;
4628 const char* s;
4629 bool trailing_line_already_counted = false;
4630 if (flags & ImGuiInputTextFlags_WordWrap)
4631 {
4632 for (s = buf; s < buf_end; s = (*s == '\n') ? s + 1 : s)
4633 {
4634 if (size++ <= max_output_buffer_size)
4635 line_index->Offsets.push_back((int)(s - buf));
4636 s = ImFontCalcWordWrapPositionEx(g.Font, g.FontSize, s, buf_end, wrap_width, ImDrawTextFlags_WrapKeepBlanks);
4637 }
4638 }
4639 else if (buf_end != NULL)
4640 {
4641 for (s = buf; s < buf_end; s = s ? s + 1 : buf_end)
4642 {
4643 if (size++ <= max_output_buffer_size)
4644 line_index->Offsets.push_back((int)(s - buf));
4645 s = (const char*)ImMemchr(s, '\n', buf_end - s);
4646 }
4647 }
4648 else
4649 {
4650 // Inactive path: we don't know buf_end ahead of time.
4651 const char* s_eol;
4652 for (s = buf; ; s = s_eol + 1)
4653 {
4654 if (size++ <= max_output_buffer_size)
4655 line_index->Offsets.push_back((int)(s - buf));
4656 if ((s_eol = strchr(s, '\n')) != NULL)
4657 continue;
4658 s += strlen(s);
4659 trailing_line_already_counted = true;
4660 break;
4661 }
4662 }
4663 if (out_buf_end != NULL)
4664 *out_buf_end = buf_end = s;
4665 if (size == 0)
4666 {
4667 line_index->Offsets.push_back(0);
4668 size++;
4669 }
4670 if (buf_end > buf && buf_end[-1] == '\n' && !trailing_line_already_counted && size++ <= max_output_buffer_size)
4671 line_index->Offsets.push_back((int)(buf_end - buf));
4672 return size;
4673}
4674
4675static ImVec2 InputTextLineIndexGetPosOffset(ImGuiContext& g, ImGuiInputTextState* state, ImGuiTextIndex* line_index, const char* buf, const char* buf_end, int cursor_n)
4676{

Callers 1

InputTextExMethod · 0.85

Calls 2

push_backMethod · 0.45

Tested by

no test coverage detected