Improve layout of shareable folder limit boxes.

This commit is contained in:
John Preston 2023-04-04 20:03:33 +04:00
parent 09de881036
commit 06cf2b562f
3 changed files with 120 additions and 63 deletions

View File

@ -46,6 +46,7 @@ struct InfographicDescriptor {
float64 premiumLimit = 0; float64 premiumLimit = 0;
const style::icon *icon; const style::icon *icon;
std::optional<tr::phrase<lngtag_count>> phrase; std::optional<tr::phrase<lngtag_count>> phrase;
bool complexRatio = false;
}; };
[[nodiscard]] rpl::producer<> BoxShowFinishes(not_null<Ui::GenericBox*> box) { [[nodiscard]] rpl::producer<> BoxShowFinishes(not_null<Ui::GenericBox*> box) {
@ -433,7 +434,11 @@ void SimpleLimitBox(
Ui::Premium::AddLimitRow( Ui::Premium::AddLimitRow(
top, top,
descriptor.premiumLimit, descriptor.premiumLimit,
descriptor.phrase); descriptor.phrase,
0,
(descriptor.complexRatio
? (float64(descriptor.current) / descriptor.premiumLimit)
: Ui::Premium::kLimitRowRatio));
Settings::AddSkip(top, st::premiumInfographicPadding.bottom()); Settings::AddSkip(top, st::premiumInfographicPadding.bottom());
} }
@ -757,7 +762,13 @@ void FilterLinksLimitBox(
tr::lng_filter_links_limit_title(), tr::lng_filter_links_limit_title(),
std::move(text), std::move(text),
"chatlist_invites", "chatlist_invites",
{ defaultLimit, current, premiumLimit, &st::premiumIconChats }); {
defaultLimit,
current,
premiumLimit,
&st::premiumIconChats,
std::nullopt,
true });
} }
@ -834,7 +845,13 @@ void ShareableFiltersLimitBox(
tr::lng_filter_shared_limit_title(), tr::lng_filter_shared_limit_title(),
std::move(text), std::move(text),
"chatlists_joined", "chatlists_joined",
{ defaultLimit, current, premiumLimit, &st::premiumIconFolders }); {
defaultLimit,
current,
premiumLimit,
&st::premiumIconFolders,
std::nullopt,
true });
} }
void FilterPinsLimitBox( void FilterPinsLimitBox(

View File

@ -559,8 +559,13 @@ public:
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
int max, int max,
TextFactory textFactory, TextFactory textFactory,
int min); int min,
Line(not_null<Ui::RpWidget*> parent, QString max, QString min); float64 ratio);
Line(
not_null<Ui::RpWidget*> parent,
QString max,
QString min,
float64 ratio);
void setColorOverride(QBrush brush); void setColorOverride(QBrush brush);
@ -589,14 +594,20 @@ Line::Line(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
int max, int max,
TextFactory textFactory, TextFactory textFactory,
int min) int min,
float64 ratio)
: Line( : Line(
parent, parent,
max ? textFactory(max) : QString(), max ? textFactory(max) : QString(),
min ? textFactory(min) : QString()) { min ? textFactory(min) : QString(),
ratio) {
} }
Line::Line(not_null<Ui::RpWidget*> parent, QString max, QString min) Line::Line(
not_null<Ui::RpWidget*> parent,
QString max,
QString min,
float64 ratio)
: Ui::RpWidget(parent) : Ui::RpWidget(parent)
, _leftText(st::semiboldTextStyle, tr::lng_premium_free(tr::now)) , _leftText(st::semiboldTextStyle, tr::lng_premium_free(tr::now))
, _rightText(st::semiboldTextStyle, tr::lng_premium(tr::now)) , _rightText(st::semiboldTextStyle, tr::lng_premium(tr::now))
@ -609,7 +620,7 @@ Line::Line(not_null<Ui::RpWidget*> parent, QString max, QString min)
if (s.isEmpty()) { if (s.isEmpty()) {
return; return;
} }
_leftWidth = (s.width() / 2); _leftWidth = int(base::SafeRound(s.width() * ratio));
_rightWidth = (s.width() - _leftWidth); _rightWidth = (s.width() - _leftWidth);
recache(s); recache(s);
update(); update();
@ -635,76 +646,95 @@ void Line::paintEvent(QPaintEvent *event) {
const auto textPadding = st::premiumLineTextSkip; const auto textPadding = st::premiumLineTextSkip;
const auto textTop = (height() - _leftText.minHeight()) / 2; const auto textTop = (height() - _leftText.minHeight()) / 2;
p.setPen(st::windowFg); const auto leftMinWidth = _leftLabel.maxWidth()
_leftLabel.drawRight( + _leftText.maxWidth()
p, + 3 * textPadding;
textPadding, if (_leftWidth >= leftMinWidth) {
textTop, p.setPen(st::windowFg);
_leftWidth - textPadding, _leftLabel.drawRight(
_leftWidth, p,
style::al_right); textPadding,
_leftText.drawLeft( textTop,
p, _leftWidth - textPadding,
textPadding, _leftWidth,
textTop, style::al_right);
_leftWidth - textPadding, _leftText.drawLeft(
_leftWidth); p,
textPadding,
p.setPen(st::activeButtonFg); textTop,
_rightLabel.drawRight( _leftWidth - textPadding,
p, _leftWidth);
textPadding, }
textTop, const auto rightMinWidth = 2 * _rightLabel.maxWidth()
_rightWidth - textPadding, + 3 * textPadding;
width(), if (_rightWidth >= rightMinWidth) {
style::al_right); p.setPen(st::activeButtonFg);
_rightText.drawLeftElided( _rightLabel.drawRight(
p, p,
_leftWidth + textPadding, textPadding,
textTop, textTop,
_rightWidth - _rightLabel.countWidth(_rightWidth) - textPadding * 2, _rightWidth - textPadding,
_rightWidth); width(),
style::al_right);
_rightText.drawLeftElided(
p,
_leftWidth + textPadding,
textTop,
(_rightWidth
- _rightLabel.countWidth(_rightWidth)
- textPadding * 2),
_rightWidth);
}
} }
void Line::recache(const QSize &s) { void Line::recache(const QSize &s) {
const auto r = QRect(0, 0, _leftWidth, s.height()); const auto r = [&](int width) {
auto pixmap = QPixmap(r.size() * style::DevicePixelRatio()); return QRect(0, 0, width, s.height());
pixmap.setDevicePixelRatio(style::DevicePixelRatio()); };
pixmap.fill(Qt::transparent); const auto pixmap = [&](int width) {
auto result = QPixmap(r(width).size() * style::DevicePixelRatio());
auto pathRound = QPainterPath(); result.setDevicePixelRatio(style::DevicePixelRatio());
pathRound.addRoundedRect(r, st::buttonRadius, st::buttonRadius); result.fill(Qt::transparent);
return result;
};
const auto pathRound = [&](int width) {
auto result = QPainterPath();
result.addRoundedRect(r(width), st::buttonRadius, st::buttonRadius);
return result;
};
{ {
auto leftPixmap = pixmap; auto leftPixmap = pixmap(_leftWidth);
auto p = QPainter(&leftPixmap); auto p = QPainter(&leftPixmap);
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
auto pathRect = QPainterPath(); auto pathRect = QPainterPath();
auto halfRect = r; auto halfRect = r(_leftWidth);
halfRect.setLeft(r.center().x()); halfRect.setLeft(halfRect.center().x());
pathRect.addRect(halfRect); pathRect.addRect(halfRect);
p.fillPath(pathRound + pathRect, st::windowBgOver); p.fillPath(pathRound(_leftWidth) + pathRect, st::windowBgOver);
_leftPixmap = std::move(leftPixmap); _leftPixmap = std::move(leftPixmap);
} }
{ {
auto rightPixmap = pixmap; auto rightPixmap = pixmap(_rightWidth);
auto p = QPainter(&rightPixmap); auto p = QPainter(&rightPixmap);
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
auto pathRect = QPainterPath(); auto pathRect = QPainterPath();
auto halfRect = r; auto halfRect = r(_rightWidth);
halfRect.setRight(r.center().x()); halfRect.setRight(halfRect.center().x());
pathRect.addRect(halfRect); pathRect.addRect(halfRect);
if (_overrideBrush) { if (_overrideBrush) {
p.fillPath(pathRound + pathRect, *_overrideBrush); p.fillPath(pathRound(_rightWidth) + pathRect, *_overrideBrush);
} else { } else {
auto gradient = ComputeGradient( auto gradient = ComputeGradient(
this, this,
(_leftPixmap.width() / style::DevicePixelRatio()) + r.x(), _leftPixmap.width() / style::DevicePixelRatio(),
r.width()); _rightWidth);
p.fillPath(pathRound + pathRect, QBrush(std::move(gradient))); p.fillPath(
pathRound(_rightWidth) + pathRect,
QBrush(std::move(gradient)));
} }
_rightPixmap = std::move(rightPixmap); _rightPixmap = std::move(rightPixmap);
@ -743,20 +773,25 @@ void AddBubbleRow(
void AddLimitRow( void AddLimitRow(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
QString max, QString max,
QString min) { QString min,
parent->add(object_ptr<Line>(parent, max, min), st::boxRowPadding); float64 ratio) {
parent->add(
object_ptr<Line>(parent, max, min, ratio),
st::boxRowPadding);
} }
void AddLimitRow( void AddLimitRow(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
int max, int max,
std::optional<tr::phrase<lngtag_count>> phrase, std::optional<tr::phrase<lngtag_count>> phrase,
int min) { int min,
float64 ratio) {
const auto factory = ProcessTextFactory(phrase); const auto factory = ProcessTextFactory(phrase);
AddLimitRow( AddLimitRow(
parent, parent,
max ? factory(max) : QString(), max ? factory(max) : QString(),
min ? factory(min) : QString()); min ? factory(min) : QString(),
ratio);
} }
void AddAccountsRow( void AddAccountsRow(
@ -971,7 +1006,8 @@ void ShowListBox(
return text(n); return text(n);
} }
}), }),
entry.leftNumber), entry.leftNumber,
kLimitRowRatio),
st::settingsPremiumPreviewLinePadding); st::settingsPremiumPreviewLinePadding);
lines.push_back(limitRow); lines.push_back(limitRow);
} }

View File

@ -34,6 +34,8 @@ class VerticalLayout;
namespace Premium { namespace Premium {
inline constexpr auto kLimitRowRatio = 0.5;
void AddBubbleRow( void AddBubbleRow(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
rpl::producer<> showFinishes, rpl::producer<> showFinishes,
@ -47,13 +49,15 @@ void AddBubbleRow(
void AddLimitRow( void AddLimitRow(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
QString max, QString max,
QString min = {}); QString min = {},
float64 ratio = kLimitRowRatio);
void AddLimitRow( void AddLimitRow(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
int max, int max,
std::optional<tr::phrase<lngtag_count>> phrase, std::optional<tr::phrase<lngtag_count>> phrase,
int min = 0); int min = 0,
float64 ratio = kLimitRowRatio);
struct AccountsRowArgs final { struct AccountsRowArgs final {
std::shared_ptr<Ui::RadiobuttonGroup> group; std::shared_ptr<Ui::RadiobuttonGroup> group;