mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-27 07:52:57 +02:00
Implement SingleChoiceBox using Ui::GenericBox.
This commit is contained in:
parent
eb11185de7
commit
cb2d77d386
4 changed files with 82 additions and 97 deletions
|
@ -16,56 +16,42 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
|
||||||
SingleChoiceBox::SingleChoiceBox(
|
void SingleChoiceBox(
|
||||||
QWidget*,
|
not_null<Ui::GenericBox*> box,
|
||||||
rpl::producer<QString> title,
|
SingleChoiceBoxArgs &&args) {
|
||||||
const std::vector<QString> &optionTexts,
|
box->setTitle(std::move(args.title));
|
||||||
int initialSelection,
|
|
||||||
Fn<void(int)> 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::prepare() {
|
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
|
||||||
setTitle(std::move(_title));
|
|
||||||
|
|
||||||
addButton(tr::lng_box_ok(), [=] { closeBox(); });
|
const auto group = std::make_shared<Ui::RadiobuttonGroup>(
|
||||||
|
args.initialSelection);
|
||||||
|
|
||||||
const auto group = std::make_shared<Ui::RadiobuttonGroup>(_initialSelection);
|
const auto layout = box->verticalLayout();
|
||||||
|
layout->add(object_ptr<Ui::FixedHeightWidget>(
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
layout,
|
||||||
content->add(object_ptr<Ui::FixedHeightWidget>(
|
|
||||||
content,
|
|
||||||
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
|
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
|
||||||
auto &&ints = ranges::view::ints(0, ranges::unreachable);
|
auto &&ints = ranges::view::ints(0, ranges::unreachable);
|
||||||
for (const auto &[i, text] : ranges::view::zip(ints, _optionTexts)) {
|
for (const auto &[i, text] : ranges::view::zip(ints, args.options)) {
|
||||||
content->add(
|
layout->add(
|
||||||
object_ptr<Ui::Radiobutton>(
|
object_ptr<Ui::Radiobutton>(
|
||||||
content,
|
layout,
|
||||||
group,
|
group,
|
||||||
i,
|
i,
|
||||||
text,
|
text,
|
||||||
_st,
|
args.st ? *args.st : st::defaultBoxCheckbox,
|
||||||
_radioSt),
|
args.radioSt ? *args.radioSt : st::defaultRadio),
|
||||||
QMargins(
|
QMargins(
|
||||||
st::boxPadding.left() + st::boxOptionListPadding.left(),
|
st::boxPadding.left() + st::boxOptionListPadding.left(),
|
||||||
0,
|
0,
|
||||||
st::boxPadding.right(),
|
st::boxPadding.right(),
|
||||||
st::boxOptionListSkip));
|
st::boxOptionListSkip));
|
||||||
}
|
}
|
||||||
|
const auto callback = args.callback.value();
|
||||||
group->setChangedCallback([=](int value) {
|
group->setChangedCallback([=](int value) {
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(box);
|
||||||
_callback(value);
|
callback(value);
|
||||||
if (weak) {
|
if (weak) {
|
||||||
closeBox();
|
box->closeBox();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setDimensionsToContent(st::boxWidth, content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,38 +7,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "boxes/abstract_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include <vector>
|
#include "base/required.h"
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
class Radiobutton;
|
|
||||||
} // namespace Ui
|
|
||||||
|
|
||||||
namespace style {
|
namespace style {
|
||||||
struct Checkbox;
|
struct Checkbox;
|
||||||
|
struct Radio;
|
||||||
} // namespace style
|
} // namespace style
|
||||||
|
|
||||||
class SingleChoiceBox : public Ui::BoxContent {
|
struct SingleChoiceBoxArgs {
|
||||||
public:
|
template <typename T>
|
||||||
SingleChoiceBox(
|
using required = base::required<T>;
|
||||||
QWidget*,
|
|
||||||
rpl::producer<QString> title,
|
|
||||||
const std::vector<QString> &optionTexts,
|
|
||||||
int initialSelection,
|
|
||||||
Fn<void(int)> callback,
|
|
||||||
const style::Checkbox *st = nullptr,
|
|
||||||
const style::Radio *radioSt = nullptr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void prepare() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
rpl::producer<QString> _title;
|
|
||||||
std::vector<QString> _optionTexts;
|
|
||||||
int _initialSelection = 0;
|
|
||||||
Fn<void(int)> _callback;
|
|
||||||
const style::Checkbox &_st;
|
|
||||||
const style::Radio &_radioSt;
|
|
||||||
|
|
||||||
|
required<rpl::producer<QString>> title;
|
||||||
|
const std::vector<QString> &options;
|
||||||
|
int initialSelection = 0;
|
||||||
|
required<Fn<void(int)>> callback;
|
||||||
|
const style::Checkbox *st = nullptr;
|
||||||
|
const style::Radio *radioSt = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SingleChoiceBox(
|
||||||
|
not_null<Ui::GenericBox*> box,
|
||||||
|
SingleChoiceBoxArgs &&args);
|
||||||
|
|
|
@ -124,11 +124,14 @@ void Calls::setupContent() {
|
||||||
call->setCurrentVideoDevice(deviceId);
|
call->setCurrentVideoDevice(deviceId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Ui::show(Box<SingleChoiceBox>(
|
Ui::show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
tr::lng_settings_call_camera(),
|
SingleChoiceBox(box, {
|
||||||
options,
|
.title = tr::lng_settings_call_camera(),
|
||||||
currentOption,
|
.options = options,
|
||||||
save));
|
.initialSelection = currentOption,
|
||||||
|
.callback = save,
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
const auto bubbleWrap = content->add(object_ptr<Ui::RpWidget>(content));
|
const auto bubbleWrap = content->add(object_ptr<Ui::RpWidget>(content));
|
||||||
const auto bubble = content->lifetime().make_state<::Calls::VideoBubble>(
|
const auto bubble = content->lifetime().make_state<::Calls::VideoBubble>(
|
||||||
|
@ -366,7 +369,7 @@ QString CurrentAudioInputName() {
|
||||||
: tr::lng_settings_call_device_default(tr::now);
|
: tr::lng_settings_call_device_default(tr::now);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<SingleChoiceBox> ChooseAudioOutputBox(
|
object_ptr<Ui::GenericBox> ChooseAudioOutputBox(
|
||||||
Fn<void(QString id, QString name)> chosen,
|
Fn<void(QString id, QString name)> chosen,
|
||||||
const style::Checkbox *st,
|
const style::Checkbox *st,
|
||||||
const style::Radio *radioSt) {
|
const style::Radio *radioSt) {
|
||||||
|
@ -390,16 +393,19 @@ object_ptr<SingleChoiceBox> ChooseAudioOutputBox(
|
||||||
Core::App().calls().setCurrentAudioDevice(false, deviceId);
|
Core::App().calls().setCurrentAudioDevice(false, deviceId);
|
||||||
chosen(deviceId, options[option]);
|
chosen(deviceId, options[option]);
|
||||||
};
|
};
|
||||||
return Box<SingleChoiceBox>(
|
return Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
tr::lng_settings_call_output_device(),
|
SingleChoiceBox(box, {
|
||||||
options,
|
.title = tr::lng_settings_call_output_device(),
|
||||||
currentOption,
|
.options = options,
|
||||||
save,
|
.initialSelection = currentOption,
|
||||||
st,
|
.callback = save,
|
||||||
radioSt);
|
.st = st,
|
||||||
|
.radioSt = radioSt,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
object_ptr<Ui::GenericBox> ChooseAudioInputBox(
|
||||||
Fn<void(QString id, QString name)> chosen,
|
Fn<void(QString id, QString name)> chosen,
|
||||||
const style::Checkbox *st,
|
const style::Checkbox *st,
|
||||||
const style::Radio *radioSt) {
|
const style::Radio *radioSt) {
|
||||||
|
@ -423,16 +429,19 @@ object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
||||||
Core::App().calls().setCurrentAudioDevice(true, deviceId);
|
Core::App().calls().setCurrentAudioDevice(true, deviceId);
|
||||||
chosen(deviceId, options[option]);
|
chosen(deviceId, options[option]);
|
||||||
};
|
};
|
||||||
return Box<SingleChoiceBox>(
|
return Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
tr::lng_settings_call_input_device(),
|
SingleChoiceBox(box, {
|
||||||
options,
|
.title = tr::lng_settings_call_input_device(),
|
||||||
currentOption,
|
.options = options,
|
||||||
save,
|
.initialSelection = currentOption,
|
||||||
st,
|
.callback = save,
|
||||||
radioSt);
|
.st = st,
|
||||||
|
.radioSt = radioSt,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
//
|
||||||
//object_ptr<SingleChoiceBox> ChooseAudioBackendBox(
|
//object_ptr<Ui::GenericBox> ChooseAudioBackendBox(
|
||||||
// const style::Checkbox *st,
|
// const style::Checkbox *st,
|
||||||
// const style::Radio *radioSt) {
|
// const style::Radio *radioSt) {
|
||||||
// const auto &settings = Core::App().settings();
|
// const auto &settings = Core::App().settings();
|
||||||
|
@ -451,13 +460,16 @@ object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
||||||
// Core::App().saveSettings();
|
// Core::App().saveSettings();
|
||||||
// App::restart();
|
// App::restart();
|
||||||
// };
|
// };
|
||||||
// return Box<SingleChoiceBox>(
|
// return Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
// rpl::single<QString>("Calls audio backend"),
|
// SingleChoiceBox(box, {
|
||||||
// options,
|
// .title = rpl::single<QString>("Calls audio backend"),
|
||||||
// currentOption,
|
// .options = options,
|
||||||
// save,
|
// .initialSelection = currentOption,
|
||||||
// st,
|
// .callback = save,
|
||||||
// radioSt);
|
// .st = st,
|
||||||
|
// .radioSt = radioSt,
|
||||||
|
// });
|
||||||
|
// });
|
||||||
//}
|
//}
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -22,14 +22,13 @@ class Call;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class LevelMeter;
|
class LevelMeter;
|
||||||
|
class GenericBox;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Webrtc {
|
namespace Webrtc {
|
||||||
class AudioInputTester;
|
class AudioInputTester;
|
||||||
} // namespace Webrtc
|
} // namespace Webrtc
|
||||||
|
|
||||||
class SingleChoiceBox;
|
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
class Calls : public Section {
|
class Calls : public Section {
|
||||||
|
@ -61,17 +60,17 @@ inline constexpr auto kMicTestAnimationDuration = crl::time(200);
|
||||||
|
|
||||||
[[nodiscard]] QString CurrentAudioOutputName();
|
[[nodiscard]] QString CurrentAudioOutputName();
|
||||||
[[nodiscard]] QString CurrentAudioInputName();
|
[[nodiscard]] QString CurrentAudioInputName();
|
||||||
[[nodiscard]] object_ptr<SingleChoiceBox> ChooseAudioOutputBox(
|
[[nodiscard]] object_ptr<Ui::GenericBox> ChooseAudioOutputBox(
|
||||||
Fn<void(QString id, QString name)> chosen,
|
Fn<void(QString id, QString name)> chosen,
|
||||||
const style::Checkbox *st = nullptr,
|
const style::Checkbox *st = nullptr,
|
||||||
const style::Radio *radioSt = nullptr);
|
const style::Radio *radioSt = nullptr);
|
||||||
[[nodiscard]] object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
[[nodiscard]] object_ptr<Ui::GenericBox> ChooseAudioInputBox(
|
||||||
Fn<void(QString id, QString name)> chosen,
|
Fn<void(QString id, QString name)> chosen,
|
||||||
const style::Checkbox *st = nullptr,
|
const style::Checkbox *st = nullptr,
|
||||||
const style::Radio *radioSt = nullptr);
|
const style::Radio *radioSt = nullptr);
|
||||||
[[nodiscard]] object_ptr<SingleChoiceBox> ChooseAudioBackendBox(
|
//[[nodiscard]] object_ptr<Ui::GenericBox> ChooseAudioBackendBox(
|
||||||
const style::Checkbox *st = nullptr,
|
// const style::Checkbox *st = nullptr,
|
||||||
const style::Radio *radioSt = nullptr);
|
// const style::Radio *radioSt = nullptr);
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue