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

Method CalcTextSizeA

tutorials/common/imgui/imgui_draw.cpp:3447–3529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3445}
3446
3447ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
3448{
3449 if (!text_end)
3450 text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
3451
3452 const float line_height = size;
3453 const float scale = size / FontSize;
3454
3455 ImVec2 text_size = ImVec2(0, 0);
3456 float line_width = 0.0f;
3457
3458 const bool word_wrap_enabled = (wrap_width > 0.0f);
3459 const char* word_wrap_eol = NULL;
3460
3461 const char* s = text_begin;
3462 while (s < text_end)
3463 {
3464 if (word_wrap_enabled)
3465 {
3466 // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
3467 if (!word_wrap_eol)
3468 word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
3469
3470 if (s >= word_wrap_eol)
3471 {
3472 if (text_size.x < line_width)
3473 text_size.x = line_width;
3474 text_size.y += line_height;
3475 line_width = 0.0f;
3476 word_wrap_eol = NULL;
3477 s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks
3478 continue;
3479 }
3480 }
3481
3482 // Decode and advance source
3483 const char* prev_s = s;
3484 unsigned int c = (unsigned int)*s;
3485 if (c < 0x80)
3486 {
3487 s += 1;
3488 }
3489 else
3490 {
3491 s += ImTextCharFromUtf8(&c, s, text_end);
3492 if (c == 0) // Malformed UTF-8?
3493 break;
3494 }
3495
3496 if (c < 32)
3497 {
3498 if (c == '\n')
3499 {
3500 text_size.x = ImMax(text_size.x, line_width);
3501 text_size.y += line_height;
3502 line_width = 0.0f;
3503 continue;
3504 }

Callers 2

RenderTextEllipsisMethod · 0.80
CalcTextSizeMethod · 0.80

Calls 4

ImVec2Function · 0.85
ImTextCharFromUtf8Function · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected