Support arbitrary content in toasts.

This commit is contained in:
John Preston 2024-08-09 12:25:58 +02:00
parent ac92e1c99e
commit e89f2b55e8
23 changed files with 37 additions and 60 deletions

View file

@ -763,9 +763,6 @@ void EditMessagesPrivacyBox(
lt_link, lt_link,
link, link,
Ui::Text::WithEntities), Ui::Text::WithEntities),
.st = &st::defaultMultilineToast,
.duration = Ui::Toast::kDefaultDuration * 2,
.multiline = true,
.filter = crl::guard(&controller->session(), [=]( .filter = crl::guard(&controller->session(), [=](
const ClickHandlerPtr &, const ClickHandlerPtr &,
Qt::MouseButton button) { Qt::MouseButton button) {

View file

@ -932,8 +932,8 @@ void ShowAlreadyPremiumToast(
Ui::Text::Link( Ui::Text::Link(
Ui::Text::Bold(tr::lng_gift_link_already_link(tr::now))), Ui::Text::Bold(tr::lng_gift_link_already_link(tr::now))),
Ui::Text::WithEntities), Ui::Text::WithEntities),
.duration = 6 * crl::time(1000),
.filter = crl::guard(navigation, shareLink), .filter = crl::guard(navigation, shareLink),
.duration = 6 * crl::time(1000),
}); });
} }

View file

@ -554,7 +554,6 @@ void Panel::reinitWithCall(Call *call) {
Ui::Toast::Show(widget(), Ui::Toast::Config{ Ui::Toast::Show(widget(), Ui::Toast::Config{
.text = { text }, .text = { text },
.st = &st::callErrorToast, .st = &st::callErrorToast,
.multiline = true,
}); });
}, _callLifetime); }, _callLifetime);

View file

@ -1126,10 +1126,8 @@ base::unique_qptr<Ui::RpWidget> CreateDisabledFieldView(
: list.back(); : list.back();
*toast = Ui::Toast::Show(parent, { *toast = Ui::Toast::Show(parent, {
.text = { tr::lng_send_text_no_about(tr::now, lt_types, types) }, .text = { tr::lng_send_text_no_about(tr::now, lt_types, types) },
.st = &st::defaultMultilineToast, .attach = RectPart::Bottom,
.duration = kTypesDuration, .duration = kTypesDuration,
.multiline = true,
.slideSide = RectPart::Bottom,
}); });
}); });
return result; return result;

View file

@ -2266,7 +2266,6 @@ ClickHandlerPtr MediaDice::MakeHandler(
.text = { tr::lng_about_random(tr::now, lt_emoji, emoji) }, .text = { tr::lng_about_random(tr::now, lt_emoji, emoji) },
.st = &st::historyDiceToast, .st = &st::historyDiceToast,
.duration = Ui::Toast::kDefaultDuration * 2, .duration = Ui::Toast::kDefaultDuration * 2,
.multiline = true,
}; };
if (CanSend(history->peer, ChatRestriction::SendOther)) { if (CanSend(history->peer, ChatRestriction::SendOther)) {
auto link = Ui::Text::Link(tr::lng_about_random_send(tr::now)); auto link = Ui::Text::Link(tr::lng_about_random_send(tr::now));
@ -2295,7 +2294,7 @@ ClickHandlerPtr MediaDice::MakeHandler(
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
ShownToast = strong->showToast(std::move(config)); ShownToast = strong->showToast(std::move(config));
} else { } else {
ShownToast = Ui::Toast::Show(config); ShownToast = Ui::Toast::Show(std::move(config));
} }
}); });
} }

View file

@ -96,8 +96,8 @@ void MaybeShowPremiumToast(
}; };
show->showToast({ show->showToast({
.text = std::move(text), .text = std::move(text),
.duration = kPremiumToastDuration,
.filter = filter, .filter = filter,
.duration = kPremiumToastDuration,
}); });
} }
@ -398,7 +398,6 @@ void Stickers::applyArchivedResult(
Ui::Toast::Show(Ui::Toast::Config{ Ui::Toast::Show(Ui::Toast::Config{
.text = { tr::lng_stickers_packs_archived(tr::now) }, .text = { tr::lng_stickers_packs_archived(tr::now) },
.st = &st::stickersToast, .st = &st::stickersToast,
.multiline = true,
}); });
//Ui::show( //Ui::show(
// Box<StickersBox>(archived, &session()), // Box<StickersBox>(archived, &session()),

View file

@ -840,8 +840,8 @@ void ShowTrialTranscribesToast(int left, TimeId until) {
Ui::Text::WithEntities); Ui::Text::WithEntities);
window->uiShow()->showToast(Ui::Toast::Config{ window->uiShow()->showToast(Ui::Toast::Config{
.text = text, .text = text,
.duration = kToastDuration,
.filter = filter, .filter = filter,
.duration = kToastDuration,
}); });
} }

