diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2021-02-01 23:24:42 +0200 |
---|---|---|
committer | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2021-02-01 23:33:41 +0200 |
commit | 44b6459dfaa4f1605fdbcb7e07ac03b9d057d603 (patch) | |
tree | c88886947e37c44b9a13db83a0c8115aea8d303f /indra/newview/llpanelpermissions.cpp | |
parent | d3169aa696f5afaff18eb4d90c8b70a4f5528eb7 (diff) | |
parent | 21565a1f3fe1ae737e2f91c58be2c3cb0b5a2fec (diff) |
Merge branch 'master' into DRTVWR-514-keymappings
# Conflicts:
# indra/llui/llscrolllistctrl.cpp
Diffstat (limited to 'indra/newview/llpanelpermissions.cpp')
-rw-r--r-- | indra/newview/llpanelpermissions.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/indra/newview/llpanelpermissions.cpp b/indra/newview/llpanelpermissions.cpp index ef16427713..3e770958da 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->getLocalRect().getWidth()); + 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->getLocalRect().getWidth()); + mLabelCreatorName->setText(name, style_params); } // static |