MCPcopy Create free account
hub / github.com/RenderKit/embree / TextEx

Method TextEx

tutorials/common/imgui/imgui_widgets.cpp:151–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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