Improved style of button for earn out when it is disabled.

This commit is contained in:
23rd 2024-11-11 19:32:21 +03:00
parent e56bbf557d
commit d37c040b36

View file

@ -1855,44 +1855,48 @@ void AddWithdrawalWidget(
}, label->lifetime()); }, label->lifetime());
const auto lockedColor = anim::with_alpha(stButton.textFg->c, .5); const auto lockedColor = anim::with_alpha(stButton.textFg->c, .5);
const auto lockedLabelTop = Ui::CreateChild<Ui::FlatLabel>( const auto lockedLabel = Ui::CreateChild<Ui::RpWidget>(button);
button, lockedLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
tr::lng_bot_earn_balance_button_locked(), struct LockedState final {
st::botEarnLockedButtonLabel); Ui::Text::String text;
lockedLabelTop->setTextColorOverride(lockedColor); bool locked = false;
lockedLabelTop->setAttribute(Qt::WA_TransparentForMouseEvents); bool dateIsNull = false;
const auto lockedLabelBottom = Ui::CreateChild<Ui::FlatLabel>( rpl::lifetime dateUpdateLifetime;
button, };
QString(), const auto state = lockedLabel->lifetime().make_state<LockedState>();
st::botEarnLockedButtonLabel);
lockedLabelBottom->setTextColorOverride(lockedColor);
lockedLabelBottom->setAttribute(Qt::WA_TransparentForMouseEvents);
rpl::combine( rpl::combine(
rpl::duplicate(lockedValue), rpl::duplicate(lockedValue),
button->sizeValue(), button->sizeValue()
lockedLabelTop->sizeValue(), ) | rpl::start_with_next([=](bool locked, const QSize &s) {
lockedLabelBottom->sizeValue() state->locked = locked;
) | rpl::start_with_next([=]( lockedLabel->resize(s);
bool locked, }, lockedLabel->lifetime());
const QSize &b, lockedLabel->paintRequest() | rpl::start_with_next([=] {
const QSize &top, auto p = QPainter(lockedLabel);
const QSize &bottom) { p.setPen(state->locked ? QPen(lockedColor) : stButton.textFg->p);
const auto factor = locked ? 1 : -10; if (state->dateIsNull) {
const auto sumHeight = top.height() + bottom.height(); p.setFont(st::channelEarnSemiboldLabel.style.font);
lockedLabelTop->moveToLeft( p.drawText(
(b.width() - top.width()) / 2, lockedLabel->rect(),
factor * (b.height() - sumHeight) / 2); style::al_center,
lockedLabelBottom->moveToLeft( tr::lng_bot_earn_balance_button_locked(tr::now));
(b.width() - bottom.width()) / 2, return;
factor * ((b.height() - sumHeight) / 2 + top.height())); }
}, lockedLabelTop->lifetime()); state->text.draw(p, {
.position = QPoint(
0,
(lockedLabel->height() - state->text.minHeight()) / 2),
.outerWidth = lockedLabel->width(),
.availableWidth = lockedLabel->width(),
.align = style::al_center,
});
}, lockedLabel->lifetime());
const auto dateUpdateLifetime
= lockedLabelBottom->lifetime().make_state<rpl::lifetime>();
std::move( std::move(
dateValue dateValue
) | rpl::start_with_next([=](const QDateTime &dt) { ) | rpl::start_with_next([=](const QDateTime &dt) {
dateUpdateLifetime->destroy(); state->dateUpdateLifetime.destroy();
state->dateIsNull = dt.isNull();
if (dt.isNull()) { if (dt.isNull()) {
return; return;
} }
@ -1901,7 +1905,7 @@ void AddWithdrawalWidget(
const auto context = Core::MarkedTextContext{ const auto context = Core::MarkedTextContext{
.session = session, .session = session,
.customEmojiRepaint = [=] { lockedLabelBottom->update(); }, .customEmojiRepaint = [=] { lockedLabel->update(); },
}; };
const auto emoji = Ui::Text::SingleCustomEmoji( const auto emoji = Ui::Text::SingleCustomEmoji(
session->data().customEmojiManager().registerInternalEmoji( session->data().customEmojiManager().registerInternalEmoji(
@ -1929,11 +1933,18 @@ void AddWithdrawalWidget(
: (u"%1:%2"_q) : (u"%1:%2"_q)
.arg(minutes, 2, 10, kZero) .arg(minutes, 2, 10, kZero)
.arg(seconds, 2, 10, kZero); .arg(seconds, 2, 10, kZero);
lockedLabelBottom->setMarkedText( state->text.setMarkedText(
base::duplicate(emoji).append(formatted), st::botEarnLockedButtonLabel.style,
TextWithEntities()
.append(tr::lng_bot_earn_balance_button_locked(tr::now))
.append('\n')
.append(emoji)
.append(formatted),
kMarkupTextOptions,
context); context);
}, *dateUpdateLifetime); lockedLabel->update();
}, lockedLabelBottom->lifetime()); }, state->dateUpdateLifetime);
}, lockedLabel->lifetime());
Api::HandleWithdrawalButton( Api::HandleWithdrawalButton(
Api::RewardReceiver{ Api::RewardReceiver{