Added ability to provide style to box for choosing date and time.

This commit is contained in:
23rd 2022-03-06 12:07:43 +03:00
parent 239c617818
commit 5298cf0e52
2 changed files with 34 additions and 6 deletions

View File

@ -58,6 +58,15 @@ QString TimeString(QTime time) {
} // namespace
ChooseDateTimeStyleArgs::ChooseDateTimeStyleArgs()
: labelStyle(&st::boxLabel)
, dateFieldStyle(&st::scheduleDateField)
, timeFieldStyle(&st::scheduleTimeField)
, separatorStyle(&st::scheduleTimeSeparator)
, atStyle(&st::scheduleAtLabel)
, calendarStyle(&st::defaultCalendarColors) {
}
ChooseDateTimeBoxDescriptor ChooseDateTimeBox(
not_null<GenericBox*> box,
ChooseDateTimeBoxArgs &&args) {
@ -76,25 +85,25 @@ ChooseDateTimeBoxDescriptor ChooseDateTimeBox(
box->addRow(object_ptr<FlatLabel>(
box,
std::move(args.description),
st::boxLabel));
*args.style.labelStyle));
}
const auto parsed = base::unixtime::parse(args.time);
const auto state = box->lifetime().make_state<State>(State{
.date = parsed.date(),
.day = CreateChild<InputField>(
content,
st::scheduleDateField),
*args.style.dateFieldStyle),
.time = CreateChild<TimeInput>(
content,
TimeString(parsed.time()),
st::scheduleTimeField,
st::scheduleDateField,
st::scheduleTimeSeparator,
*args.style.timeFieldStyle,
*args.style.dateFieldStyle,
*args.style.separatorStyle,
st::scheduleTimeSeparatorPadding),
.at = CreateChild<FlatLabel>(
content,
tr::lng_schedule_at(),
st::scheduleAtLabel),
*args.style.atStyle),
});
state->date.value(
@ -155,6 +164,7 @@ ChooseDateTimeBoxDescriptor ChooseDateTimeBox(
const auto calendar =
content->lifetime().make_state<QPointer<CalendarBox>>();
const auto calendarStyle = args.style.calendarStyle;
QObject::connect(state->day, &InputField::focused, [=] {
if (*calendar) {
return;
@ -169,6 +179,7 @@ ChooseDateTimeBoxDescriptor ChooseDateTimeBox(
}),
.minDate = minDate(),
.maxDate = maxDate(),
.stColors = *calendarStyle,
}));
(*calendar)->boxClosing(
) | rpl::start_with_next(crl::guard(state->time, [=] {

View File

@ -9,6 +9,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/layers/generic_box.h"
namespace style {
struct FlatLabel;
struct InputField;
struct CalendarColors;
} // namespace style
namespace Ui {
class RoundButton;
@ -19,6 +25,16 @@ struct ChooseDateTimeBoxDescriptor {
rpl::producer<TimeId> values;
};
struct ChooseDateTimeStyleArgs {
ChooseDateTimeStyleArgs();
const style::FlatLabel *labelStyle;
const style::InputField *dateFieldStyle;
const style::InputField *timeFieldStyle;
const style::FlatLabel *separatorStyle;
const style::FlatLabel *atStyle;
const style::CalendarColors *calendarStyle;
};
struct ChooseDateTimeBoxArgs {
rpl::producer<QString> title;
rpl::producer<QString> submit;
@ -27,6 +43,7 @@ struct ChooseDateTimeBoxArgs {
TimeId time = 0;
Fn<TimeId()> max;
rpl::producer<QString> description;
ChooseDateTimeStyleArgs style;
};
ChooseDateTimeBoxDescriptor ChooseDateTimeBox(