MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / RenderTextClippedEx

Method RenderTextClippedEx

KBotExt/imgui/imgui.cpp:3310–3336  ·  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) FIXME-OPT: Since we have or calculate text_size we could coarse clip whole block immediately, especally for text above draw_list->DrawList. Effectively as this is called from widget doing their own coarse clipping it's not very

Source from the content-addressed store, hash-verified

3308// Effectively as this is called from widget doing their own coarse clipping it's not very valuable presently. Next time function will take
3309// better advantage of the render function taking size into account for coarse clipping.
3310void 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)
3311{
3312 // Perform CPU side clipping for single clipped element to avoid using scissor state
3313 ImVec2 pos = pos_min;
3314 const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f);
3315
3316 const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min;
3317 const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max;
3318 bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y);
3319 if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min
3320 need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
3321
3322 // Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment.
3323 if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x);
3324 if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y);
3325
3326 // Render
3327 if (need_clipping)
3328 {
3329 ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y);
3330 draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, &fine_clip_rect);
3331 }
3332 else
3333 {
3334 draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, NULL);
3335 }
3336}
3337
3338void 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)
3339{

Callers

nothing calls this directly

Calls 2

ImMaxFunction · 0.85
AddTextMethod · 0.80

Tested by

no test coverage detected