From 68450e44feaed219741add9c4f86204719027f99 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 30 Jun 2020 19:53:52 +0300 Subject: SL-12930 Long names are not beautiful in Build Floater --- indra/newview/llpanelpermissions.cpp | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpanelpermissions.cpp') diff --git a/indra/newview/llpanelpermissions.cpp b/indra/newview/llpanelpermissions.cpp index ef16427713..225e2fb22c 100644 --- a/indra/newview/llpanelpermissions.cpp +++ b/indra/newview/llpanelpermissions.cpp @@ -972,13 +972,45 @@ void LLPanelPermissions::refresh() getChildView("clickaction")->setEnabled(is_perm_modify && is_nonpermanent_enforced && all_volume); } +// Shorten name if it doesn't fit into max_pixels of two lines +void shorten_name(std::string &name, const LLStyle::Params& style_params, S32 max_pixels) +{ + const LLFontGL* font = style_params.font(); + + LLWString wline = utf8str_to_wstring(name); + // panel supports two lines long names + S32 segment_length = font->maxDrawableChars(wline.c_str(), max_pixels, wline.length(), LLFontGL::WORD_BOUNDARY_IF_POSSIBLE); + if (segment_length == wline.length()) + { + // no work needed + return; + } + + S32 first_line_length = segment_length; + segment_length = font->maxDrawableChars(wline.substr(first_line_length).c_str(), max_pixels, wline.length(), LLFontGL::ANYWHERE); + if (segment_length + first_line_length == wline.length()) + { + // no work needed + return; + } + + // name does not fit, cut it, add ... + const LLWString dots_pad(utf8str_to_wstring(std::string("...."))); + S32 elipses_width = font->getWidthF32(dots_pad.c_str()); + segment_length = font->maxDrawableChars(wline.substr(first_line_length).c_str(), max_pixels - elipses_width, wline.length(), LLFontGL::ANYWHERE); + + name = name.substr(0, segment_length + first_line_length) + std::string("..."); +} + void LLPanelPermissions::updateOwnerName(const LLUUID& owner_id, const LLAvatarName& owner_name, const LLStyle::Params& style_params) { if (mOwnerCacheConnection.connected()) { mOwnerCacheConnection.disconnect(); } - mLabelOwnerName->setText(owner_name.getCompleteName(), style_params); + std::string name = owner_name.getCompleteName(); + shorten_name(name, style_params, mLabelOwnerName->getTextPixelWidth()); + mLabelOwnerName->setText(name, style_params); } void LLPanelPermissions::updateCreatorName(const LLUUID& creator_id, const LLAvatarName& creator_name, const LLStyle::Params& style_params) @@ -987,7 +1019,9 @@ void LLPanelPermissions::updateCreatorName(const LLUUID& creator_id, const LLAva { mCreatorCacheConnection.disconnect(); } - mLabelCreatorName->setText(creator_name.getCompleteName(), style_params); + std::string name = creator_name.getCompleteName(); + shorten_name(name, style_params, mLabelCreatorName->getTextPixelWidth()); + mLabelCreatorName->setText(name, style_params); } // static -- cgit v1.2.3 From 4487b3f105c59733d5bf667a94df81b531fef525 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 1 Jul 2020 23:37:14 +0300 Subject: SL-12930 Fixed wrong width source --- indra/newview/llpanelpermissions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpanelpermissions.cpp') diff --git a/indra/newview/llpanelpermissions.cpp b/indra/newview/llpanelpermissions.cpp index 225e2fb22c..1de73ec1f3 100644 --- a/indra/newview/llpanelpermissions.cpp +++ b/indra/newview/llpanelpermissions.cpp @@ -1009,7 +1009,7 @@ void LLPanelPermissions::updateOwnerName(const LLUUID& owner_id, const LLAvatarN mOwnerCacheConnection.disconnect(); } std::string name = owner_name.getCompleteName(); - shorten_name(name, style_params, mLabelOwnerName->getTextPixelWidth()); + shorten_name(name, style_params, mLabelOwnerName->getVisibleTextRect().getWidth()); mLabelOwnerName->setText(name, style_params); } @@ -1020,7 +1020,7 @@ void LLPanelPermissions::updateCreatorName(const LLUUID& creator_id, const LLAva mCreatorCacheConnection.disconnect(); } std::string name = creator_name.getCompleteName(); - shorten_name(name, style_params, mLabelCreatorName->getTextPixelWidth()); + shorten_name(name, style_params, mLabelCreatorName->getVisibleTextRect().getWidth()); mLabelCreatorName->setText(name, style_params); } -- cgit v1.2.3 From 708ab146540b4117434f8feb719b6619a0438fe2 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 2 Jul 2020 18:53:01 +0300 Subject: SL-12930 Fixed wrong width source getVisibleTextRect can be uninitialized, yet it is identical to getLocalRect (and getRect) in width due to these elements not having scrollers. --- indra/newview/llpanelpermissions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpanelpermissions.cpp') diff --git a/indra/newview/llpanelpermissions.cpp b/indra/newview/llpanelpermissions.cpp index 1de73ec1f3..3e770958da 100644 --- a/indra/newview/llpanelpermissions.cpp +++ b/indra/newview/llpanelpermissions.cpp @@ -1009,7 +1009,7 @@ void LLPanelPermissions::updateOwnerName(const LLUUID& owner_id, const LLAvatarN mOwnerCacheConnection.disconnect(); } std::string name = owner_name.getCompleteName(); - shorten_name(name, style_params, mLabelOwnerName->getVisibleTextRect().getWidth()); + shorten_name(name, style_params, mLabelOwnerName->getLocalRect().getWidth()); mLabelOwnerName->setText(name, style_params); } @@ -1020,7 +1020,7 @@ void LLPanelPermissions::updateCreatorName(const LLUUID& creator_id, const LLAva mCreatorCacheConnection.disconnect(); } std::string name = creator_name.getCompleteName(); - shorten_name(name, style_params, mLabelCreatorName->getVisibleTextRect().getWidth()); + shorten_name(name, style_params, mLabelCreatorName->getLocalRect().getWidth()); mLabelCreatorName->setText(name, style_params); } -- cgit v1.2.3