MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / RenderTextClippedEx

Method RenderTextClippedEx

lib/imgui/imgui.cpp:2356–2382  ·  view source on GitHub ↗

Default clip_rect uses (pos_min,pos_max) Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges)

Source from the content-addressed store, hash-verified

2354// Default clip_rect uses (pos_min,pos_max)
2355// Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges)
2356void ImGui::RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_display_end, const ImVec2* text_size_if_known, const ImVec2& align, const ImRect* clip_rect)
2357{
2358 // Perform CPU side clipping for single clipped element to avoid using scissor state
2359 ImVec2 pos = pos_min;
2360 const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f);
2361
2362 const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min;
2363 const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max;
2364 bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y);
2365 if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min
2366 need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
2367
2368 // Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment.
2369 if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x);
2370 if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
2371
2372 // Render
2373 if (need_clipping)
2374 {
2375 ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
2376 draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, &fine_clip_rect);
2377 }
2378 else
2379 {
2380 draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, NULL);
2381 }
2382}
2383
2384void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align, const ImRect* clip_rect)
2385{

Callers

nothing calls this directly

Calls 2

ImMaxFunction · 0.85
AddTextMethod · 0.80

Tested by

no test coverage detected