Added ability to provide data to Ui::ExpandablePeerListController.

This commit is contained in:
23rd 2024-08-21 13:26:35 +03:00
parent eb268102fc
commit d5774830d8
3 changed files with 36 additions and 36 deletions

View file

@ -229,14 +229,9 @@ void CreateModerateMessagesBox(
false, false,
st::defaultBoxCheckbox), st::defaultBoxCheckbox),
st::boxRowPadding + buttonPadding); st::boxRowPadding + buttonPadding);
const auto controller = box->lifetime().make_state<Controller>(); const auto controller = box->lifetime().make_state<Controller>(
Ui::AddExpandablePeerList( Controller::Data{ .participants = participants });
report, Ui::AddExpandablePeerList(report, controller, inner);
controller,
inner,
participants,
true,
false);
handleSubmition(report); handleSubmition(report);
const auto ids = items.front()->from()->owner().itemsToIds(items); const auto ids = items.front()->from()->owner().itemsToIds(items);
@ -293,14 +288,9 @@ void CreateModerateMessagesBox(
}, title->lifetime()); }, title->lifetime());
} }
const auto controller = box->lifetime().make_state<Controller>(); const auto controller = box->lifetime().make_state<Controller>(
Ui::AddExpandablePeerList( Controller::Data{ .participants = participants });
deleteAll, Ui::AddExpandablePeerList(deleteAll, controller, inner);
controller,
inner,
participants,
true,
false);
handleSubmition(deleteAll); handleSubmition(deleteAll);
handleConfirmation(deleteAll, controller, [=]( handleConfirmation(deleteAll, controller, [=](
@ -329,14 +319,9 @@ void CreateModerateMessagesBox(
false, false,
st::defaultBoxCheckbox), st::defaultBoxCheckbox),
st::boxRowPadding + buttonPadding); st::boxRowPadding + buttonPadding);
const auto controller = box->lifetime().make_state<Controller>(); const auto controller = box->lifetime().make_state<Controller>(
Ui::AddExpandablePeerList( Controller::Data{ .participants = participants });
ban, Ui::AddExpandablePeerList(ban, controller, inner);
controller,
inner,
participants,
true,
false);
handleSubmition(ban); handleSubmition(ban);
Ui::AddSkip(inner); Ui::AddSkip(inner);

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_peer.h" #include "data/data_peer.h"
#include "ui/controls/userpic_button.h" #include "ui/controls/userpic_button.h"
#include "ui/rect.h" #include "ui/rect.h"
#include "ui/text/text_utilities.h"
#include "ui/vertical_list.h" #include "ui/vertical_list.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/participants_check_view.h" #include "ui/widgets/participants_check_view.h"
@ -69,11 +70,13 @@ void Button::paintEvent(QPaintEvent *event) {
void AddExpandablePeerList( void AddExpandablePeerList(
not_null<Ui::Checkbox*> checkbox, not_null<Ui::Checkbox*> checkbox,
not_null<ExpandablePeerListController*> controller, not_null<ExpandablePeerListController*> controller,
not_null<Ui::VerticalLayout*> inner, not_null<Ui::VerticalLayout*> inner) {
const Participants &participants, const auto &participants = controller->data.participants;
bool handleSingle, const auto hideRightButton = controller->data.hideRightButton;
bool hideRightButton) { const auto checkTopOnAllInner = controller->data.checkTopOnAllInner;
const auto isSingle = handleSingle ? (participants.size() == 1) : false; const auto isSingle = controller->data.skipSingle
? false
: (participants.size() == 1);
if (isSingle) { if (isSingle) {
const auto p = participants.front(); const auto p = participants.front();
controller->collectRequests = [=] { return Participants{ p }; }; controller->collectRequests = [=] { return Participants{ p }; };
@ -151,8 +154,10 @@ void AddExpandablePeerList(
st); st);
const auto checkbox = Ui::CreateChild<Ui::Checkbox>( const auto checkbox = Ui::CreateChild<Ui::Checkbox>(
line, line,
peer->name(), controller->data.bold
false, ? Ui::Text::Bold(peer->name())
: TextWithEntities{ .text = peer->name() },
ranges::contains(controller->data.checked, peer->id),
st::defaultBoxCheckbox); st::defaultBoxCheckbox);
line->widthValue( line->widthValue(
) | rpl::start_with_next([=](int width) { ) | rpl::start_with_next([=](int width) {
@ -186,7 +191,9 @@ void AddExpandablePeerList(
clicks->events( clicks->events(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
controller->toggleRequestsFromInner.fire_copy( controller->toggleRequestsFromInner.fire_copy(
ranges::any_of(checkboxes, &Ui::Checkbox::checked)); checkTopOnAllInner
? ranges::all_of(checkboxes, &Ui::Checkbox::checked)
: ranges::any_of(checkboxes, &Ui::Checkbox::checked));
}, container->lifetime()); }, container->lifetime());
controller->checkAllRequests.events( controller->checkAllRequests.events(

View file

@ -17,6 +17,17 @@ class Checkbox;
class VerticalLayout; class VerticalLayout;
struct ExpandablePeerListController final { struct ExpandablePeerListController final {
struct Data final {
Participants participants;
std::vector<PeerId> checked;
bool skipSingle = false;
bool hideRightButton = false;
bool checkTopOnAllInner = false;
bool bold = true;
};
ExpandablePeerListController(Data &&data) : data(std::move(data)) {
}
const Data data;
rpl::event_stream<bool> toggleRequestsFromTop; rpl::event_stream<bool> toggleRequestsFromTop;
rpl::event_stream<bool> toggleRequestsFromInner; rpl::event_stream<bool> toggleRequestsFromInner;
rpl::event_stream<bool> checkAllRequests; rpl::event_stream<bool> checkAllRequests;
@ -26,9 +37,6 @@ struct ExpandablePeerListController final {
void AddExpandablePeerList( void AddExpandablePeerList(
not_null<Ui::Checkbox*> checkbox, not_null<Ui::Checkbox*> checkbox,
not_null<ExpandablePeerListController*> controller, not_null<ExpandablePeerListController*> controller,
not_null<Ui::VerticalLayout*> inner, not_null<Ui::VerticalLayout*> inner);
const Participants &participants,
bool handleSingle,
bool hideRightButton);
} // namespace Ui } // namespace Ui