View file

@ -40,12 +40,10 @@ void InfoTooltip::show(
hide(anim::type::normal); hide(anim::type::normal);
_topToast = Ui::Toast::Show(parent, Ui::Toast::Config{ _topToast = Ui::Toast::Show(parent, Ui::Toast::Config{
.text = text, .text = text,
.st = &st::historyInfoToast,
.duration = CountToastDuration(text),
.multiline = true,
.dark = true,
.slideSide = RectPart::Top,
.textContext = context, .textContext = context,
.st = &st::historyInfoToast,
.attach = RectPart::Top,
.duration = CountToastDuration(text),
}); });
if (const auto strong = _topToast.get()) { if (const auto strong = _topToast.get()) {
if (hiddenCallback) { if (hiddenCallback) {

View file

@ -115,16 +115,14 @@ void PaidReactionToast::showFor(
_weak = Ui::Toast::Show(_parent, Ui::Toast::Config{ _weak = Ui::Toast::Show(_parent, Ui::Toast::Config{
.text = text, .text = text,
.st = &_st, .st = &_st,
.duration = -1, .attach = RectPart::Top,
.multiline = true, .acceptinput = true,
.dark = true, .infinite = true,
.slideSide = RectPart::Top,
}); });
const auto strong = _weak.get(); const auto strong = _weak.get();
if (!strong) { if (!strong) {
return; return;
} }
strong->setInputUsed(true);
const auto widget = strong->widget(); const auto widget = strong->widget();
const auto hideToast = [weak = _weak] { const auto hideToast = [weak = _weak] {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
@ -188,9 +186,10 @@ void PaidReactionToast::setupLottiePreview(
const auto bytes = document->createMediaView()->bytes(); const auto bytes = document->createMediaView()->bytes();
const auto filepath = document->filepath(); const auto filepath = document->filepath();
const auto ratio = style::DevicePixelRatio();
const auto player = widget->lifetime().make_state<Lottie::SinglePlayer>( const auto player = widget->lifetime().make_state<Lottie::SinglePlayer>(
Lottie::ReadContent(bytes, filepath), Lottie::ReadContent(bytes, filepath),
Lottie::FrameRequest{ QSize(size, size) }, Lottie::FrameRequest{ QSize(size, size) * ratio },
Lottie::Quality::Default); Lottie::Quality::Default);
widget->paintRequest( widget->paintRequest(
@ -200,7 +199,7 @@ void PaidReactionToast::setupLottiePreview(
} }
const auto image = player->frame(); const auto image = player->frame();
QPainter(widget).drawImage( QPainter(widget).drawImage(
QRect(QPoint(), image.size() / image.devicePixelRatio()), QRect(QPoint(), image.size() / ratio),
image); image);
if (player->frameIndex() + 1 != player->framesCount()) { if (player->frameIndex() + 1 != player->framesCount()) {
player->markFrameShown(); player->markFrameShown();

View file

@ -165,16 +165,14 @@ void StickerToast::showWithTitle(const QString &title) {
_weak = Ui::Toast::Show(_parent, Ui::Toast::Config{ _weak = Ui::Toast::Show(_parent, Ui::Toast::Config{
.text = text, .text = text,
.st = &_st, .st = &_st,
.attach = RectPart::Bottom,
.acceptinput = true,
.duration = kPremiumToastDuration, .duration = kPremiumToastDuration,
.multiline = true,
.dark = true,
.slideSide = RectPart::Bottom,
}); });
const auto strong = _weak.get(); const auto strong = _weak.get();
if (!strong) { if (!strong) {
return; return;
} }
strong->setInputUsed(true);
const auto widget = strong->widget(); const auto widget = strong->widget();
const auto hideToast = [weak = _weak] { const auto hideToast = [weak = _weak] {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
@ -325,9 +323,10 @@ void StickerToast::setupLottiePreview(not_null<Ui::RpWidget*> widget, int size)
const auto bytes = _for->createMediaView()->bytes(); const auto bytes = _for->createMediaView()->bytes();
const auto filepath = _for->filepath(); const auto filepath = _for->filepath();
const auto ratio = style::DevicePixelRatio();
const auto player = widget->lifetime().make_state<Lottie::SinglePlayer>( const auto player = widget->lifetime().make_state<Lottie::SinglePlayer>(
Lottie::ReadContent(bytes, filepath), Lottie::ReadContent(bytes, filepath),
Lottie::FrameRequest{ QSize(size, size) }, Lottie::FrameRequest{ QSize(size, size) * ratio },
Lottie::Quality::Default); Lottie::Quality::Default);
widget->paintRequest( widget->paintRequest(
@ -337,7 +336,7 @@ void StickerToast::setupLottiePreview(not_null<Ui::RpWidget*> widget, int size)
} }
const auto image = player->frame(); const auto image = player->frame();
QPainter(widget).drawImage( QPainter(widget).drawImage(
QRect(QPoint(), image.size() / image.devicePixelRatio()), QRect(QPoint(), image.size() / ratio),
image); image);
player->markFrameShown(); player->markFrameShown();
}, widget->lifetime()); }, widget->lifetime());

View file

@ -524,16 +524,14 @@ void TranslateBar::showToast(
const auto weak = Ui::Toast::Show(_wrap.window(), Ui::Toast::Config{ const auto weak = Ui::Toast::Show(_wrap.window(), Ui::Toast::Config{
.text = std::move(text), .text = std::move(text),
.st = st.get(), .st = st.get(),
.attach = RectPart::Bottom,
.acceptinput = true,
.duration = kToastDuration, .duration = kToastDuration,
.multiline = true,
.dark = true,
.slideSide = RectPart::Bottom,
}); });
const auto strong = weak.get(); const auto strong = weak.get();
if (!strong) { if (!strong) {
return; return;
} }
strong->setInputUsed(true);
const auto widget = strong->widget(); const auto widget = strong->widget();
widget->lifetime().add([st] {}); widget->lifetime().add([st] {});
const auto hideToast = [weak] { const auto hideToast = [weak] {

View file

@ -146,10 +146,8 @@ void ShowSetToast(
const auto weak = controller->showToast({ const auto weak = controller->showToast({
.text = text, .text = text,
.st = st.get(), .st = st.get(),
.attach = RectPart::Bottom,
.duration = kToastDuration, .duration = kToastDuration,
.multiline = true,
.dark = true,
.slideSide = RectPart::Bottom,
}); });
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
const auto widget = strong->widget(); const auto widget = strong->widget();

View file

@ -1076,9 +1076,9 @@ void CreateGiveawayBox(
tr::lng_giveaway_created_link( tr::lng_giveaway_created_link(
tr::now)), tr::now)),
Ui::Text::WithEntities)), Ui::Text::WithEntities)),
.duration = kDoneTooltipDuration,
.adaptive = true,
.filter = filter, .filter = filter,
.adaptive = true,
.duration = kDoneTooltipDuration,
}); });
} else if (weak) { } else if (weak) {
state->confirmButtonBusy = false; state->confirmButtonBusy = false;

View file

@ -1947,9 +1947,9 @@ void MainWidget::showNonPremiumLimitToast(bool download) {
? tr::lng_limit_download_title ? tr::lng_limit_download_title
: tr::lng_limit_upload_title)(tr::now), : tr::lng_limit_upload_title)(tr::now),
.text = std::move(text), .text = std::move(text),
.duration = 5 * crl::time(1000),
.slideSide = RectPart::Top,
.filter = std::move(filter), .filter = std::move(filter),
.attach = RectPart::Top,
.duration = 5 * crl::time(1000),
}); });
} }

