Improved style of box for credits history entries for refunded entry.

This commit is contained in:
23rd 2024-05-29 02:37:56 +03:00 committed by John Preston
parent cd7507fb23
commit 58c060c59d

View file

@ -437,23 +437,38 @@ void ReceiptCreditsBox(
auto &lifetime = content->lifetime(); auto &lifetime = content->lifetime();
const auto text = lifetime.make_state<Ui::Text::String>( const auto text = lifetime.make_state<Ui::Text::String>(
st::semiboldTextStyle, st::semiboldTextStyle,
(!e.bareId ? QChar('+') : kMinus) ((!e.bareId || e.refunded) ? QChar('+') : kMinus)
+ Lang::FormatCountDecimal(std::abs(int64(e.credits)))); + Lang::FormatCountDecimal(std::abs(int64(e.credits))));
const auto refundedText = tr::lng_channel_earn_history_return(
tr::now);
const auto refunded = e.refunded
? lifetime.make_state<Ui::Text::String>(
st::defaultTextStyle,
refundedText)
: (Ui::Text::String*)(nullptr);
const auto amount = content->add( const auto amount = content->add(
object_ptr<Ui::FixedHeightWidget>( object_ptr<Ui::FixedHeightWidget>(
content, content,
star.height() / style::DevicePixelRatio())); star.height() / style::DevicePixelRatio()));
const auto font = text->style()->font; const auto font = text->style()->font;
const auto refundedFont = st::defaultTextStyle.font;
const auto starWidth = star.width()
/ style::DevicePixelRatio();
const auto refundedSkip = refundedFont->spacew * 2;
const auto refundedWidth = refunded
? refundedFont->width(refundedText)
+ refundedSkip
+ refundedFont->height
: 0;
const auto fullWidth = text->maxWidth()
+ font->spacew * 1
+ starWidth
+ refundedWidth;
amount->paintRequest( amount->paintRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
auto p = Painter(amount); auto p = Painter(amount);
const auto starWidth = star.width() p.setPen((!e.bareId || e.refunded)
/ style::DevicePixelRatio();
const auto fullWidth = text->maxWidth()
+ font->spacew * 2
+ starWidth;
p.setPen(!e.bareId
? st::boxTextFgGood ? st::boxTextFgGood
: st::menuIconAttentionColor); : st::menuIconAttentionColor);
const auto x = (amount->width() - fullWidth) / 2; const auto x = (amount->width() - fullWidth) / 2;
@ -463,11 +478,41 @@ void ReceiptCreditsBox(
(amount->height() - font->height) / 2), (amount->height() - font->height) / 2),
.outerWidth = amount->width(), .outerWidth = amount->width(),
.availableWidth = amount->width(), .availableWidth = amount->width(),
});; });
p.drawImage( p.drawImage(
x + fullWidth - starWidth, x + fullWidth - starWidth - refundedWidth,
0, 0,
star); star);
if (refunded) {
const auto refundedLeft = fullWidth
+ x
- refundedWidth
+ refundedSkip;
const auto pen = p.pen();
auto color = pen.color();
color.setAlphaF(color.alphaF() * 0.15);
p.setPen(Qt::NoPen);
p.setBrush(color);
{
auto hq = PainterHighQualityEnabler(p);
p.drawRoundedRect(
refundedLeft,
(amount->height() - refundedFont->height) / 2,
refundedWidth - refundedSkip,
refundedFont->height,
refundedFont->height / 2,
refundedFont->height / 2);
}
p.setPen(pen);
refunded->draw(p, Ui::Text::PaintContext{
.position = QPoint(
refundedLeft + refundedFont->height / 2,
(amount->height() - refundedFont->height) / 2),
.outerWidth = refundedWidth,
.availableWidth = refundedWidth,
});
}
}, amount->lifetime()); }, amount->lifetime());
} }
@ -481,16 +526,6 @@ void ReceiptCreditsBox(
st::defaultFlatLabel))); st::defaultFlatLabel)));
} }
if (e.refunded) {
Ui::AddSkip(content);
box->addRow(object_ptr<Ui::CenterWrap<>>(
box,
object_ptr<Ui::FlatLabel>(
box,
tr::lng_channel_earn_history_return_about(),
st::defaultFlatLabel)));
}
Ui::AddSkip(content); Ui::AddSkip(content);
Ui::AddSkip(content); Ui::AddSkip(content);