mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
TextUnformatted: Using memchr(), fixed not properly testing for text_end bound + comments.
Internals: Added ImStreolRange() + used in LogRenderedText() + comments.
This commit is contained in:
@ -133,8 +133,9 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
{
|
||||
// Long text!
|
||||
// Perform manual coarse clipping to optimize for long multi-line text
|
||||
// From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
|
||||
// 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.
|
||||
// - From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
|
||||
// - 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.
|
||||
// - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster than a casually written loop.
|
||||
const char* line = text;
|
||||
const float line_height = GetTextLineHeight();
|
||||
const ImRect clip_rect = window->ClipRect;
|
||||
@ -153,7 +154,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end && lines_skipped < lines_skippable)
|
||||
{
|
||||
const char* line_end = strchr(line, '\n');
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
@ -169,15 +170,15 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
|
||||
while (line < text_end)
|
||||
{
|
||||
const char* line_end = strchr(line, '\n');
|
||||
if (IsClippedEx(line_rect, 0, false))
|
||||
break;
|
||||
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
const ImVec2 line_size = CalcTextSize(line, line_end, false);
|
||||
text_size.x = ImMax(text_size.x, line_size.x);
|
||||
RenderText(pos, line, line_end, false);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
line_rect.Min.y += line_height;
|
||||
line_rect.Max.y += line_height;
|
||||
@ -188,7 +189,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end)
|
||||
{
|
||||
const char* line_end = strchr(line, '\n');
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
|
Reference in New Issue
Block a user