mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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/search_field_controller.h
|
||||||
ui/text/format_song_document_name.cpp
|
ui/text/format_song_document_name.cpp
|
||||||
ui/text/format_song_document_name.h
|
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.cpp
|
||||||
ui/unread_badge.h
|
ui/unread_badge.h
|
||||||
window/main_window.cpp
|
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/prepare_short_info_box.h"
|
||||||
#include "boxes/peers/replace_boost_box.h" // BoostsForGift.
|
#include "boxes/peers/replace_boost_box.h" // BoostsForGift.
|
||||||
#include "boxes/premium_preview_box.h" // ShowPremiumPreviewBox.
|
#include "boxes/premium_preview_box.h" // ShowPremiumPreviewBox.
|
||||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
|
||||||
#include "data/data_boosts.h"
|
#include "data/data_boosts.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_channel.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/toast/toast.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/gradient_round_button.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/padding_wrap.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/wrap/table_layout.h"
|
#include "ui/wrap/table_layout.h"
|
||||||
|
@ -319,21 +319,20 @@ void GiftBox(
|
||||||
std::move(titleLabel)),
|
std::move(titleLabel)),
|
||||||
st::premiumGiftTitlePadding);
|
st::premiumGiftTitlePadding);
|
||||||
|
|
||||||
auto textLabel = object_ptr<Ui::FlatLabel>(box, st::premiumPreviewAbout);
|
auto textLabel = Ui::CreateLabelWithCustomEmoji(
|
||||||
tr::lng_premium_gift_about(
|
box,
|
||||||
lt_user,
|
tr::lng_premium_gift_about(
|
||||||
user->session().changes().peerFlagsValue(
|
lt_user,
|
||||||
user,
|
user->session().changes().peerFlagsValue(
|
||||||
Data::PeerUpdate::Flag::Name
|
user,
|
||||||
) | rpl::map([=] { return TextWithEntities{ user->firstName }; }),
|
Data::PeerUpdate::Flag::Name
|
||||||
Ui::Text::RichLangValue
|
) | rpl::map([=] { return TextWithEntities{ user->firstName }; }),
|
||||||
) | rpl::map(
|
Ui::Text::RichLangValue
|
||||||
BoostsForGiftText({ user })
|
) | rpl::map(
|
||||||
) | rpl::start_with_next([
|
BoostsForGiftText({ user })
|
||||||
raw = textLabel.data(),
|
),
|
||||||
session = &user->session()](const TextWithEntities &t) {
|
{ .session = &user->session() },
|
||||||
raw->setMarkedText(t, Core::MarkedTextContext{ .session = session });
|
st::premiumPreviewAbout);
|
||||||
}, textLabel->lifetime());
|
|
||||||
textLabel->setTextColorOverride(stTitle.textFg->c);
|
textLabel->setTextColorOverride(stTitle.textFg->c);
|
||||||
textLabel->resizeToWidth(available);
|
textLabel->resizeToWidth(available);
|
||||||
box->addRow(
|
box->addRow(
|
||||||
|
@ -536,14 +535,12 @@ void GiftsBox(
|
||||||
const auto label = box->addRow(
|
const auto label = box->addRow(
|
||||||
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||||
box,
|
box,
|
||||||
object_ptr<Ui::FlatLabel>(box, st::premiumPreviewAbout)),
|
Ui::CreateLabelWithCustomEmoji(
|
||||||
|
box,
|
||||||
|
std::move(text),
|
||||||
|
{ .session = session },
|
||||||
|
st::premiumPreviewAbout)),
|
||||||
padding)->entity();
|
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->setTextColorOverride(stTitle.textFg->c);
|
||||||
label->resizeToWidth(available);
|
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 "boxes/peers/edit_peer_color_box.h" // AddLevelBadge.
|
||||||
#include "chat_helpers/stickers_emoji_pack.h"
|
#include "chat_helpers/stickers_emoji_pack.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_premium_limits.h"
|
#include "data/data_premium_limits.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -31,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "statistics/chart_widget.h"
|
#include "statistics/chart_widget.h"
|
||||||
#include "ui/basic_click_handlers.h"
|
#include "ui/basic_click_handlers.h"
|
||||||
|
#include "ui/widgets/label_with_custom_emoji.h"
|
||||||
#include "ui/boxes/boost_box.h"
|
#include "ui/boxes/boost_box.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/effects/animation_value_f.h"
|
#include "ui/effects/animation_value_f.h"
|
||||||
|
@ -334,23 +334,21 @@ void InnerWidget::fill() {
|
||||||
st::channelEarnLearnArrowMargins,
|
st::channelEarnLearnArrowMargins,
|
||||||
false));
|
false));
|
||||||
const auto addAboutWithLearn = [&](const tr::phrase<lngtag_link> &text) {
|
const auto addAboutWithLearn = [&](const tr::phrase<lngtag_link> &text) {
|
||||||
auto label = object_ptr<Ui::FlatLabel>(
|
auto label = Ui::CreateLabelWithCustomEmoji(
|
||||||
container,
|
container,
|
||||||
st::boxDividerLabel);
|
text(
|
||||||
const auto raw = label.data();
|
lt_link,
|
||||||
text(
|
tr::lng_channel_earn_about_link(
|
||||||
lt_link,
|
lt_emoji,
|
||||||
tr::lng_channel_earn_about_link(
|
rpl::single(arrow),
|
||||||
lt_emoji,
|
Ui::Text::RichLangValue
|
||||||
rpl::single(arrow),
|
) | rpl::map([](TextWithEntities text) {
|
||||||
|
return Ui::Text::Link(std::move(text), 1);
|
||||||
|
}),
|
||||||
Ui::Text::RichLangValue
|
Ui::Text::RichLangValue
|
||||||
) | rpl::map([](TextWithEntities text) {
|
),
|
||||||
return Ui::Text::Link(std::move(text), 1);
|
{ .session = session },
|
||||||
}),
|
st::boxDividerLabel);
|
||||||
Ui::Text::RichLangValue
|
|
||||||
) | rpl::start_with_next([=](const TextWithEntities &text) {
|
|
||||||
raw->setMarkedText(text, makeContext(raw));
|
|
||||||
}, label->lifetime());
|
|
||||||
label->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
label->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
||||||
_show->showBox(Box([=](not_null<Ui::GenericBox*> box) {
|
_show->showBox(Box([=](not_null<Ui::GenericBox*> box) {
|
||||||
box->setNoContentMargin(true);
|
box->setNoContentMargin(true);
|
||||||
|
@ -454,17 +452,16 @@ void InnerWidget::fill() {
|
||||||
const auto l = box->addRow(
|
const auto l = box->addRow(
|
||||||
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::FlatLabel>(
|
Ui::CreateLabelWithCustomEmoji(
|
||||||
content,
|
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();
|
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);
|
const auto diamonds = l->lifetime().make_state<int>(0);
|
||||||
l->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
l->setLink(1, std::make_shared<LambdaClickHandler>([=] {
|
||||||
const auto count = (*diamonds);
|
const auto count = (*diamonds);
|
||||||
|
@ -480,25 +477,23 @@ void InnerWidget::fill() {
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
{
|
{
|
||||||
const auto label = box->addRow(
|
const auto label = box->addRow(
|
||||||
object_ptr<Ui::FlatLabel>(
|
Ui::CreateLabelWithCustomEmoji(
|
||||||
content,
|
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));
|
st::channelEarnLearnDescription));
|
||||||
tr::lng_channel_earn_learn_coin_about(
|
label->resizeToWidth(box->width()
|
||||||
lt_link,
|
- rect::m::sum::h(st::boxRowPadding));
|
||||||
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->setLink(
|
label->setLink(
|
||||||
1,
|
1,
|
||||||
LearnMoreCurrencyLink(
|
LearnMoreCurrencyLink(
|
||||||
|
|
|
@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "boxes/premium_preview_box.h"
|
#include "boxes/premium_preview_box.h"
|
||||||
#include "chat_helpers/compose/compose_show.h"
|
#include "chat_helpers/compose/compose_show.h"
|
||||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
|
||||||
#include "data/components/sponsored_messages.h"
|
#include "data/components/sponsored_messages.h"
|
||||||
#include "data/data_premium_limits.h"
|
#include "data/data_premium_limits.h"
|
||||||
#include "data/data_session.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/vertical_list.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
#include "ui/widgets/label_with_custom_emoji.h"
|
||||||
#include "styles/style_channel_earn.h"
|
#include "styles/style_channel_earn.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
@ -169,31 +169,23 @@ void AboutBox(
|
||||||
st::topicButtonArrow,
|
st::topicButtonArrow,
|
||||||
st::channelEarnLearnArrowMargins,
|
st::channelEarnLearnArrowMargins,
|
||||||
false));
|
false));
|
||||||
const auto label = box->addRow(
|
const auto available = box->width()
|
||||||
object_ptr<Ui::FlatLabel>(
|
- rect::m::sum::h(st::boxRowPadding);
|
||||||
|
box->addRow(
|
||||||
|
Ui::CreateLabelWithCustomEmoji(
|
||||||
content,
|
content,
|
||||||
st::channelEarnLearnDescription));
|
tr::lng_sponsored_revenued_footer_description(
|
||||||
tr::lng_sponsored_revenued_footer_description(
|
lt_link,
|
||||||
lt_link,
|
tr::lng_channel_earn_about_link(
|
||||||
tr::lng_channel_earn_about_link(
|
lt_emoji,
|
||||||
lt_emoji,
|
rpl::single(arrow),
|
||||||
rpl::single(arrow),
|
Ui::Text::RichLangValue
|
||||||
Ui::Text::RichLangValue
|
) | rpl::map([=](TextWithEntities text) {
|
||||||
) | rpl::map([=](TextWithEntities text) {
|
return Ui::Text::Link(std::move(text), kUrl.utf16());
|
||||||
return Ui::Text::Link(std::move(text), kUrl.utf16());
|
}),
|
||||||
}),
|
Ui::Text::RichLangValue),
|
||||||
Ui::Text::RichLangValue
|
{ .session = session },
|
||||||
) | rpl::start_with_next([=, l = label](
|
st::channelEarnLearnDescription))->resizeToWidth(available);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
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