diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index 2165833206..36f9ad9797 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -122,8 +122,10 @@ void FiltersMenu::setup() { const auto j = _filters.find(_activeFilterId); if (j != end(_filters)) { j->second->setActive(true); + scrollToButton(j->second); } else if (!_activeFilterId) { _all->setActive(true); + scrollToButton(_all); } }, _outer.lifetime()); @@ -132,6 +134,32 @@ void FiltersMenu::setup() { }); } +void FiltersMenu::scrollToButton(not_null widget) { + const auto globalPosition = widget->mapToGlobal(QPoint(0, 0)); + const auto localTop = _scroll.mapFromGlobal(globalPosition).y(); + const auto localBottom = localTop + widget->height() - _scroll.height(); + const auto isTopEdge = (localTop < 0); + const auto isBottomEdge = (localBottom > 0); + if (!isTopEdge && !isBottomEdge) { + return; + } + + _scrollToAnimation.stop(); + const auto scrollTop = _scroll.scrollTop(); + const auto scrollTo = scrollTop + (isBottomEdge ? localBottom : localTop); + + auto scroll = [=] { + _scroll.scrollToY(qRound(_scrollToAnimation.value(scrollTo))); + }; + + _scrollToAnimation.start( + std::move(scroll), + scrollTop, + scrollTo, + st::slideDuration, + anim::sineInOut); +} + void FiltersMenu::refresh() { const auto filters = &_session->session().data().chatsFilters(); if (filters->list().empty() || _ignoreRefresh) { diff --git a/Telegram/SourceFiles/window/window_filters_menu.h b/Telegram/SourceFiles/window/window_filters_menu.h index 34aea5a6b4..347aac0a93 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.h +++ b/Telegram/SourceFiles/window/window_filters_menu.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" #include "ui/widgets/side_bar_button.h" #include "ui/widgets/scroll_area.h" #include "ui/wrap/vertical_layout.h" @@ -49,6 +50,7 @@ private: void showEditBox(FilterId id); void showRemoveBox(FilterId id); void remove(FilterId id); + void scrollToButton(not_null widget); const not_null _session; const not_null _parent; @@ -68,6 +70,8 @@ private: base::unique_qptr _popupMenu; + Ui::Animations::Simple _scrollToAnimation; + }; } // namespace Window