From 3b379c67ac2da639a4fcfba77fb6ec3caf0b8d3a Mon Sep 17 00:00:00 2001
From: 23rd <23rd@vivaldi.net>
Date: Tue, 24 May 2022 07:20:22 +0300
Subject: [PATCH] Slightly improved style of some boxes for premium limits.

---
 Telegram/Resources/langs/lang.strings         |  4 +-
 Telegram/SourceFiles/boxes/boxes.style        |  3 +-
 .../SourceFiles/boxes/premium_limits_box.cpp  | 37 ++++++++++++-----
 .../ui/effects/premium_graphics.cpp           | 40 +++++++++++++------
 .../SourceFiles/ui/effects/premium_graphics.h |  5 ++-
 Telegram/lib_ui                               |  2 +-
 6 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings
index e0be2f086..5f4149fd0 100644
--- a/Telegram/Resources/langs/lang.strings
+++ b/Telegram/Resources/langs/lang.strings
@@ -177,7 +177,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 "lng_channels_leave_done" = "You've left the selected communities.";
 
 "lng_links_limit_title" = "Too Many Public Links";
-"lng_links_limit_subtitle" = "Your public communitites";
 "lng_links_limit1#one" = "You have reserved **{count}** public link.";
 "lng_links_limit1#other" = "You have reserved **{count}** public links.";
 "lng_links_limit2#one" = "Try revoking the link from an older group or channel, or upgrade to **Telegram Premium** to double the limit to **{count}** public link.";
@@ -224,7 +223,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 "lng_caption_limit_reached#other" = "You've reached the media caption limit. Please make the caption shorter by {count} characters.";
 
 "lng_file_size_limit_title" = "File Too Large";
-"lng_file_size_limit" = "{total} Gb";
+"lng_file_size_limit#one" = "{count} Gb";
+"lng_file_size_limit#other" = "{count} Gb";
 "lng_file_size_limit1" = "The document can't be sent, because it is larger than {size}.";
 "lng_file_size_limit2" = "You can double this limit to {size} per document by subscribing to **Telegram Premium**.";
 
diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style
index 3455548c4..6f5237dee 100644
--- a/Telegram/SourceFiles/boxes/boxes.style
+++ b/Telegram/SourceFiles/boxes/boxes.style
@@ -1080,7 +1080,8 @@ ringtonesBoxSkip: 7px;
 
 premiumBubblePadding: margins(14px, 0px, 14px, 0px);
 premiumBubbleHeight: 40px;
-premiumBubbleSkip: 5px;
+premiumBubbleSkip: 8px;
+premiumBubbleWidthLimit: 80px;
 premiumBubbleTextSkip: 3px;
 premiumBubbleSlideDuration: 1000;
 premiumBubbleTailSize: size(21px, 7px);
diff --git a/Telegram/SourceFiles/boxes/premium_limits_box.cpp b/Telegram/SourceFiles/boxes/premium_limits_box.cpp
index 5b91aaf2f..e2e0b1571 100644
--- a/Telegram/SourceFiles/boxes/premium_limits_box.cpp
+++ b/Telegram/SourceFiles/boxes/premium_limits_box.cpp
@@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "styles/style_boxes.h"
 #include "styles/style_layers.h"
 #include "styles/style_info.h"
