Added ability to provide style to schedule box.

This commit is contained in:
23rd 2022-03-06 12:31:28 +03:00
parent 5298cf0e52
commit dd6501ef8f
2 changed files with 34 additions and 10 deletions

View File

@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h" #include "ui/widgets/popup_menu.h"
#include "ui/wrap/padding_wrap.h" #include "ui/wrap/padding_wrap.h"
#include "ui/boxes/choose_date_time.h"
#include "chat_helpers/send_context_menu.h" #include "chat_helpers/send_context_menu.h"
#include "styles/style_info.h" #include "styles/style_info.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -32,12 +31,13 @@ namespace {
void FillSendUntilOnlineMenu( void FillSendUntilOnlineMenu(
not_null<Ui::IconButton*> button, not_null<Ui::IconButton*> button,
Fn<void()> callback) { Fn<void()> callback,
const ScheduleBoxStyleArgs &style) {
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>(); const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
button->setClickedCallback([=] { button->setClickedCallback([=] {
*menu = base::make_unique_q<Ui::PopupMenu>( *menu = base::make_unique_q<Ui::PopupMenu>(
button, button,
st::popupMenuWithIcons); *style.popupMenuStyle);
(*menu)->addAction( (*menu)->addAction(
tr::lng_scheduled_send_until_online(tr::now), tr::lng_scheduled_send_until_online(tr::now),
std::move(callback), std::move(callback),
@ -49,6 +49,12 @@ void FillSendUntilOnlineMenu(
} // namespace } // namespace
ScheduleBoxStyleArgs::ScheduleBoxStyleArgs()
: topButtonStyle(&st::infoTopBarMenu)
, popupMenuStyle(&st::popupMenuWithIcons)
, chooseDateTimeArgs({}) {
}
TimeId DefaultScheduleTime() { TimeId DefaultScheduleTime() {
return base::unixtime::now() + 600; return base::unixtime::now() + 600;
} }
@ -64,7 +70,8 @@ void ScheduleBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
SendMenu::Type type, SendMenu::Type type,
Fn<void(Api::SendOptions)> done, Fn<void(Api::SendOptions)> done,
TimeId time) { TimeId time,
ScheduleBoxStyleArgs style) {
const auto save = [=](bool silent, TimeId scheduleDate) { const auto save = [=](bool silent, TimeId scheduleDate) {
if (!scheduleDate) { if (!scheduleDate) {
return; return;
@ -84,6 +91,7 @@ void ScheduleBox(
.submit = tr::lng_schedule_button(), .submit = tr::lng_schedule_button(),
.done = [=](TimeId result) { save(false, result); }, .done = [=](TimeId result) { save(false, result); },
.time = time, .time = time,
.style = style.chooseDateTimeArgs,
}); });
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(
@ -93,12 +101,13 @@ void ScheduleBox(
nullptr); nullptr);
if (type == SendMenu::Type::ScheduledToUser) { if (type == SendMenu::Type::ScheduledToUser) {
const auto sendUntilOnline = box->addTopButton(st::infoTopBarMenu); const auto sendUntilOnline = box->addTopButton(*style.topButtonStyle);
const auto timestamp const auto timestamp
= Data::ScheduledMessages::kScheduledUntilOnlineTimestamp; = Data::ScheduledMessages::kScheduledUntilOnlineTimestamp;
FillSendUntilOnlineMenu( FillSendUntilOnlineMenu(
sendUntilOnline.data(), sendUntilOnline.data(),
[=] { save(false, timestamp); }); [=] { save(false, timestamp); },
style);
} }
} }

View File

@ -7,7 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "ui/layers/generic_box.h" #include "ui/boxes/choose_date_time.h"
namespace style {
struct IconButton;
struct PopupMenu;
} // namespace style
namespace Api { namespace Api {
struct SendOptions; struct SendOptions;
@ -22,23 +27,33 @@ namespace HistoryView {
[[nodiscard]] TimeId DefaultScheduleTime(); [[nodiscard]] TimeId DefaultScheduleTime();
[[nodiscard]] bool CanScheduleUntilOnline(not_null<PeerData*> peer); [[nodiscard]] bool CanScheduleUntilOnline(not_null<PeerData*> peer);
struct ScheduleBoxStyleArgs {
ScheduleBoxStyleArgs();
const style::IconButton *topButtonStyle;
const style::PopupMenu *popupMenuStyle;
Ui::ChooseDateTimeStyleArgs chooseDateTimeArgs;
};
void ScheduleBox( void ScheduleBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
SendMenu::Type type, SendMenu::Type type,
Fn<void(Api::SendOptions)> done, Fn<void(Api::SendOptions)> done,
TimeId time); TimeId time,
ScheduleBoxStyleArgs style);
template <typename Guard, typename Submit> template <typename Guard, typename Submit>
[[nodiscard]] object_ptr<Ui::GenericBox> PrepareScheduleBox( [[nodiscard]] object_ptr<Ui::GenericBox> PrepareScheduleBox(
Guard &&guard, Guard &&guard,
SendMenu::Type type, SendMenu::Type type,
Submit &&submit, Submit &&submit,
TimeId scheduleTime = DefaultScheduleTime()) { TimeId scheduleTime = DefaultScheduleTime(),
ScheduleBoxStyleArgs style = ScheduleBoxStyleArgs()) {
return Box( return Box(
ScheduleBox, ScheduleBox,
type, type,
crl::guard(std::forward<Guard>(guard), std::forward<Submit>(submit)), crl::guard(std::forward<Guard>(guard), std::forward<Submit>(submit)),
scheduleTime); scheduleTime,
std::move(style));
} }
} // namespace HistoryView } // namespace HistoryView