diff --git a/Telegram/SourceFiles/boxes/single_choice_box.cpp b/Telegram/SourceFiles/boxes/single_choice_box.cpp index ea2cf9a105..718687be15 100644 --- a/Telegram/SourceFiles/boxes/single_choice_box.cpp +++ b/Telegram/SourceFiles/boxes/single_choice_box.cpp @@ -16,56 +16,42 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" #include "styles/style_layers.h" -SingleChoiceBox::SingleChoiceBox( - QWidget*, - rpl::producer title, - const std::vector &optionTexts, - int initialSelection, - Fn callback, - const style::Checkbox *st, - const style::Radio *radioSt) -: _title(std::move(title)) -, _optionTexts(optionTexts) -, _initialSelection(initialSelection) -, _callback(callback) -, _st(st ? *st : st::defaultBoxCheckbox) -, _radioSt(radioSt ? *radioSt : st::defaultRadio) { -} +void SingleChoiceBox( + not_null box, + SingleChoiceBoxArgs &&args) { + box->setTitle(std::move(args.title)); -void SingleChoiceBox::prepare() { - setTitle(std::move(_title)); + box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); }); - addButton(tr::lng_box_ok(), [=] { closeBox(); }); + const auto group = std::make_shared( + args.initialSelection); - const auto group = std::make_shared(_initialSelection); - - const auto content = Ui::CreateChild(this); - content->add(object_ptr( - content, + const auto layout = box->verticalLayout(); + layout->add(object_ptr( + layout, st::boxOptionListPadding.top() + st::autolockButton.margin.top())); auto &&ints = ranges::view::ints(0, ranges::unreachable); - for (const auto &[i, text] : ranges::view::zip(ints, _optionTexts)) { - content->add( + for (const auto &[i, text] : ranges::view::zip(ints, args.options)) { + layout->add( object_ptr( - content, + layout, group, i, text, - _st, - _radioSt), + args.st ? *args.st : st::defaultBoxCheckbox, + args.radioSt ? *args.radioSt : st::defaultRadio), QMargins( st::boxPadding.left() + st::boxOptionListPadding.left(), 0, st::boxPadding.right(), st::boxOptionListSkip)); } + const auto callback = args.callback.value(); group->setChangedCallback([=](int value) { - const auto weak = Ui::MakeWeak(this); - _callback(value); + const auto weak = Ui::MakeWeak(box); + callback(value); if (weak) { - closeBox(); + box->closeBox(); } }); - setDimensionsToContent(st::boxWidth, content); } - diff --git a/Telegram/SourceFiles/boxes/single_choice_box.h b/Telegram/SourceFiles/boxes/single_choice_box.h index 2a83c8e294..4964d3b057 100644 --- a/Telegram/SourceFiles/boxes/single_choice_box.h +++ b/Telegram/SourceFiles/boxes/single_choice_box.h @@ -7,38 +7,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "boxes/abstract_box.h" -#include - -namespace Ui { -class Radiobutton; -} // namespace Ui +#include "ui/layers/generic_box.h" +#include "base/required.h" namespace style { struct Checkbox; +struct Radio; } // namespace style -class SingleChoiceBox : public Ui::BoxContent { -public: - SingleChoiceBox( - QWidget*, - rpl::producer title, - const std::vector &optionTexts, - int initialSelection, - Fn callback, - const style::Checkbox *st = nullptr, - const style::Radio *radioSt = nullptr); - -protected: - void prepare() override; - -private: - rpl::producer _title; - std::vector _optionTexts; - int _initialSelection = 0; - Fn _callback; - const style::Checkbox &_st; - const style::Radio &_radioSt; +struct SingleChoiceBoxArgs { + template + using required = base::required; + required> title; + const std::vector &options; + int initialSelection = 0; + required> callback; + const style::Checkbox *st = nullptr; + const style::Radio *radioSt = nullptr; }; +void SingleChoiceBox( + not_null box, + SingleChoiceBoxArgs &&args); diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index 94d981359d..dc0d49eff0 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -124,11 +124,14 @@ void Calls::setupContent() { call->setCurrentVideoDevice(deviceId); } }); - Ui::show(Box( - tr::lng_settings_call_camera(), - options, - currentOption, - save)); + Ui::show(Box([=](not_null box) { + SingleChoiceBox(box, { + .title = tr::lng_settings_call_camera(), + .options = options, + .initialSelection = currentOption, + .callback = save, + }); + })); }); const auto bubbleWrap = content->add(object_ptr(content)); const auto bubble = content->lifetime().make_state<::Calls::VideoBubble>( @@ -366,7 +369,7 @@ QString CurrentAudioInputName() { : tr::lng_settings_call_device_default(tr::now); } -object_ptr ChooseAudioOutputBox( +object_ptr ChooseAudioOutputBox( Fn chosen, const style::Checkbox *st, const style::Radio *radioSt) { @@ -390,16 +393,19 @@ object_ptr ChooseAudioOutputBox( Core::App().calls().setCurrentAudioDevice(false, deviceId); chosen(deviceId, options[option]); }; - return Box( - tr::lng_settings_call_output_device(), - options, - currentOption, - save, - st, - radioSt); + return Box([=](not_null box) { + SingleChoiceBox(box, { + .title = tr::lng_settings_call_output_device(), + .options = options, + .initialSelection = currentOption, + .callback = save, + .st = st, + .radioSt = radioSt, + }); + }); } -object_ptr ChooseAudioInputBox( +object_ptr ChooseAudioInputBox( Fn chosen, const style::Checkbox *st, const style::Radio *radioSt) { @@ -423,16 +429,19 @@ object_ptr ChooseAudioInputBox( Core::App().calls().setCurrentAudioDevice(true, deviceId); chosen(deviceId, options[option]); }; - return Box( - tr::lng_settings_call_input_device(), - options, - currentOption, - save, - st, - radioSt); + return Box([=](not_null box) { + SingleChoiceBox(box, { + .title = tr::lng_settings_call_input_device(), + .options = options, + .initialSelection = currentOption, + .callback = save, + .st = st, + .radioSt = radioSt, + }); + }); } - -//object_ptr ChooseAudioBackendBox( +// +//object_ptr ChooseAudioBackendBox( // const style::Checkbox *st, // const style::Radio *radioSt) { // const auto &settings = Core::App().settings(); @@ -451,13 +460,16 @@ object_ptr ChooseAudioInputBox( // Core::App().saveSettings(); // App::restart(); // }; -// return Box( -// rpl::single("Calls audio backend"), -// options, -// currentOption, -// save, -// st, -// radioSt); +// return Box([=](not_null box) { +// SingleChoiceBox(box, { +// .title = rpl::single("Calls audio backend"), +// .options = options, +// .initialSelection = currentOption, +// .callback = save, +// .st = st, +// .radioSt = radioSt, +// }); +// }); //} } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_calls.h b/Telegram/SourceFiles/settings/settings_calls.h index 068208242c..679b167fa8 100644 --- a/Telegram/SourceFiles/settings/settings_calls.h +++ b/Telegram/SourceFiles/settings/settings_calls.h @@ -22,14 +22,13 @@ class Call; namespace Ui { class LevelMeter; +class GenericBox; } // namespace Ui namespace Webrtc { class AudioInputTester; } // namespace Webrtc -class SingleChoiceBox; - namespace Settings { class Calls : public Section { @@ -61,17 +60,17 @@ inline constexpr auto kMicTestAnimationDuration = crl::time(200); [[nodiscard]] QString CurrentAudioOutputName(); [[nodiscard]] QString CurrentAudioInputName(); -[[nodiscard]] object_ptr ChooseAudioOutputBox( +[[nodiscard]] object_ptr ChooseAudioOutputBox( Fn chosen, const style::Checkbox *st = nullptr, const style::Radio *radioSt = nullptr); -[[nodiscard]] object_ptr ChooseAudioInputBox( +[[nodiscard]] object_ptr ChooseAudioInputBox( Fn chosen, const style::Checkbox *st = nullptr, const style::Radio *radioSt = nullptr); -[[nodiscard]] object_ptr ChooseAudioBackendBox( - const style::Checkbox *st = nullptr, - const style::Radio *radioSt = nullptr); +//[[nodiscard]] object_ptr ChooseAudioBackendBox( +// const style::Checkbox *st = nullptr, +// const style::Radio *radioSt = nullptr); } // namespace Settings