View file

@ -55,8 +55,8 @@ struct Feature {
TextWithEntities{ TimeLeftText(left) }, TextWithEntities{ TimeLeftText(left) },
Ui::Text::RichLangValue), Ui::Text::RichLangValue),
.st = &st::storiesStealthToast, .st = &st::storiesStealthToast,
.duration = kAlreadyToastDuration,
.adaptive = true, .adaptive = true,
.duration = kAlreadyToastDuration,
}; };
} }
@ -67,8 +67,8 @@ struct Feature {
tr::now, tr::now,
Ui::Text::RichLangValue), Ui::Text::RichLangValue),
.st = &st::storiesStealthToast, .st = &st::storiesStealthToast,
.duration = kAlreadyToastDuration,
.adaptive = true, .adaptive = true,
.duration = kAlreadyToastDuration,
}; };
} }
@ -78,8 +78,8 @@ struct Feature {
tr::now, tr::now,
Ui::Text::RichLangValue), Ui::Text::RichLangValue),
.st = &st::storiesStealthToast, .st = &st::storiesStealthToast,
.duration = kAlreadyToastDuration,
.adaptive = true, .adaptive = true,
.duration = kAlreadyToastDuration,
}; };
} }

View file

@ -1271,9 +1271,9 @@ void OverlayWidget::showPremiumDownloadPromo() {
Ui::Text::Bold( Ui::Text::Bold(
tr::lng_send_as_premium_required_link(tr::now))), tr::lng_send_as_premium_required_link(tr::now))),
Ui::Text::WithEntities), Ui::Text::WithEntities),
.duration = kStorySavePromoDuration,
.adaptive = true,
.filter = filter, .filter = filter,
.adaptive = true,
.duration = kStorySavePromoDuration,
}); });
} }

