tdesktop/Telegram/SourceFiles/boxes/single_choice_box.cpp

58 lines
1.6 KiB
C++
Raw Normal View History

2019-01-05 11:08:02 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/single_choice_box.h"
#include "lang/lang_keys.h"
#include "storage/localstorage.h"
#include "mainwindow.h"
#include "ui/widgets/checkbox.h"
2019-01-21 06:37:31 +00:00
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/padding_wrap.h"
2019-01-05 11:08:02 +00:00
#include "styles/style_boxes.h"
2019-09-18 11:19:05 +00:00
#include "styles/style_layers.h"
2019-01-05 11:08:02 +00:00
void SingleChoiceBox(
not_null<Ui::GenericBox*> box,
SingleChoiceBoxArgs &&args) {
box->setTitle(std::move(args.title));
2019-01-05 11:08:02 +00:00
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
2019-01-05 11:08:02 +00:00
const auto group = std::make_shared<Ui::RadiobuttonGroup>(
args.initialSelection);
2019-01-21 06:37:31 +00:00
const auto layout = box->verticalLayout();
layout->add(object_ptr<Ui::FixedHeightWidget>(
layout,
2019-01-21 06:37:31 +00:00
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
auto &&ints = ranges::views::ints(0, ranges::unreachable);
for (const auto &[i, text] : ranges::views::zip(ints, args.options)) {
layout->add(
2019-01-21 06:37:31 +00:00
object_ptr<Ui::Radiobutton>(
layout,
2019-01-21 06:37:31 +00:00
group,
i,
text,
args.st ? *args.st : st::defaultBoxCheckbox,
args.radioSt ? *args.radioSt : st::defaultRadio),
2019-01-21 06:37:31 +00:00
QMargins(
st::boxPadding.left() + st::boxOptionListPadding.left(),
0,
st::boxPadding.right(),
st::boxOptionListSkip));
2019-01-05 11:08:02 +00:00
}
2021-02-02 13:39:51 +00:00
const auto callback = args.callback;
2019-01-11 10:07:56 +00:00
group->setChangedCallback([=](int value) {
const auto weak = Ui::MakeWeak(box);
callback(value);
2019-01-11 10:07:56 +00:00
if (weak) {
box->closeBox();
2019-01-11 10:07:56 +00:00
}
2019-01-05 11:08:02 +00:00
});
}