From cbd9dd0c2c7dbb3eb7fe06380879db2cf530b40d Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 9 Feb 2023 12:17:16 +0400 Subject: [PATCH] Allow either category or set being selected. --- .../chat_helpers/emoji_list_widget.cpp | 15 ++++++++++--- .../chat_helpers/gifs_list_widget.cpp | 15 +++++++++---- .../chat_helpers/stickers_list_footer.cpp | 22 ++++++++++++++++--- .../chat_helpers/stickers_list_widget.cpp | 11 ++++++++++ .../chat_helpers/stickers_list_widget.h | 1 + 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 1e4ec87f0..5748cbc9a 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -485,7 +485,10 @@ void EmojiListWidget::applyNextSearchQuery() { if (!_searchMode && !searching) { return; } - _searchMode = searching; + const auto modeChanged = (_searchMode != searching); + if (modeChanged) { + _searchMode = searching; + } if (!searching) { _searchResults.clear(); _searchCustomIds.clear(); @@ -493,6 +496,9 @@ void EmojiListWidget::applyNextSearchQuery() { clearSelection(); resizeToWidth(width()); update(); + if (modeChanged) { + visibleTopBottomUpdated(getVisibleTop(), getVisibleBottom()); + } }; if (_searchQuery.empty()) { finish(false); @@ -2190,10 +2196,13 @@ void EmojiListWidget::showSet(uint64 setId) { } uint64 EmojiListWidget::sectionSetId(int section) const { - Expects(section < _staticCount + Expects(_searchMode + || section < _staticCount || (section - _staticCount) < _custom.size()); - return (section < _staticCount) + return _searchMode + ? SearchEmojiSectionSetId() + : (section < _staticCount) ? EmojiSectionSetId(static_cast
(section)) : _custom[section - _staticCount].id; } diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 56ff0c35b..fae4dd8f6 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -161,6 +161,7 @@ object_ptr GifsListWidget::createFooter() { .st = &st(), }); _footer = result; + _chosenSetId = Data::Stickers::RecentSetId; GifSectionsValue( &session() @@ -171,6 +172,9 @@ object_ptr GifsListWidget::createFooter() { _footer->setChosen( ) | rpl::start_with_next([=](uint64 setId) { + if (_search) { + _search->cancel(); + } _chosenSetId = setId; refreshIcons(); const auto i = ranges::find(_sections, setId, [](GifSection value) { @@ -791,13 +795,16 @@ bool GifsListWidget::refreshInlineRows(int32 *added) { void GifsListWidget::setupSearch() { const auto session = &_controller->session(); _search = MakeSearch(this, st(), [=](std::vector &&query) { - _chosenSetId = Data::Stickers::RecentSetId; - refreshIcons(); - searchForGifs(ranges::accumulate(query, QString(), []( + const auto accumulated = ranges::accumulate(query, QString(), []( QString a, QString b) { return a.isEmpty() ? b : (a + ' ' + b); - })); + }); + _chosenSetId = accumulated.isEmpty() + ? Data::Stickers::RecentSetId + : SearchEmojiSectionSetId(); + refreshIcons(); + searchForGifs(accumulated); }, session); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp index bb4879510..a846b5362 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp @@ -417,6 +417,16 @@ void StickersListFooter::enumerateSubicons( } auto StickersListFooter::iconInfo(int index) const -> IconInfo { + if (index < 0) { + const auto iconsX = int(base::SafeRound(_iconState.x.current())); + return { + .index = -1, + .left = -_singleWidth - _iconsLeft, + .adjustedLeft = -_singleWidth - _iconsLeft - iconsX, + .width = _singleWidth, + .visible = false, + }; + } auto result = IconInfo(); enumerateIcons([&](const IconInfo &info) { if (info.index == index) { @@ -473,7 +483,8 @@ void StickersListFooter::validateSelectedIcon( && setId == Data::Stickers::RecentSetId)) { newSelected = i; break; - } else if (_icons[i].setId == Data::Stickers::FavedSetId) { + } else if (_icons[i].setId == Data::Stickers::FavedSetId + && setId != SearchEmojiSectionSetId()) { favedIconIndex = i; } else if (isEmojiSection && _icons[i].setId == allEmojiSetId) { newSelected = i; @@ -483,7 +494,9 @@ void StickersListFooter::validateSelectedIcon( setSelectedIcon( (newSelected >= 0 ? newSelected - : (favedIconIndex >= 0) ? favedIconIndex : 0), + : (favedIconIndex >= 0) + ? favedIconIndex + : -1), animations); setSelectedSubicon( (newSubSelected >= 0 ? newSubSelected : 0), @@ -522,6 +535,9 @@ void StickersListFooter::setSelectedIcon( if (_iconState.selected == newSelected) { return; } + if ((_iconState.selected < 0) != (newSelected < 0)) { + animations = ValidateIconAnimations::None; + } _iconState.selected = newSelected; updateEmojiSectionWidth(); const auto info = iconInfo(_iconState.selected); @@ -1113,7 +1129,7 @@ void StickersListFooter::refreshIconsGeometry( (st().footer - st().iconArea) / 2); refreshScrollableDimensions(); refreshSubiconsGeometry(); - _iconState.selected = _subiconState.selected = -1; + _iconState.selected = _subiconState.selected = -2; validateSelectedIcon(activeSetId, animations); update(); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 463c25ae3..0285b5656 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -2463,7 +2463,18 @@ auto StickersListWidget::getLottieRenderer() } void StickersListWidget::showStickerSet(uint64 setId) { + if (_showingSetById) { + return; + } + _showingSetById = true; + const auto guard = gsl::finally([&] { _showingSetById = false; }); + clearSelection(); + if (_search + && (!_searchQuery.isEmpty() || !_searchNextQuery.isEmpty())) { + _search->cancel(); + cancelSetsSearch(); + } if (setId == Data::Stickers::FeaturedSetId) { if (_section != Section::Featured) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 0a76937b9..1c0d8445c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -355,6 +355,7 @@ private: base::flat_set> _favedStickersMap; std::weak_ptr _lottieRenderer; + bool _showingSetById = false; crl::time _lastScrolledAt = 0; crl::time _lastFullUpdatedAt = 0;