View file

@ -167,7 +167,6 @@ void AntiSpamValidator::addAction(
channel = _channel] { channel = _channel] {
window->showToast({ window->showToast({
.text = text, .text = text,
.duration = ApiWrap::kJoinErrorDuration,
.filter = [=]( .filter = [=](
const ClickHandlerPtr&, const ClickHandlerPtr&,
Qt::MouseButton) { Qt::MouseButton) {
@ -177,6 +176,7 @@ void AntiSpamValidator::addAction(
ParticipantsRole::Admins); ParticipantsRole::Admins);
return true; return true;
}, },
.duration = ApiWrap::kJoinErrorDuration,
}); });
}; };
menu->addAction( menu->addAction(

View file

@ -106,8 +106,8 @@ void AddAction(
tr::lng_mediaview_downloads(tr::now), tr::lng_mediaview_downloads(tr::now),
"internal:show_saved_message"), "internal:show_saved_message"),
Ui::Text::WithEntities), Ui::Text::WithEntities),
.st = &st::defaultToast,
.filter = filter, .filter = filter,
.st = &st::defaultToast,
}); });
}; };

View file

@ -1395,10 +1395,6 @@ void ShowPremiumPromoToast(
const auto toast = std::make_shared<WeakToast>(); const auto toast = std::make_shared<WeakToast>();
(*toast) = show->showToast({ (*toast) = show->showToast({
.text = std::move(textWithLink), .text = std::move(textWithLink),
.st = &st::defaultMultilineToast,
.duration = Ui::Toast::kDefaultDuration * 2,
.adaptive = true,
.multiline = true,
.filter = crl::guard(&show->session(), [=]( .filter = crl::guard(&show->session(), [=](
const ClickHandlerPtr &, const ClickHandlerPtr &,
Qt::MouseButton button) { Qt::MouseButton button) {
@ -1416,6 +1412,8 @@ void ShowPremiumPromoToast(
} }
return false; return false;
}), }),
.adaptive = true,
.duration = Ui::Toast::kDefaultDuration * 2,
}); });
} }

View file

@ -1429,9 +1429,6 @@ Fn<void()> VoicesPrivacyController::premiumClickedCallback(
lt_link, lt_link,
link, link,
Ui::Text::WithEntities), Ui::Text::WithEntities),
.st = &st::defaultMultilineToast,
.duration = Ui::Toast::kDefaultDuration * 2,
.multiline = true,
.filter = crl::guard(&controller->session(), [=]( .filter = crl::guard(&controller->session(), [=](
const ClickHandlerPtr &, const ClickHandlerPtr &,
Qt::MouseButton button) { Qt::MouseButton button) {
@ -1447,6 +1444,7 @@ Fn<void()> VoicesPrivacyController::premiumClickedCallback(
} }
return false; return false;
}), }),
.duration = Ui::Toast::kDefaultDuration * 2,
}); });
}; };

View file

@ -307,9 +307,7 @@ void AddPremiumPrivacyButton(
lt_link, lt_link,
link, link,
Ui::Text::WithEntities), Ui::Text::WithEntities),
.st = &st::defaultMultilineToast,
.duration = Ui::Toast::kDefaultDuration * 2, .duration = Ui::Toast::kDefaultDuration * 2,
.multiline = true,
.filter = crl::guard(&controller->session(), [=]( .filter = crl::guard(&controller->session(), [=](
const ClickHandlerPtr &, const ClickHandlerPtr &,
Qt::MouseButton button) { Qt::MouseButton button) {

View file

@ -2605,7 +2605,6 @@ void ToggleHistoryArchived(
.duration = (archived .duration = (archived
? kArchivedToastDuration ? kArchivedToastDuration
: Ui::Toast::kDefaultDuration), : Ui::Toast::kDefaultDuration),
.multiline = true,
}); });
}; };
history->session().api().toggleHistoryArchived( history->session().api().toggleHistoryArchived(

@ -1 +1 @@
Subproject commit 40df9722c97385277f128c21a7fcfc13da52b7c7 Subproject commit c48bbd9b910480bc4a179df7b96d84b7dfe44671