Another overly complex function until we reorganize everything into a nice all-in-one helper. This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define _where_ the ellipsis is, from actual clipping of text and limit of the ellipsis display. This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but
| 3229 | // This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define _where_ the ellipsis is, from actual clipping of text and limit of the ellipsis display. |
| 3230 | // This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move. |
| 3231 | void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known) |
| 3232 | { |
| 3233 | ImGuiContext& g = *GImGui; |
| 3234 | if (text_end_full == NULL) |
| 3235 | text_end_full = FindRenderedTextEnd(text); |
| 3236 | const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_end_full, false, 0.0f); |
| 3237 | |
| 3238 | //draw_list->AddLine(ImVec2(pos_max.x, pos_min.y - 4), ImVec2(pos_max.x, pos_max.y + 4), IM_COL32(0, 0, 255, 255)); |
| 3239 | //draw_list->AddLine(ImVec2(ellipsis_max_x, pos_min.y-2), ImVec2(ellipsis_max_x, pos_max.y+2), IM_COL32(0, 255, 0, 255)); |
| 3240 | //draw_list->AddLine(ImVec2(clip_max_x, pos_min.y), ImVec2(clip_max_x, pos_max.y), IM_COL32(255, 0, 0, 255)); |
| 3241 | // FIXME: We could technically remove (last_glyph->AdvanceX - last_glyph->X1) from text_size.x here and save a few pixels. |
| 3242 | if (text_size.x > pos_max.x - pos_min.x) |
| 3243 | { |
| 3244 | // Hello wo... |
| 3245 | // | | | |
| 3246 | // min max ellipsis_max |
| 3247 | // <-> this is generally some padding value |
| 3248 | |
| 3249 | const ImFont* font = draw_list->_Data->Font; |
| 3250 | const float font_size = draw_list->_Data->FontSize; |
| 3251 | const char* text_end_ellipsis = NULL; |
| 3252 | |
| 3253 | ImWchar ellipsis_char = font->EllipsisChar; |
| 3254 | int ellipsis_char_count = 1; |
| 3255 | if (ellipsis_char == (ImWchar)-1) |
| 3256 | { |
| 3257 | ellipsis_char = font->DotChar; |
| 3258 | ellipsis_char_count = 3; |
| 3259 | } |
| 3260 | const ImFontGlyph* glyph = font->FindGlyph(ellipsis_char); |
| 3261 | |
| 3262 | float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side |
| 3263 | float ellipsis_total_width = ellipsis_glyph_width; // Full width of entire ellipsis |
| 3264 | |
| 3265 | if (ellipsis_char_count > 1) |
| 3266 | { |
| 3267 | // Full ellipsis size without free spacing after it. |
| 3268 | const float spacing_between_dots = 1.0f * (draw_list->_Data->FontSize / font->FontSize); |
| 3269 | ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; |
| 3270 | ellipsis_total_width = ellipsis_glyph_width * (float)ellipsis_char_count - spacing_between_dots; |
| 3271 | } |
| 3272 | |
| 3273 | // We can now claim the space between pos_max.x and ellipsis_max.x |
| 3274 | const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_total_width) - pos_min.x, 1.0f); |
| 3275 | float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; |
| 3276 | if (text == text_end_ellipsis && text_end_ellipsis < text_end_full) |
| 3277 | { |
| 3278 | // Always display at least 1 character if there's no room for character + ellipsis |
| 3279 | text_end_ellipsis = text + ImTextCountUtf8BytesFromChar(text, text_end_full); |
| 3280 | text_size_clipped_x = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text, text_end_ellipsis).x; |
| 3281 | } |
| 3282 | while (text_end_ellipsis > text && ImCharIsBlankA(text_end_ellipsis[-1])) |
| 3283 | { |
| 3284 | // Trim trailing space before ellipsis (FIXME: Supporting non-ascii blanks would be nice, for this we need a function to backtrack in UTF-8 text) |
| 3285 | text_end_ellipsis--; |
| 3286 | text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte |
| 3287 | } |
| 3288 |
nothing calls this directly
no test coverage detected