From 0c17bdc783f42d7c36468418e382f612acd2a787 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 20 Jan 2023 14:11:47 +0300 Subject: [PATCH] Replaced Calls box with GenericBox. --- .../SourceFiles/window/window_main_menu.cpp | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 08f7feb2ad..5d1021418e 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -94,19 +94,36 @@ constexpr auto kPlayStatusLimit = 2; } void ShowCallsBox(not_null window) { - auto controller = std::make_unique(window); - const auto initBox = [ - window, - controller = controller.get() - ](not_null box) { + struct State { + State(not_null window) + : callsController(window) { + } + Calls::BoxController callsController; + PeerListContentDelegateSimple callsDelegate; + + base::unique_qptr menu; + }; + + window->show(Box([=](not_null box) { + const auto state = box->lifetime().make_state(window); + const auto content = box->addRow( + object_ptr(box, &state->callsController), + {}); + state->callsDelegate.setContent(content); + state->callsController.setDelegate(&state->callsDelegate); + + box->setWidth(state->callsController.contentWidth()); + state->callsController.boxHeightValue( + ) | rpl::start_with_next([=](int height) { + box->setMinHeight(height); + }, box->lifetime()); + box->setTitle(tr::lng_call_box_title()); box->addButton(tr::lng_close(), [=] { box->closeBox(); }); - using MenuPointer = base::unique_qptr; - const auto menu = std::make_shared(); const auto menuButton = box->addTopButton(st::infoTopBarMenu); menuButton->setClickedCallback([=] { - *menu = base::make_unique_q( + state->menu = base::make_unique_q( menuButton, st::popupMenuWithIcons); const auto showSettings = [=] { @@ -115,23 +132,22 @@ void ShowCallsBox(not_null window) { Window::SectionShow(anim::type::instant)); }; const auto clearAll = crl::guard(box, [=] { - box->getDelegate()->show(Box(Calls::ClearCallsBox, window)); + Ui::BoxShow(box).showBox(Box(Calls::ClearCallsBox, window)); }); - (*menu)->addAction( + state->menu->addAction( tr::lng_settings_section_call_settings(tr::now), showSettings, &st::menuIconSettings); - if (controller->delegate()->peerListFullRowsCount() > 0) { - (*menu)->addAction( + if (state->callsDelegate.peerListFullRowsCount() > 0) { + state->menu->addAction( tr::lng_call_box_clear_all(tr::now), clearAll, &st::menuIconDelete); } - (*menu)->popup(QCursor::pos()); + state->menu->popup(QCursor::pos()); return true; }); - }; - window->show(Box(std::move(controller), initBox)); + })); } [[nodiscard]] rpl::producer SetStatusLabel(