+#include "styles/style_settings.h"
 
 namespace {
 
@@ -39,6 +40,7 @@ struct InfographicDescriptor {
 	float64 current = 0;
 	float64 premiumLimit = 0;
 	const style::icon *icon;
+	std::optional<tr::phrase<lngtag_count>> phrase;
 };
 
 [[nodiscard]] rpl::producer<> BoxShowFinishes(not_null<Ui::GenericBox*> box) {
@@ -54,6 +56,16 @@ struct InfographicDescriptor {
 	return showFinishes->events();
 }
 
+void AddSubsectionTitle(
+		not_null<Ui::VerticalLayout*> container,
+		rpl::producer<QString> text) {
+	const auto &subtitlePadding = st::settingsButton.padding;
+	Settings::AddSubsectionTitle(
+		container,
+		std::move(text),
+		{ 0, subtitlePadding.top(), 0, -subtitlePadding.bottom() });
+}
+
 class InactiveController final : public PeerListController {
 public:
 	explicit InactiveController(not_null<Main::Session*> session);
@@ -411,10 +423,10 @@ void SimpleLimitBox(
 		descriptor.defaultLimit,
 		descriptor.current,
 		descriptor.premiumLimit,
-		std::nullopt,
+		descriptor.phrase,
 		descriptor.icon);
 	Settings::AddSkip(top, st::premiumLineTextSkip);
-	Ui::Premium::AddLimitRow(top, descriptor.premiumLimit);
+	Ui::Premium::AddLimitRow(top, descriptor.premiumLimit, descriptor.phrase);
 	Settings::AddSkip(top, st::premiumInfographicPadding.bottom());
 
 	box->setTitle(std::move(title));
@@ -443,7 +455,7 @@ void SimpleLimitBox(
 	});
 
 	if (fixed) {
-		Settings::AddSkip(top);
+		Settings::AddSkip(top, st::settingsButton.padding.bottom());
 		Settings::AddDivider(top);
 	}
 }
@@ -522,6 +534,8 @@ void ChannelsLimitBox(
 		premium,
 		true);
 
+	AddSubsectionTitle(box->verticalLayout(), tr::lng_channels_leave_title());
+
 	const auto delegate = box->lifetime().make_state<InactiveDelegate>();
 	const auto controller = box->lifetime().make_state<InactiveController>(
 		session);
@@ -615,9 +629,7 @@ void PublicLinksLimitBox(
 		premium,
 		true);
 
-	Settings::AddSubsectionTitle(
-		box->verticalLayout(),
-		tr::lng_links_limit_subtitle());
+	AddSubsectionTitle(box->verticalLayout(), tr::lng_links_revoke_title());
 
 	const auto delegate = box->lifetime().make_state<InactiveDelegate>();
 	const auto controller = box->lifetime().make_state<PublicsController>(
@@ -835,10 +847,7 @@ void FileSizeLimitBox(
 	const auto defaultGb = (defaultLimit + 999) / 2000;
 	const auto premiumGb = (premiumLimit + 999) / 2000;
 	const auto gb = [](int count) {
-		return tr::lng_file_size_limit(
-			tr::now,
-			lt_total,
-			QString::number(count));
+		return tr::lng_file_size_limit(tr::now, lt_count, count);
 	};
 
 	auto text = rpl::combine(
@@ -860,7 +869,13 @@ void FileSizeLimitBox(
 		tr::lng_file_size_limit_title(),
 		std::move(text),
 		"upload_max_fileparts",
-		{ defaultGb, defaultGb, premiumGb, &st::premiumIconFiles },
+		{
+			defaultGb,
+			defaultGb,
+			premiumGb,
+			&st::premiumIconFiles,
+			tr::lng_file_size_limit
+		},
 		premium);
 }
 
diff --git a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp
index 4467f8f94..fbc4e2cb1 100644
--- a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp
+++ b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp
@@ -23,12 +23,20 @@ namespace {
 
 using TextFactory = Fn<QString(int)>;
 
+constexpr auto kDeflectionSmall = 20.;
 constexpr auto kDeflection = 30.;
 
 constexpr auto kStepBeforeDeflection = 0.75;
 constexpr auto kStepAfterDeflection = kStepBeforeDeflection
 	+ (1. - kStepBeforeDeflection) / 2.;
 
+[[nodiscard]] TextFactory ProcessTextFactory(
+		std::optional<tr::phrase<lngtag_count>> phrase) {
+	return phrase
+		? TextFactory([=](int n) { return (*phrase)(tr::now, lt_count, n); })
+		: TextFactory([=](int n) { return QString::number(n); });
+}
+
 [[nodiscard]] QLinearGradient ComputeGradient(
 		not_null<QWidget*> content,
 		int left,
@@ -103,6 +111,7 @@ Bubble::Bubble(
 , _tailSize(st::premiumBubbleTailSize)
 , _height(st::premiumBubbleHeight + _tailSize.height())
 , _textTop((_height - _tailSize.height() - _font->height) / 2) {
+	_numberAnimation.setDisabledMonospace(true);
 	_numberAnimation.setWidthChangedCallback([=] {
 		_widthChanges.fire({});
 	});
@@ -216,6 +225,8 @@ private:
 
 	QLinearGradient _cachedGradient;
 
+	float64 _deflection;
+
 };
 
 BubbleWidget::BubbleWidget(
@@ -228,8 +239,12 @@ BubbleWidget::BubbleWidget(
 : RpWidget(parent)
 , _currentCounter(current)
 , _maxCounter(maxCounter)
-, _bubble([=] { update(); }, std::move(textFactory), icon) {
+, _bubble([=] { update(); }, std::move(textFactory), icon)
+, _deflection(kDeflection) {
 	const auto resizeTo = [=](int w, int h) {
+		_deflection = (w > st::premiumBubbleWidthLimit)
+			? kDeflectionSmall
+			: kDeflection;
 		_spaceForDeflection = QSize(
 			st::premiumBubbleSkip,
 			st::premiumBubbleSkip);
@@ -338,8 +353,8 @@ void BubbleWidget::paintEvent(QPaintEvent *e) {
 		const auto offsetY = bubbleRect.y() + bubbleRect.height();
 		p.translate(offsetX, offsetY);
 		p.scale(scale, scale);
-		p.rotate(rotationProgress * kDeflection
-			- rotationProgressReverse * kDeflection);
+		p.rotate(rotationProgress * _deflection
+			- rotationProgressReverse * _deflection);
 		p.translate(-offsetX, -offsetY);
 	}
 
@@ -348,7 +363,7 @@ void BubbleWidget::paintEvent(QPaintEvent *e) {
 
 class Line final : public Ui::RpWidget {
 public:
-	Line(not_null<Ui::RpWidget*> parent, int max);
+	Line(not_null<Ui::RpWidget*> parent, int max, TextFactory textFactory);
 
 protected:
 	void paintEvent(QPaintEvent *event) override;
@@ -368,11 +383,11 @@ private:
 
 };
 
-Line::Line(not_null<Ui::RpWidget*> parent, int max)
+Line::Line(not_null<Ui::RpWidget*> parent, int max, TextFactory textFactory)
 : Ui::RpWidget(parent)
 , _leftText(st::defaultTextStyle, tr::lng_premium_free(tr::now))
 , _rightText(st::defaultTextStyle, tr::lng_premium(tr::now))
-, _rightLabel(st::defaultTextStyle, QString::number(max)) {
+, _rightLabel(st::defaultTextStyle, textFactory(max)) {
 	resize(width(), st::requestsAcceptButton.height);
 
 	sizeValue(
@@ -470,15 +485,11 @@ void AddBubbleRow(
 		int max,
 		std::optional<tr::phrase<lngtag_count>> phrase,
 		const style::icon *icon) {
-	auto textFactory = phrase
-		? TextFactory([=](int n) { return (*phrase)(tr::now, lt_count, n); })
-		: TextFactory([=](int n) { return QString::number(n); });
-
 	const auto container = parent->add(
 		object_ptr<Ui::FixedHeightWidget>(parent, 0));
 	const auto bubble = Ui::CreateChild<BubbleWidget>(
 		container,
-		std::move(textFactory),
+		ProcessTextFactory(phrase),
 		current,
 		max,
 		std::move(showFinishes),
@@ -491,9 +502,12 @@ void AddBubbleRow(
 	}, bubble->lifetime());
 }
 
-void AddLimitRow(not_null<Ui::VerticalLayout*> parent, int max) {
+void AddLimitRow(
+		not_null<Ui::VerticalLayout*> parent,
+		int max,
+		std::optional<tr::phrase<lngtag_count>> phrase) {
 	const auto line = parent->add(
-		object_ptr<Line>(parent, max),
+		object_ptr<Line>(parent, max, ProcessTextFactory(phrase)),
 		st::boxRowPadding);
 }
 
diff --git a/Telegram/SourceFiles/ui/effects/premium_graphics.h b/Telegram/SourceFiles/ui/effects/premium_graphics.h
index 3c22ff059..6f5a94298 100644
--- a/Telegram/SourceFiles/ui/effects/premium_graphics.h
+++ b/Telegram/SourceFiles/ui/effects/premium_graphics.h
@@ -31,7 +31,10 @@ void AddBubbleRow(
 	std::optional<tr::phrase<lngtag_count>> phrase,
 	const style::icon *icon);
 
-void AddLimitRow(not_null<Ui::VerticalLayout*> parent, int max);
+void AddLimitRow(
+	not_null<Ui::VerticalLayout*> parent,
+	int max,
+	std::optional<tr::phrase<lngtag_count>> phrase);
 
 [[nodiscard]] QGradientStops LimitGradientStops();
 [[nodiscard]] QGradientStops ButtonGradientStops();
diff --git a/Telegram/lib_ui b/Telegram/lib_ui
index 7133ccd2f..79af7c552 160000
--- a/Telegram/lib_ui
+++ b/Telegram/lib_ui
@@ -1 +1 @@
-Subproject commit 7133ccd2f9e5176334e597cd7727d69faf944868
+Subproject commit 79af7c5523ae59d4dd13cc2bde86bb8611bde11c