From 4f18535f8d4008d6c85ca713149e8810182b74ed Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 24 Jan 2023 12:11:09 +0400 Subject: [PATCH] Implement nice emoji categories scrolling. --- .../calls/group/calls_group_members_row.cpp | 2 +- .../chat_helpers/chat_helpers.style | 4 +- .../chat_helpers/emoji_list_widget.cpp | 4 +- .../chat_helpers/stickers_list_footer.cpp | 4 - .../chat_helpers/stickers_list_footer.h | 2 - .../inline_bots/inline_results_widget.cpp | 1 - .../inline_bots/inline_results_widget.h | 1 - .../SourceFiles/ui/controls/tabbed_search.cpp | 250 +++++++++++++++--- .../SourceFiles/ui/controls/tabbed_search.h | 18 +- Telegram/lib_ui | 2 +- 10 files changed, 242 insertions(+), 46 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp b/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp index 3bba7087c..96a31fcb9 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp @@ -656,7 +656,7 @@ void MembersRow::paintComplexStatusText( (_mutedByMe ? tr::lng_group_call_muted_by_me_status(tr::now) : !about.isEmpty() - ? font->m.elidedText(about, Qt::ElideRight, availableWidth) + ? font->elided(about, availableWidth) : _delegate->rowIsMe(peer()) ? tr::lng_status_connecting(tr::now) : tr::lng_group_call_invited_status(tr::now))); diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index 2a10d0a95..fba45fefb 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -24,6 +24,7 @@ TabbedSearch { cancel: CrossButton; defaultFieldWidth: pixels; groupWidth: pixels; + groupSkip: pixels; height: pixels; } @@ -248,8 +249,9 @@ defaultTabbedSearch: TabbedSearch { loadingPeriod: 1000; ripple: emptyRippleAnimation; } - defaultFieldWidth: 101px; + defaultFieldWidth: 103px; groupWidth: 30px; + groupSkip: 2px; height: 33px; } defaultEmojiPan: EmojiPan { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 392f271ed..177b16caf 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -476,7 +476,9 @@ void EmojiListWidget::setupSearch() { .groups = (_mode == Mode::EmojiStatus ? session().data().emojiStatuses().statusGroupsValue() : session().data().emojiStatuses().emojiGroupsValue()), - .customEmojiFactory = session().data().customEmojiManager().factory() + .customEmojiFactory = session().data().customEmojiManager().factory( + Data::CustomEmojiManager::SizeTag::SetIcon, + Ui::SearchWithGroups::IconSizeOverride()) }); _search->queryValue( ) | rpl::start_with_next([=](std::vector &&query) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp index 24981175d..fa573e5da 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp @@ -549,7 +549,6 @@ void StickersListFooter::processHideFinished() { _subiconState.animation.stop(); _subiconState.animationStart = 0; _subiconState.x.finish(); - _horizontal = false; } void StickersListFooter::leaveToChildEvent(QEvent *e, QWidget *child) { @@ -943,9 +942,6 @@ void StickersListFooter::scrollByWheelEvent( if (!horizontal && !vertical) { return; } - if (horizontal) { - _horizontal = true; - } auto delta = horizontal ? ((rtl() ? -1 : 1) * (e->pixelDelta().x() ? e->pixelDelta().x() diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h index 4d64e85c4..07b8b0397 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h @@ -304,8 +304,6 @@ private: bool _barSelection = false; bool _repaintScheduled = false; - bool _horizontal = false; - bool _searchShown = false; object_ptr _searchField = { nullptr }; object_ptr _searchCancel = { nullptr }; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 37320de40..ea3d94152 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -285,7 +285,6 @@ void Widget::hideFinished() { _a_show.stop(); _showAnimation.reset(); _cache = QPixmap(); - _horizontal = false; _hiding = false; _scroll->scrollToY(0); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index 7f8079680..7a26bcaf8 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -129,7 +129,6 @@ private: int _contentMaxHeight = 0; int _contentHeight = 0; - bool _horizontal = false; int _width = 0; int _height = 0; diff --git a/Telegram/SourceFiles/ui/controls/tabbed_search.cpp b/Telegram/SourceFiles/ui/controls/tabbed_search.cpp index 8fd8e822b..3cfacb680 100644 --- a/Telegram/SourceFiles/ui/controls/tabbed_search.cpp +++ b/Telegram/SourceFiles/ui/controls/tabbed_search.cpp @@ -15,10 +15,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rect.h" #include "styles/style_chat_helpers.h" +#include + namespace Ui { namespace { constexpr auto kDebounceTimeout = crl::time(400); +constexpr auto kCategoryIconSizeOverride = 22; class GroupsStrip final : public RpWidget { public: @@ -28,23 +31,35 @@ public: rpl::producer> groups, Text::CustomEmojiFactory factory); - [[nodiscard]] rpl::producer chosen() const; + void scrollByWheel(QWheelEvent *e); + + struct Chosen { + not_null group; + int iconLeft = 0; + int iconRight = 0; + }; + [[nodiscard]] rpl::producer chosen() const; void clearChosen(); + [[nodiscard]] rpl::producer moveRequests() const; + private: struct Button { EmojiGroup group; QString iconId; - std::unique_ptr icon; + std::unique_ptr icon; }; void init(rpl::producer> groups); void set(std::vector list); void paintEvent(QPaintEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; + void fireChosenGroup(); + static inline auto FindById(auto &&buttons, QStringView id) { return ranges::find(buttons, id, &Button::iconId); } @@ -53,8 +68,10 @@ private: const Text::CustomEmojiFactory _factory; std::vector