From 7a61693034b260084b2ce99463e394526c279df3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 28 Jul 2022 18:15:18 +0300 Subject: [PATCH] Limit attached emoji phrase to two lines. --- .../view/history_view_context_menu.cpp | 23 +++++++++++++++++++ Telegram/SourceFiles/ui/chat/chat.style | 6 ++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 0c0adf808..f4915dcce 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -1267,6 +1267,7 @@ void AddEmojiPacksAction( , _dummyAction(new QAction(parent)) { enableMouseSelecting(); _text->setAttribute(Qt::WA_TransparentForMouseEvents); + updateMinWidth(); parent->widthValue() | rpl::start_with_next([=](int width) { const auto top = st::historyHasCustomEmojiPosition.y(); const auto skip = st::historyHasCustomEmojiPosition.x(); @@ -1297,6 +1298,28 @@ void AddEmojiPacksAction( RippleButton::paintRipple(p, 0, 0); } + void updateMinWidth() { + const auto skip = st::historyHasCustomEmojiPosition.x(); + auto min = _text->naturalWidth() / 2; + auto max = _text->naturalWidth() - skip; + _text->resizeToWidth(max); + const auto height = _text->height(); + _text->resizeToWidth(min); + const auto heightMax = _text->height(); + if (heightMax > height) { + while (min + 1 < max) { + const auto middle = (max + min) / 2; + _text->resizeToWidth(middle); + if (_text->height() > height) { + min = middle; + } else { + max = middle; + } + } + } + setMinWidth(skip * 2 + max); + } + const style::Menu &_st; const base::unique_qptr _text; const not_null _dummyAction; diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 4e245b622..a31cbe5b3 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -1090,9 +1090,9 @@ msgServiceGiftBoxStickerSize: size(140px, 140px); historyHasCustomEmoji: FlatLabel(defaultFlatLabel) { style: TextStyle(defaultTextStyle) { - font: font(12px); - linkFont: font(12px underline); - linkFontOver: font(12px underline); + font: font(11px); + linkFont: font(11px underline); + linkFontOver: font(11px underline); } minWidth: 80px; }