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();
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 {

View file

@ -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<Ui::PlainShadow>(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 {

View file

@ -126,8 +126,6 @@ void ShowMenu(
not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
not_null<Ui::RpWidget*> parent,
not_null<Main::Session*> session,
rpl::producer<int> multiSelectHeightValue,
Fn<void(int)> setAddedTopScrollSkip,
Fn<void(FilterId)> choose,
bool trackActiveChatsFilter) {
const auto window = Core::App().findWindow(parent);
@ -150,15 +148,6 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
QMargins(sliderPadding, 0, sliderPadding, 0)))->entity();
const auto state = wrap->lifetime().make_state<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<QWheelEvent*> e) {
const auto pixelDelta = e->pixelDelta();
const auto angleDelta = e->angleDelta();
@ -305,19 +294,14 @@ not_null<Ui::RpWidget*> 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;
}

View file

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

View file

@ -2110,12 +2110,16 @@ QPointer<Ui::BoxContent> 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<ListBox>(std::move(controller), std::move(init));
const auto boxRaw = box.data();