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

View file

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

View file

@ -17,6 +17,17 @@ class Checkbox;
class VerticalLayout;
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> toggleRequestsFromInner;
rpl::event_stream<bool> checkAllRequests;
@ -26,9 +37,6 @@ struct ExpandablePeerListController final {
void AddExpandablePeerList(
not_null<Ui::Checkbox*> checkbox,
not_null<ExpandablePeerListController*> controller,
not_null<Ui::VerticalLayout*> inner,
const Participants &participants,
bool handleSingle,
bool hideRightButton);
not_null<Ui::VerticalLayout*> inner);
} // namespace Ui