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)
| 3182 | // Default clip_rect uses (pos_min,pos_max) |
| 3183 | // Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges) |
| 3184 | 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) |
| 3185 | { |
| 3186 | // Perform CPU side clipping for single clipped element to avoid using scissor state |
| 3187 | ImVec2 pos = pos_min; |
| 3188 | const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f); |
| 3189 | |
| 3190 | const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min; |
| 3191 | const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max; |
| 3192 | bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y); |
| 3193 | if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min |
| 3194 | need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y); |
| 3195 | |
| 3196 | // Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment. |
| 3197 | if (align.x > 0.0f) pos.x = ImMax(pos.x, pos.x + (pos_max.x - pos.x - text_size.x) * align.x); |
| 3198 | if (align.y > 0.0f) pos.y = ImMax(pos.y, pos.y + (pos_max.y - pos.y - text_size.y) * align.y); |
| 3199 | |
| 3200 | // Render |
| 3201 | if (need_clipping) |
| 3202 | { |
| 3203 | ImVec4 fine_clip_rect(clip_min->x, clip_min->y, clip_max->x, clip_max->y); |
| 3204 | draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, &fine_clip_rect); |
| 3205 | } |
| 3206 | else |
| 3207 | { |
| 3208 | draw_list->AddText(NULL, 0.0f, pos, GetColorU32(ImGuiCol_Text), text, text_display_end, 0.0f, NULL); |
| 3209 | } |
| 3210 | } |
| 3211 | |
| 3212 | 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) |
| 3213 | { |