diff --git a/src/font.cpp b/src/font.cpp index c9ca7b80b7b..e4518ee0ae2 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -853,13 +853,19 @@ SDL_Rect line_size(const std::string& line, int font_size, int style) return res; } -std::string make_text_ellipsis(const std::string &text, int font_size, int max_width, bool with_tags) +std::string make_text_ellipsis(const std::string &text, int font_size, + int max_width, bool with_tags, bool parse_for_style) { static const std::string ellipsis = "..."; - if(line_width(with_tags ? text : del_tags(text), font_size) <= max_width) + SDL_Color unused_color; + int unused_int; + int style = TTF_STYLE_NORMAL; + if(parse_for_style) parse_markup(text.begin(), text.end(), &unused_int, &unused_color, &style); + + if(line_width(with_tags ? text : del_tags(text), font_size, style) <= max_width) return text; - if(line_width(ellipsis, font_size) > max_width) + if(line_width(ellipsis, font_size, style) > max_width) return ""; std::string current_substring; @@ -871,7 +877,7 @@ std::string make_text_ellipsis(const std::string &text, int font_size, int max_w tmp.append(itor.substr().first, itor.substr().second); tmp += ellipsis; - if (line_width(with_tags ? tmp : del_tags(tmp), font_size) > max_width) { + if (line_width(with_tags ? tmp : del_tags(tmp), font_size, style) > max_width) { return current_substring + ellipsis; } diff --git a/src/font.hpp b/src/font.hpp index b4c47d95740..0f2a74ec1b9 100644 --- a/src/font.hpp +++ b/src/font.hpp @@ -112,8 +112,11 @@ SDL_Rect line_size(const std::string& line, int font_size, int style=TTF_STYLE_N /// /// If the text excedes the specified max width, end it with an ellipsis (...) /// The with_tags can probably always be set to false +/// If parse_for_style is true we look for the style of the text (bold, etc.) +/// before deleting its tags. /// -std::string make_text_ellipsis(const std::string& text, int font_size, int max_width, bool with_tags = true); +std::string make_text_ellipsis(const std::string& text, int font_size, int max_width, + bool with_tags = true, bool parse_for_style = false); /// structure which will hide all current floating labels, and cause floating labels diff --git a/src/widgets/menu.cpp b/src/widgets/menu.cpp index 1c9da5037c1..4044f6bcb79 100644 --- a/src/widgets/menu.cpp +++ b/src/widgets/menu.cpp @@ -913,7 +913,7 @@ void menu::draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type) const std::string to_show = (use_ellipsis_ && !has_wrap) ? font::make_text_ellipsis(str, style_->get_font_size(), - loc.w - (xpos - rect.x) - 2*style_->get_thickness(), false) + loc.w - (xpos - rect.x) - 2*style_->get_thickness(), false, true) : str; const SDL_Rect& text_size = font::text_area(str,style_->get_font_size()); const size_t y = rect.y + (rect.h - text_size.h)/2;