Added ability to insert custom separators to PeerListsBox.

This commit is contained in:
23rd
2026-01-22 17:27:22 +03:00
committed by John Preston
parent 3e456dbcb9
commit 41eb626338
2 changed files with 31 additions and 5 deletions
+23 -5
View File
@@ -146,12 +146,12 @@ void PeerListsBox::updateScrollSkips() {
}
void PeerListsBox::prepare() {
auto rows = setInnerWidget(
_rows = setInnerWidget(
object_ptr<Ui::VerticalLayout>(this),
st::boxScroll);
for (auto &list : _lists) {
const auto content = rows->add(object_ptr<PeerListContent>(
rows,
const auto content = _rows->add(object_ptr<PeerListContent>(
_rows,
list.controller.get()));
list.content = content;
list.delegate->setContent(content);
@@ -176,13 +176,13 @@ void PeerListsBox::prepare() {
}
}, lifetime());
}
rows->resizeToWidth(firstController()->contentWidth());
_rows->resizeToWidth(firstController()->contentWidth());
{
setDimensions(
firstController()->contentWidth(),
std::clamp(
rows->height(),
_rows->height(),
st::boxMaxListHeight,
st::boxMaxListHeight * 3));
}
@@ -350,6 +350,24 @@ void PeerListsBox::Delegate::peerListSetForeignRowChecked(
}
}
void PeerListsBox::addSeparatorBefore(
int listIndex,
object_ptr<Ui::RpWidget> widget) {
if (listIndex < 0 || listIndex >= int(_lists.size()) || !_rows) {
return;
}
const auto position = listIndex * 2;
auto wrapped = object_ptr<Ui::SlideWrap<>>(
_rows,
std::move(widget));
_lists[listIndex].content->heightValue(
) | rpl::on_next([=, separator = wrapped.data()](int h) {
separator->toggle(h > 0, anim::type::instant);
}, wrapped->lifetime());
_lists[listIndex].separator = wrapped.data();
_rows->insert(position, std::move(wrapped));
}
void PeerListsBox::Delegate::peerListScrollToTop() {
_box->scrollToY(0);
}
@@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/peer_list_box.h"
namespace Ui {
class VerticalLayout;
} // namespace Ui
class PeerListsBox : public Ui::BoxContent {
public:
PeerListsBox(
@@ -16,6 +20,8 @@ public:
std::vector<std::unique_ptr<PeerListController>> controllers,
Fn<void(not_null<PeerListsBox*>)> init);
void addSeparatorBefore(int listIndex, object_ptr<Ui::RpWidget> widget);
[[nodiscard]] std::vector<not_null<PeerData*>> collectSelectedRows();
protected:
@@ -66,6 +72,7 @@ private:
std::unique_ptr<PeerListController> controller;
std::unique_ptr<Delegate> delegate;
PeerListContent *content = nullptr;
Ui::SlideWrap<Ui::RpWidget> *separator = nullptr;
};
friend class Delegate;
@@ -99,5 +106,6 @@ private:
std::vector<List> _lists;
Fn<void(PeerListsBox*)> _init;
bool _scrollBottomFixed = false;
Ui::VerticalLayout *_rows = nullptr;
};