From 41eb6263382c8cce0f489dfa3d5b2f1b325e36bb Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 22 Jan 2026 17:27:22 +0300 Subject: [PATCH] Added ability to insert custom separators to PeerListsBox. --- Telegram/SourceFiles/boxes/peer_lists_box.cpp | 28 +++++++++++++++---- Telegram/SourceFiles/boxes/peer_lists_box.h | 8 ++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peer_lists_box.cpp b/Telegram/SourceFiles/boxes/peer_lists_box.cpp index 4506075cec..fbc0b50dff 100644 --- a/Telegram/SourceFiles/boxes/peer_lists_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_lists_box.cpp @@ -146,12 +146,12 @@ void PeerListsBox::updateScrollSkips() { } void PeerListsBox::prepare() { - auto rows = setInnerWidget( + _rows = setInnerWidget( object_ptr(this), st::boxScroll); for (auto &list : _lists) { - const auto content = rows->add(object_ptr( - rows, + const auto content = _rows->add(object_ptr( + _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 widget) { + if (listIndex < 0 || listIndex >= int(_lists.size()) || !_rows) { + return; + } + const auto position = listIndex * 2; + auto wrapped = object_ptr>( + _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); } diff --git a/Telegram/SourceFiles/boxes/peer_lists_box.h b/Telegram/SourceFiles/boxes/peer_lists_box.h index 20377548a4..5348269a98 100644 --- a/Telegram/SourceFiles/boxes/peer_lists_box.h +++ b/Telegram/SourceFiles/boxes/peer_lists_box.h @@ -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> controllers, Fn)> init); + void addSeparatorBefore(int listIndex, object_ptr widget); + [[nodiscard]] std::vector> collectSelectedRows(); protected: @@ -66,6 +72,7 @@ private: std::unique_ptr controller; std::unique_ptr delegate; PeerListContent *content = nullptr; + Ui::SlideWrap *separator = nullptr; }; friend class Delegate; @@ -99,5 +106,6 @@ private: std::vector _lists; Fn _init; bool _scrollBottomFixed = false; + Ui::VerticalLayout *_rows = nullptr; };