Simplified geometry management of chats filters strip.

This commit is contained in:
23rd 2024-11-04 16:41:16 +03:00
parent ba0da9f59e
commit 146409844d
5 changed files with 32 additions and 43 deletions

View file

@ -344,19 +344,23 @@ void ShareBox::prepare() {
_select->raise(); _select->raise();
AddChatFiltersTabsStrip( {
this, const auto chatsFilters = AddChatFiltersTabsStrip(
_descriptor.session, this,
_select->heightValue(), _descriptor.session,
[this](int height) { [this](FilterId id) {
_additionalTopScrollSkip = height; _inner->applyChatFilter(id);
scrollToY(0);
});
chatsFilters->heightValue() | rpl::start_with_next([this](int h) {
_additionalTopScrollSkip = h;
updateScrollSkips(); updateScrollSkips();
scrollToY(0); scrollToY(0);
}, }, lifetime());
[this](FilterId id) { _select->heightValue() | rpl::start_with_next([=](int h) {
_inner->applyChatFilter(id); chatsFilters->moveToLeft(0, h);
scrollToY(0); }, chatsFilters->lifetime());
}); }
} }
int ShareBox::getTopScrollSkip() const { int ShareBox::getTopScrollSkip() const {

View file

@ -1309,8 +1309,6 @@ void Widget::toggleFiltersMenu(bool enabled) {
const auto inner = Ui::AddChatFiltersTabsStrip( const auto inner = Ui::AddChatFiltersTabsStrip(
_chatFilters.get(), _chatFilters.get(),
&session(), &session(),
rpl::single(0),
[this](int h) { updateControlsGeometry(); },
[this](FilterId id) { [this](FilterId id) {
if (controller()->activeChatsFilterCurrent() != id) { if (controller()->activeChatsFilterCurrent() != id) {
controller()->setActiveChatsFilter(id); controller()->setActiveChatsFilter(id);
@ -1322,13 +1320,14 @@ void Widget::toggleFiltersMenu(bool enabled) {
raw->resizeToWidth(width()); raw->resizeToWidth(width());
const auto shadow = Ui::CreateChild<Ui::PlainShadow>(raw); const auto shadow = Ui::CreateChild<Ui::PlainShadow>(raw);
shadow->show(); shadow->show();
inner->sizeValue() | rpl::start_with_next([=](const QSize &s) { inner->sizeValue() | rpl::start_with_next([=, this](const QSize &s) {
raw->resize(s); raw->resize(s);
shadow->setGeometry( shadow->setGeometry(
0, 0,
s.height() - shadow->height(), s.height() - shadow->height(),
s.width(), s.width(),
shadow->height()); shadow->height());
updateControlsGeometry();
}, _chatFilters->lifetime()); }, _chatFilters->lifetime());
updateControlsGeometry(); updateControlsGeometry();
} else { } else {

View file

@ -126,8 +126,6 @@ void ShowMenu(
not_null<Ui::RpWidget*> AddChatFiltersTabsStrip( not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
not_null<Main::Session*> session, not_null<Main::Session*> session,
rpl::producer<int> multiSelectHeightValue,
Fn<void(int)> setAddedTopScrollSkip,
Fn<void(FilterId)> choose, Fn<void(FilterId)> choose,
bool trackActiveChatsFilter) { bool trackActiveChatsFilter) {
const auto window = Core::App().findWindow(parent); const auto window = Core::App().findWindow(parent);
@ -150,15 +148,6 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
QMargins(sliderPadding, 0, sliderPadding, 0)))->entity(); QMargins(sliderPadding, 0, sliderPadding, 0)))->entity();
const auto state = wrap->lifetime().make_state<State>(); const auto state = wrap->lifetime().make_state<State>();
wrap->toggle(false, anim::type::instant); 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<QWheelEvent*> e) { scroll->setCustomWheelProcess([=](not_null<QWheelEvent*> e) {
const auto pixelDelta = e->pixelDelta(); const auto pixelDelta = e->pixelDelta();
const auto angleDelta = e->angleDelta(); const auto angleDelta = e->angleDelta();
@ -305,19 +294,14 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
} }
}, wrap->lifetime()); }, wrap->lifetime());
{ rpl::combine(
std::move( parent->widthValue() | rpl::filter(rpl::mappers::_1 > 0),
multiSelectHeightValue slider->heightValue() | rpl::filter(rpl::mappers::_1 > 0)
) | rpl::start_with_next([=](int height) { ) | rpl::start_with_next([=](int w, int h) {
wrap->moveToLeft(0, height); scroll->resize(w, h + scrollSt.deltax * 4);
}, wrap->lifetime()); container->resize(w, h);
wrap->heightValue() | rpl::start_with_next([=](int height) { wrap->resize(w, h);
setAddedTopScrollSkip(height); }, wrap->lifetime());
}, wrap->lifetime());
parent->widthValue() | rpl::start_with_next([=](int w) {
wrap->resizeToWidth(w);
}, wrap->lifetime());
}
return wrap; return wrap;
} }

View file

@ -20,8 +20,6 @@ namespace Ui {
not_null<Ui::RpWidget*> AddChatFiltersTabsStrip( not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
not_null<Main::Session*> session, not_null<Main::Session*> session,
rpl::producer<int> multiSelectHeightValue,
Fn<void(int)> setAddedTopScrollSkip,
Fn<void(FilterId)> choose, Fn<void(FilterId)> choose,
bool trackActiveChatsFilter = false); bool trackActiveChatsFilter = false);

View file

@ -2110,12 +2110,16 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
}); });
box->peerListRefreshRows(); box->peerListRefreshRows();
}; };
Ui::AddChatFiltersTabsStrip( const auto chatsFilters = Ui::AddChatFiltersTabsStrip(
box, box,
session, session,
box->multiSelectHeightValue(),
[=](int height) { box->setAddedTopScrollSkip(height); },
std::move(applyFilter)); 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<ListBox>(std::move(controller), std::move(init)); auto box = Box<ListBox>(std::move(controller), std::move(init));
const auto boxRaw = box.data(); const auto boxRaw = box.data();