From 146409844da18e9535bb8d84173a5b67e11c13be Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 4 Nov 2024 16:41:16 +0300 Subject: [PATCH] Simplified geometry management of chats filters strip. --- Telegram/SourceFiles/boxes/share_box.cpp | 26 ++++++++------- .../SourceFiles/dialogs/dialogs_widget.cpp | 5 ++- .../ui/widgets/chat_filters_tabs_strip.cpp | 32 +++++-------------- .../ui/widgets/chat_filters_tabs_strip.h | 2 -- .../SourceFiles/window/window_peer_menu.cpp | 10 ++++-- 5 files changed, 32 insertions(+), 43 deletions(-) diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 6550b3e10..8551a4f7e 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -344,19 +344,23 @@ void ShareBox::prepare() { _select->raise(); - AddChatFiltersTabsStrip( - this, - _descriptor.session, - _select->heightValue(), - [this](int height) { - _additionalTopScrollSkip = height; + { + const auto chatsFilters = AddChatFiltersTabsStrip( + this, + _descriptor.session, + [this](FilterId id) { + _inner->applyChatFilter(id); + scrollToY(0); + }); + chatsFilters->heightValue() | rpl::start_with_next([this](int h) { + _additionalTopScrollSkip = h; updateScrollSkips(); scrollToY(0); - }, - [this](FilterId id) { - _inner->applyChatFilter(id); - scrollToY(0); - }); + }, lifetime()); + _select->heightValue() | rpl::start_with_next([=](int h) { + chatsFilters->moveToLeft(0, h); + }, chatsFilters->lifetime()); + } } int ShareBox::getTopScrollSkip() const { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index df00ed494..4746532e1 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1309,8 +1309,6 @@ void Widget::toggleFiltersMenu(bool enabled) { const auto inner = Ui::AddChatFiltersTabsStrip( _chatFilters.get(), &session(), - rpl::single(0), - [this](int h) { updateControlsGeometry(); }, [this](FilterId id) { if (controller()->activeChatsFilterCurrent() != id) { controller()->setActiveChatsFilter(id); @@ -1322,13 +1320,14 @@ void Widget::toggleFiltersMenu(bool enabled) { raw->resizeToWidth(width()); const auto shadow = Ui::CreateChild(raw); shadow->show(); - inner->sizeValue() | rpl::start_with_next([=](const QSize &s) { + inner->sizeValue() | rpl::start_with_next([=, this](const QSize &s) { raw->resize(s); shadow->setGeometry( 0, s.height() - shadow->height(), s.width(), shadow->height()); + updateControlsGeometry(); }, _chatFilters->lifetime()); updateControlsGeometry(); } else { diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp index f44cc38b8..95e224eb1 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp @@ -126,8 +126,6 @@ void ShowMenu( not_null AddChatFiltersTabsStrip( not_null parent, not_null session, - rpl::producer multiSelectHeightValue, - Fn setAddedTopScrollSkip, Fn choose, bool trackActiveChatsFilter) { const auto window = Core::App().findWindow(parent); @@ -150,15 +148,6 @@ not_null AddChatFiltersTabsStrip( QMargins(sliderPadding, 0, sliderPadding, 0)))->entity(); const auto state = wrap->lifetime().make_state(); wrap->toggle(false, anim::type::instant); - container->sizeValue() | rpl::start_with_next([=](const QSize &s) { - scroll->resize(s + QSize(0, scrollSt.deltax * 4)); - }, scroll->lifetime()); - rpl::combine( - parent->widthValue(), - slider->heightValue() - ) | rpl::start_with_next([=](int w, int h) { - container->resize(w, h); - }, wrap->lifetime()); scroll->setCustomWheelProcess([=](not_null e) { const auto pixelDelta = e->pixelDelta(); const auto angleDelta = e->angleDelta(); @@ -305,19 +294,14 @@ not_null AddChatFiltersTabsStrip( } }, wrap->lifetime()); - { - std::move( - multiSelectHeightValue - ) | rpl::start_with_next([=](int height) { - wrap->moveToLeft(0, height); - }, wrap->lifetime()); - wrap->heightValue() | rpl::start_with_next([=](int height) { - setAddedTopScrollSkip(height); - }, wrap->lifetime()); - parent->widthValue() | rpl::start_with_next([=](int w) { - wrap->resizeToWidth(w); - }, wrap->lifetime()); - } + rpl::combine( + parent->widthValue() | rpl::filter(rpl::mappers::_1 > 0), + slider->heightValue() | rpl::filter(rpl::mappers::_1 > 0) + ) | rpl::start_with_next([=](int w, int h) { + scroll->resize(w, h + scrollSt.deltax * 4); + container->resize(w, h); + wrap->resize(w, h); + }, wrap->lifetime()); return wrap; } diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h index d57cfdda3..229471b8e 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h @@ -20,8 +20,6 @@ namespace Ui { not_null AddChatFiltersTabsStrip( not_null parent, not_null session, - rpl::producer multiSelectHeightValue, - Fn setAddedTopScrollSkip, Fn choose, bool trackActiveChatsFilter = false); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index c93c9fecc..78b3e2a2c 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -2110,12 +2110,16 @@ QPointer ShowForwardMessagesBox( }); box->peerListRefreshRows(); }; - Ui::AddChatFiltersTabsStrip( + const auto chatsFilters = Ui::AddChatFiltersTabsStrip( box, session, - box->multiSelectHeightValue(), - [=](int height) { box->setAddedTopScrollSkip(height); }, std::move(applyFilter)); + chatsFilters->heightValue() | rpl::start_with_next([box](int h) { + box->setAddedTopScrollSkip(h); + }, box->lifetime()); + box->multiSelectHeightValue() | rpl::start_with_next([=](int h) { + chatsFilters->moveToLeft(0, h); + }, chatsFilters->lifetime()); }; auto box = Box(std::move(controller), std::move(init)); const auto boxRaw = box.data();