align_x: 0.0f = left, 0.5f = center, 1.0f = right. size_x : 0.0f = shortcut for GetContentRegionAvail().x FIXME-WIP: Works but API is likely to be reworked. This is designed for 1 item on the line. (#7024)
| 350 | // size_x : 0.0f = shortcut for GetContentRegionAvail().x |
| 351 | // FIXME-WIP: Works but API is likely to be reworked. This is designed for 1 item on the line. (#7024) |
| 352 | void ImGui::TextAlignedV(float align_x, float size_x, const char* fmt, va_list args) |
| 353 | { |
| 354 | ImGuiWindow* window = GetCurrentWindow(); |
| 355 | if (window->SkipItems) |
| 356 | return; |
| 357 | |
| 358 | const char* text, *text_end; |
| 359 | ImFormatStringToTempBufferV(&text, &text_end, fmt, args); |
| 360 | const ImVec2 text_size = CalcTextSize(text, text_end); |
| 361 | size_x = CalcItemSize(ImVec2(size_x, 0.0f), 0.0f, text_size.y).x; |
| 362 | |
| 363 | ImVec2 pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); |
| 364 | ImVec2 pos_max(pos.x + size_x, window->ClipRect.Max.y); |
| 365 | ImVec2 size(ImMin(size_x, text_size.x), text_size.y); |
| 366 | window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, pos.x + text_size.x); |
| 367 | window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, pos.x + text_size.x); |
| 368 | if (align_x > 0.0f && text_size.x < size_x) |
| 369 | pos.x += ImTrunc((size_x - text_size.x) * align_x); |
| 370 | RenderTextEllipsis(window->DrawList, pos, pos_max, pos_max.x, text, text_end, &text_size); |
| 371 | |
| 372 | const ImVec2 backup_max_pos = window->DC.CursorMaxPos; |
| 373 | ItemSize(size); |
| 374 | ItemAdd(ImRect(pos, pos + size), 0); |
| 375 | window->DC.CursorMaxPos.x = backup_max_pos.x; // Cancel out extending content size because right-aligned text would otherwise mess it up. |
| 376 | |
| 377 | if (size_x < text_size.x && IsItemHovered(ImGuiHoveredFlags_NoNavOverride | ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_ForTooltip)) |
| 378 | SetTooltip("%.*s", (int)(text_end - text), text); |
| 379 | } |
| 380 | |
| 381 | void ImGui::LabelText(const char* label, const char* fmt, ...) |
| 382 | { |
nothing calls this directly
no test coverage detected