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)
| 3254 | // Default clip_rect uses (pos_min,pos_max) |
| 3255 | // Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges) |
| 3256 | void 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) |
| 3257 | { |
| 3258 | // Perform CPU side clipping for single clipped element to avoid using scissor state |
| 3259 | ImVec2 pos = pos_min; |
| 3260 | const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f); |
| 3261 | |
| 3262 | const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min; |
| 3263 | const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max; |
| 3264 | bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y); |
| 3265 | if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min |
| 3266 | need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y); |
| 3267 | |
| 3268 | // Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment. |
| 3269 | if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x); |
| 3270 | if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y); |
| 3271 | |
| 3272 | // Render |
| 3273 | if (need_clipping) |
| 3274 | { |
| 3275 | ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y); |
| 3276 | draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, &fine_clip_rect); |
| 3277 | } |
| 3278 | else |
| 3279 | { |
| 3280 | draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, NULL); |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | void 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) |
| 3285 | { |