From 588624e7a9cdd4674bc62322dc0295cd37b35f8e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 20 Mar 2024 04:16:50 +0300 Subject: [PATCH] Added initial overview subsection to channel earn info section. --- .../earn/channel_earn.style | 21 ++++ .../earn/info_earn_inner_widget.cpp | 108 ++++++++++++++++++ 2 files changed, 129 insertions(+) diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style b/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style index 38c562408..62c0600fb 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style +++ b/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style @@ -9,3 +9,24 @@ using "ui/basic.style"; using "boxes/boxes.style"; channelEarnLearnArrowMargins: margins(-2px, 5px, 0px, 0px); + +channelEarnOverviewMajorLabel: FlatLabel(defaultFlatLabel) { + maxHeight: 30px; + style: TextStyle(defaultTextStyle) { + font: font(15px semibold); + } +} +channelEarnOverviewMinorLabel: FlatLabel(channelEarnOverviewMajorLabel) { + maxHeight: 30px; + style: TextStyle(defaultTextStyle) { + font: font(12px semibold); + } +} +channelEarnOverviewMinorLabelSkip: 3px; +channelEarnOverviewSubMinorLabel: FlatLabel(channelEarnOverviewMinorLabel) { + textFg: windowSubTextFg; + style: TextStyle(defaultTextStyle) { + font: font(13px); + } +} +channelEarnOverviewSubMinorLabelSkip: 4px; diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp index f58ec6b6e..e15f35ae5 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/channel_statistics/earn/info_earn_inner_widget.h" +#include "base/random.h" +#include "chat_helpers/stickers_emoji_pack.h" #include "core/ui_integration.h" // Core::MarkedTextContext. #include "data/data_peer.h" #include "data/data_session.h" @@ -15,15 +17,52 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "statistics/widgets/chart_header_widget.h" +#include "ui/rect.h" #include "ui/text/text_utilities.h" #include "ui/vertical_list.h" #include "ui/widgets/labels.h" +#include "ui/wrap/slide_wrap.h" #include "styles/style_channel_earn.h" #include "styles/style_chat.h" #include "styles/style_layers.h" +#include "styles/style_statistics.h" namespace Info::ChannelEarn { namespace { + +void AddHeader( + not_null content, + tr::phrase<> text) { + const auto header = content->add( + object_ptr(content), + st::statisticsLayerMargins + st::boostsChartHeaderPadding); + header->resizeToWidth(header->width()); + header->setTitle(text(tr::now)); + header->setSubTitle({}); +} + +void AddEmojiToMajor( + not_null label, + not_null session, + float64 value) { + auto emoji = TextWithEntities{ + .text = (QString(QChar(0xD83D)) + QChar(0xDC8E)), + }; + if (const auto e = Ui::Emoji::Find(emoji.text)) { + const auto sticker = session->emojiStickersPack().stickerForEmoji(e); + if (sticker.document) { + emoji = Data::SingleCustomEmoji(sticker.document); + } + } + label->setMarkedText( + emoji.append(' ').append(QString::number(int64(value))), + Core::MarkedTextContext{ + .session = session, + .customEmojiRepaint = [label] { label->update(); }, + }); +} + } // namespace InnerWidget::InnerWidget( @@ -76,6 +115,75 @@ void InnerWidget::fill() { st::defaultBoxDividerLabelPadding, RectPart::Top | RectPart::Bottom)); } + Ui::AddSkip(container); + Ui::AddDivider(container); + Ui::AddSkip(container); + { + Ui::AddSkip(container); + AddHeader(container, tr::lng_channel_earn_overview_title); + Ui::AddSkip(container); + Ui::AddSkip(container); + + const auto multiplier = 3.8; // Debug. + const auto addOverviewEntry = [&]( + float64 value, + const tr::phrase<> &text) { + value = base::RandomIndex(1000000) / 1000.; // Debug. + const auto line = container->add( + Ui::CreateSkipWidget(container, 0), + st::boxRowPadding); + const auto majorLabel = Ui::CreateChild( + line, + st::channelEarnOverviewMajorLabel); + AddEmojiToMajor(majorLabel, session, value); + const auto minorLabel = Ui::CreateChild( + line, + QString::number(value - int64(value)).mid(1), + st::channelEarnOverviewMinorLabel); + const auto secondMinorLabel = Ui::CreateChild( + line, + QString(QChar(0x2248)) + + QChar('$') + + QString::number(value * multiplier), + st::channelEarnOverviewSubMinorLabel); + rpl::combine( + line->widthValue(), + majorLabel->sizeValue() + ) | rpl::start_with_next([=](int available, const QSize &size) { + line->resize(line->width(), size.height()); + minorLabel->moveToLeft( + size.width(), + st::channelEarnOverviewMinorLabelSkip); + secondMinorLabel->resizeToWidth(available + - size.width() + - minorLabel->width()); + secondMinorLabel->moveToLeft( + rect::right(minorLabel) + + st::channelEarnOverviewSubMinorLabelSkip, + st::channelEarnOverviewSubMinorLabelSkip); + }, minorLabel->lifetime()); + + Ui::AddSkip(container); + const auto sub = container->add( + object_ptr( + container, + text(), + st::channelEarnOverviewSubMinorLabel), + st::boxRowPadding); + sub->setTextColorOverride(st::windowSubTextFg->c); + }; + addOverviewEntry(0, tr::lng_channel_earn_available); + Ui::AddSkip(container); + Ui::AddSkip(container); + addOverviewEntry(0, tr::lng_channel_earn_reward); + Ui::AddSkip(container); + Ui::AddSkip(container); + addOverviewEntry(0, tr::lng_channel_earn_total); + Ui::AddSkip(container); + } + Ui::AddSkip(container); + Ui::AddDivider(container); + Ui::AddSkip(container); } void InnerWidget::saveState(not_null memento) {