mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Simplified creation of label with custom emoji.
This commit is contained in:
parent
0459196982
commit
5433f95eda
6 changed files with 143 additions and 90 deletions
|
@ -1474,6 +1474,8 @@ PRIVATE
|
|||
ui/search_field_controller.h
|
||||
ui/text/format_song_document_name.cpp
|
||||
ui/text/format_song_document_name.h
|
||||
ui/widgets/label_with_custom_emoji.cpp
|
||||
ui/widgets/label_with_custom_emoji.h
|
||||
ui/unread_badge.cpp
|
||||
ui/unread_badge.h
|
||||
window/main_window.cpp
|
||||
|
|
|
@ -16,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/peers/prepare_short_info_box.h"
|
||||
#include "boxes/peers/replace_boost_box.h" // BoostsForGift.
|
||||
#include "boxes/premium_preview_box.h" // ShowPremiumPreviewBox.
|
||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
||||
#include "data/data_boosts.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_channel.h"
|
||||
|
@ -48,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/toast/toast.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/gradient_round_button.h"
|
||||
#include "ui/widgets/label_with_custom_emoji.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/table_layout.h"
|
||||
|
@ -319,21 +319,20 @@ void GiftBox(
|
|||
std::move(titleLabel)),
|
||||
st::premiumGiftTitlePadding);
|
||||
|
||||
auto textLabel = object_ptr<Ui::FlatLabel>(box, st::premiumPreviewAbout);
|
||||
tr::lng_premium_gift_about(
|
||||
lt_user,
|
||||
user->session().changes().peerFlagsValue(
|
||||
user,
|
||||
Data::PeerUpdate::Flag::Name
|
||||
) | rpl::map([=] { return TextWithEntities{ user->firstName }; }),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map(
|
||||
BoostsForGiftText({ user })
|
||||
) | rpl::start_with_next([
|
||||
raw = textLabel.data(),
|
||||
session = &user->session()](const TextWithEntities &t) {
|
||||
raw->setMarkedText(t, Core::MarkedTextContext{ .session = session });
|
||||
}, textLabel->lifetime());
|
||||
auto textLabel = Ui::CreateLabelWithCustomEmoji(
|
||||
box,
|
||||
tr::lng_premium_gift_about(
|
||||
lt_user,
|
||||
user->session().changes().peerFlagsValue(
|
||||
user,
|
||||
Data::PeerUpdate::Flag::Name
|
||||
) | rpl::map([=] { return TextWithEntities{ user->firstName }; }),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map(
|
||||
BoostsForGiftText({ user })
|
||||
),
|
||||
{ .session = &user->session() },
|
||||
st::premiumPreviewAbout);
|
||||
textLabel->setTextColorOverride(stTitle.textFg->c);
|
||||
textLabel->resizeToWidth(available);
|
||||
box->addRow(
|
||||
|
@ -536,14 +535,12 @@ void GiftsBox(
|
|||
const auto label = box->addRow(
|
||||
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||
box,
|
||||
object_ptr<Ui::FlatLabel>(box, st::premiumPreviewAbout)),
|
||||
Ui::CreateLabelWithCustomEmoji(
|
||||
box,
|
||||
std::move(text),
|
||||
{ .session = session },
|
||||
st::premiumPreviewAbout)),
|
||||
padding)->entity();
|
||||
std::move(
|
||||
text
|
||||
) | rpl::start_with_next([=](const TextWithEntities &t) {
|
||||
using namespace Core;
|
||||
label->setMarkedText(t, MarkedTextContext{ .session = session });
|
||||
}, label->lifetime());
|
||||
label->setTextColorOverride(stTitle.textFg->c);
|
||||
label->resizeToWidth(available);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/peers/edit_peer_color_box.h" // AddLevelBadge.
|
||||
#include "chat_helpers/stickers_emoji_pack.h"
|
||||
#include "core/application.h"
|
||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_session.h"
|
||||
|
@ -31,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "statistics/chart_widget.h"
|
||||
#include "ui/basic_click_handlers.h"
|
||||
#include "ui/widgets/label_with_custom_emoji.h"
|
||||
#include "ui/boxes/boost_box.h"
|
||||
#include "ui/controls/userpic_button.h"
|
||||
#include "ui/effects/animation_value_f.h"
|
||||
|
@ -334,23 +334,21 @@ void InnerWidget::fill() {
|
|||
st::channelEarnLearnArrowMargins,
|
||||
false));
|
||||
const auto addAboutWithLearn = [&](const tr::phrase<lngtag_link> &text) {
|
||||
auto label = object_ptr<Ui::FlatLabel>(
|
||||
auto label = Ui::CreateLabelWithCustomEmoji(
|
||||
container,
|
||||
st::boxDividerLabel);
|
||||
const auto raw = label.data();
|
||||
text(
|
||||
lt_link,
|
||||
tr::lng_channel_earn_about_link(
|
||||
lt_emoji,
|
||||
rpl::single(arrow),
|
||||
text(
|
||||
lt_link,
|
||||
tr::lng_channel_earn_about_link(
|
||||
lt_emoji,
|
||||
rpl::single(arrow),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map([](TextWithEntities text) {
|
||||
return Ui::Text::Link(std::move(text), 1);
|
||||
}),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map([](TextWithEntities text) {
|
||||
return Ui::Text::Link(std::move(text), 1);
|
||||
}),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::start_with_next([=](const TextWithEntities &text) {
|
||||
raw->setMarkedText(text, makeContext(raw));
|
||||
}, label->lifetime());
|
||||
),
|
||||
{ .session = session },
|
||||
st::boxDividerLabel);
|
||||
label->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
||||
_show->showBox(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
box->setNoContentMargin(true);
|
||||
|
@ -454,17 +452,16 @@ void InnerWidget::fill() {
|
|||
const auto l = box->addRow(
|
||||
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||
content,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
Ui::CreateLabelWithCustomEmoji(
|
||||
content,
|
||||
tr::lng_channel_earn_learn_coin_title(
|
||||
lt_emoji,
|
||||
rpl::single(
|
||||
Ui::Text::Link(bigCurrencyIcon, 1)),
|
||||
Ui::Text::RichLangValue
|
||||
),
|
||||
{ .session = session },
|
||||
st::boxTitle)))->entity();
|
||||
tr::lng_channel_earn_learn_coin_title(
|
||||
lt_emoji,
|
||||
rpl::single(
|
||||
Ui::Text::Link(bigCurrencyIcon, 1)),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::start_with_next([=](TextWithEntities t) {
|
||||
l->setMarkedText(std::move(t), makeContext(l));
|
||||
}, l->lifetime());
|
||||
const auto diamonds = l->lifetime().make_state<int>(0);
|
||||
l->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
||||
const auto count = (*diamonds);
|
||||
|
@ -480,25 +477,23 @@ void InnerWidget::fill() {
|
|||
Ui::AddSkip(content);
|
||||
{
|
||||
const auto label = box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
Ui::CreateLabelWithCustomEmoji(
|
||||
content,
|
||||
tr::lng_channel_earn_learn_coin_about(
|
||||
lt_link,
|
||||
tr::lng_channel_earn_about_link(
|
||||
lt_emoji,
|
||||
rpl::single(arrow),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map([](TextWithEntities text) {
|
||||
return Ui::Text::Link(std::move(text), 1);
|
||||
}),
|
||||
Ui::Text::RichLangValue
|
||||
),
|
||||
{ .session = session },
|
||||
st::channelEarnLearnDescription));
|
||||
tr::lng_channel_earn_learn_coin_about(
|
||||
lt_link,
|
||||
tr::lng_channel_earn_about_link(
|
||||
lt_emoji,
|
||||
rpl::single(arrow),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map([](TextWithEntities text) {
|
||||
return Ui::Text::Link(std::move(text), 1);
|
||||
}),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::start_with_next([=, l = label](
|
||||
TextWithEntities t) {
|
||||
l->setMarkedText(std::move(t), makeContext(l));
|
||||
l->resizeToWidth(box->width()
|
||||
- rect::m::sum::h(st::boxRowPadding));
|
||||
}, label->lifetime());
|
||||
label->resizeToWidth(box->width()
|
||||
- rect::m::sum::h(st::boxRowPadding));
|
||||
label->setLink(
|
||||
1,
|
||||
LearnMoreCurrencyLink(
|
||||
|
|
|
@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/premium_preview_box.h"
|
||||
#include "chat_helpers/compose/compose_show.h"
|
||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
||||
#include "data/components/sponsored_messages.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_session.h"
|
||||
|
@ -25,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/label_with_custom_emoji.h"
|
||||
#include "styles/style_channel_earn.h"
|
||||
#include "styles/style_chat.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
@ -169,31 +169,23 @@ void AboutBox(
|
|||
st::topicButtonArrow,
|
||||
st::channelEarnLearnArrowMargins,
|
||||
false));
|
||||
const auto label = box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
const auto available = box->width()
|
||||
- rect::m::sum::h(st::boxRowPadding);
|
||||
box->addRow(
|
||||
Ui::CreateLabelWithCustomEmoji(
|
||||
content,
|
||||
st::channelEarnLearnDescription));
|
||||
tr::lng_sponsored_revenued_footer_description(
|
||||
lt_link,
|
||||
tr::lng_channel_earn_about_link(
|
||||
lt_emoji,
|
||||
rpl::single(arrow),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map([=](TextWithEntities text) {
|
||||
return Ui::Text::Link(std::move(text), kUrl.utf16());
|
||||
}),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::start_with_next([=, l = label](
|
||||
TextWithEntities t) {
|
||||
l->setMarkedText(
|
||||
std::move(t),
|
||||
Core::MarkedTextContext{
|
||||
.session = session,
|
||||
.customEmojiRepaint = [=] { l->update(); },
|
||||
});
|
||||
l->resizeToWidth(box->width()
|
||||
- rect::m::sum::h(st::boxRowPadding));
|
||||
}, label->lifetime());
|
||||
tr::lng_sponsored_revenued_footer_description(
|
||||
lt_link,
|
||||
tr::lng_channel_earn_about_link(
|
||||
lt_emoji,
|
||||
rpl::single(arrow),
|
||||
Ui::Text::RichLangValue
|
||||
) | rpl::map([=](TextWithEntities text) {
|
||||
return Ui::Text::Link(std::move(text), kUrl.utf16());
|
||||
}),
|
||||
Ui::Text::RichLangValue),
|
||||
{ .session = session },
|
||||
st::channelEarnLearnDescription))->resizeToWidth(available);
|
||||
}
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
|
32
Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.cpp
Normal file
32
Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/widgets/label_with_custom_emoji.h"
|
||||
|
||||
#include "core/ui_integration.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
object_ptr<Ui::FlatLabel> CreateLabelWithCustomEmoji(
|
||||
QWidget *parent,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
Core::MarkedTextContext context,
|
||||
const style::FlatLabel &st) {
|
||||
auto label = object_ptr<Ui::FlatLabel>(parent, st);
|
||||
const auto raw = label.data();
|
||||
if (!context.customEmojiRepaint) {
|
||||
context.customEmojiRepaint = [=] { raw->update(); };
|
||||
}
|
||||
std::move(text) | rpl::start_with_next([=](const TextWithEntities &text) {
|
||||
raw->setMarkedText(text, context);
|
||||
}, label->lifetime());
|
||||
return label;
|
||||
}
|
||||
|
||||
} // namespace Ui
|
35
Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.h
Normal file
35
Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
||||
|
||||
template <typename Object>
|
||||
class object_ptr;
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace style {
|
||||
struct FlatLabel;
|
||||
} // namespace style
|
||||
|
||||
namespace Ui {
|
||||
class FlatLabel;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Ui {
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::FlatLabel> CreateLabelWithCustomEmoji(
|
||||
QWidget *parent,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
Core::MarkedTextContext context,
|
||||
const style::FlatLabel &st);
|
||||
|
||||
} // namespace Ui
|
Loading…
Add table
Reference in a new issue