MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / TextEx

Method TextEx

KBotExt/imgui/imgui_widgets.cpp:146–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144//-------------------------------------------------------------------------
145
146void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags)
147{
148 ImGuiWindow* window = GetCurrentWindow();
149 if (window->SkipItems)
150 return;
151 ImGuiContext& g = *GImGui;
152
153 // Accept null ranges
154 if (text == text_end)
155 text = text_end = "";
156
157 // Calculate length
158 const char* text_begin = text;
159 if (text_end == NULL)
160 text_end = text + strlen(text); // FIXME-OPT
161
162 const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
163 const float wrap_pos_x = window->DC.TextWrapPos;
164 const bool wrap_enabled = (wrap_pos_x >= 0.0f);
165 if (text_end - text <= 2000 || wrap_enabled)
166 {
167 // Common case
168 const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
169 const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
170
171 ImRect bb(text_pos, text_pos + text_size);
172 ItemSize(text_size, 0.0f);
173 if (!ItemAdd(bb, 0))
174 return;
175
176 // Render (we don't hide text after ## in this end-user function)
177 RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width);
178 }
179 else
180 {
181 // Long text!
182 // Perform manual coarse clipping to optimize for long multi-line text
183 // - From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
184 // - We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
185 // - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster than a casually written loop.
186 const char* line = text;
187 const float line_height = GetTextLineHeight();
188 ImVec2 text_size(0, 0);
189
190 // Lines to skip (can't skip when logging text)
191 ImVec2 pos = text_pos;
192 if (!g.LogEnabled)
193 {
194 int lines_skippable = (int)((window->ClipRect.Min.y - text_pos.y) / line_height);
195 if (lines_skippable > 0)
196 {
197 int lines_skipped = 0;
198 while (line < text_end && lines_skipped < lines_skippable)
199 {
200 const char* line_end = (const char*)memchr(line, '\n', text_end - line);
201 if (!line_end)
202 line_end = text_end;
203 if ((flags & ImGuiTextFlags_NoWidthForLargeClippedText) == 0)

Callers

nothing calls this directly

Calls 4

GetCurrentWindowFunction · 0.85
ItemSizeFunction · 0.85
ImMaxFunction · 0.85
ImVec2Function · 0.85

Tested by

no test coverage detected