From b6c86fd298db744c0465ce32885b934a46eae7b4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 2 Apr 2021 15:46:48 +0400 Subject: [PATCH] Add nice tips buttons. --- .../SourceFiles/payments/ui/payments.style | 17 ++ .../payments/ui/payments_form_summary.cpp | 185 ++++++++++++++++-- .../payments/ui/payments_form_summary.h | 18 +- .../payments/ui/payments_panel.cpp | 13 +- .../SourceFiles/payments/ui/payments_panel.h | 1 + .../SourceFiles/ui/text/format_values.cpp | 8 +- Telegram/SourceFiles/ui/text/format_values.h | 3 +- 7 files changed, 225 insertions(+), 20 deletions(-) diff --git a/Telegram/SourceFiles/payments/ui/payments.style b/Telegram/SourceFiles/payments/ui/payments.style index 7ec1a71497..fa068a568f 100644 --- a/Telegram/SourceFiles/payments/ui/payments.style +++ b/Telegram/SourceFiles/payments/ui/payments.style @@ -49,6 +49,23 @@ paymentsPricesTopSkip: 12px; paymentsPricesBottomSkip: 13px; paymentsPricePadding: margins(28px, 6px, 28px, 5px); +paymentsTipSkip: 8px; +paymentsTipButton: RoundButton(defaultLightButton) { + textFg: paymentsTipActive; + textFgOver: paymentsTipActive; + textBgOver: transparent; + + width: -16px; + height: 28px; + textTop: 5px; +} +paymentsTipChosen: RoundButton(paymentsTipButton) { + textFg: windowFgActive; + textFgOver: windowFgActive; + textBgOver: transparent; +} +paymentsTipButtonsPadding: margins(26px, 6px, 26px, 6px); + paymentsSectionsTopSkip: 11px; paymentsSectionButton: SettingsButton(infoProfileButton) { padding: margins(68px, 11px, 14px, 9px); diff --git a/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp b/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp index 10cada6deb..9f60bae260 100644 --- a/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp @@ -27,6 +27,36 @@ QString formatPhone(QString phone); // #TODO } // namespace App namespace Payments::Ui { +namespace { + +constexpr auto kLightOpacity = 0.1; +constexpr auto kLightRippleOpacity = 0.11; +constexpr auto kChosenOpacity = 0.8; +constexpr auto kChosenRippleOpacity = 0.5; + +[[nodiscard]] Fn TransparentColor( + const style::color &c, + float64 opacity) { + return [&c, opacity] { + return QColor( + c->c.red(), + c->c.green(), + c->c.blue(), + c->c.alpha() * opacity); + }; +} + +[[nodiscard]] style::RoundButton TipButtonStyle( + const style::RoundButton &original, + const style::color &light, + const style::color &ripple) { + auto result = original; + result.textBg = light; + result.ripple.color = ripple; + return result; +} + +} // namespace using namespace ::Ui; @@ -38,7 +68,8 @@ FormSummary::FormSummary( const RequestedInformation ¤t, const PaymentMethodDetails &method, const ShippingOptions &options, - not_null delegate) + not_null delegate, + int scrollTop) : _delegate(delegate) , _invoice(invoice) , _method(method) @@ -56,21 +87,45 @@ FormSummary::FormSummary( rpl::single(formatAmount(computeTotalAmount()))), st::paymentsPanelSubmit)) , _cancel( - this, - (_invoice.receipt.paid - ? tr::lng_about_done() - : tr::lng_cancel()), - st::paymentsPanelButton) { + this, + (_invoice.receipt.paid + ? tr::lng_about_done() + : tr::lng_cancel()), + st::paymentsPanelButton) +, _tipLightBg(TransparentColor(st::paymentsTipActive, kLightOpacity)) +, _tipLightRipple( + TransparentColor(st::paymentsTipActive, kLightRippleOpacity)) +, _tipChosenBg(TransparentColor(st::paymentsTipActive, kChosenOpacity)) +, _tipChosenRipple( + TransparentColor(st::paymentsTipActive, kChosenRippleOpacity)) +, _tipButton(TipButtonStyle( + st::paymentsTipButton, + _tipLightBg.color(), + _tipLightRipple.color())) +, _tipChosen(TipButtonStyle( + st::paymentsTipChosen, + _tipChosenBg.color(), + _tipChosenRipple.color())) +, _initialScrollTop(scrollTop) { setupControls(); } +rpl::producer FormSummary::scrollTopValue() const { + return _scroll->scrollTopValue(); +} + void FormSummary::updateThumbnail(const QImage &thumbnail) { _invoice.cover.thumbnail = thumbnail; _thumbnails.fire_copy(thumbnail); } -QString FormSummary::formatAmount(int64 amount) const { - return FillAmountAndCurrency(amount, _invoice.currency); +QString FormSummary::formatAmount( + int64 amount, + bool forceStripDotZero) const { + return FillAmountAndCurrency( + amount, + _invoice.currency, + forceStripDotZero); } int64 FormSummary::computeTotalAmount() const { @@ -279,9 +334,7 @@ void FormSummary::setupPrices(not_null layout) { add(tr::lng_payments_tips_label(tr::now), tips); } } else if (_invoice.tipsMax > 0) { - const auto text = _invoice.tipsSelected - ? formatAmount(_invoice.tipsSelected) - : tr::lng_payments_tips_add(tr::now); + const auto text = formatAmount(_invoice.tipsSelected); const auto label = addRow( tr::lng_payments_tips_label(tr::now), Ui::Text::Link(text, "internal:edit_tips")); @@ -289,12 +342,116 @@ void FormSummary::setupPrices(not_null layout) { _delegate->panelChooseTips(); return false; }); + setupSuggestedTips(layout); } add(tr::lng_payments_total_label(tr::now), total, true); Settings::AddSkip(layout, st::paymentsPricesBottomSkip); } +void FormSummary::setupSuggestedTips(not_null layout) { + if (_invoice.suggestedTips.empty()) { + return; + } + struct Button { + RoundButton *widget = nullptr; + int minWidth = 0; + }; + struct State { + std::vector