MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / MakeTitle

Function MakeTitle

Telegram/SourceFiles/ui/boxes/boost_box.cpp:51–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51[[nodiscard]] object_ptr<Ui::RpWidget> MakeTitle(
52 not_null<Ui::RpWidget*> parent,
53 rpl::producer<QString> title,
54 rpl::producer<QString> repeated,
55 bool centered = true) {
56 auto result = object_ptr<Ui::RpWidget>(parent);
57
58 struct State {
59 not_null<Ui::FlatLabel*> title;
60 not_null<Ui::FlatLabel*> repeated;
61 };
62 const auto notEmpty = [](const QString &text) {
63 return !text.isEmpty();
64 };
65 const auto state = parent->lifetime().make_state<State>(State{
66 .title = Ui::CreateChild<Ui::FlatLabel>(
67 result.data(),
68 rpl::duplicate(title),
69 st::boostTitle),
70 .repeated = Ui::CreateChild<Ui::FlatLabel>(
71 result.data(),
72 rpl::duplicate(repeated) | rpl::filter(notEmpty),
73 st::boostTitleBadge),
74 });
75 state->title->show();
76 state->repeated->showOn(std::move(repeated) | rpl::map(notEmpty));
77
78 result->resize(result->width(), st::boostTitle.style.font->height);
79
80 rpl::combine(
81 result->widthValue(),
82 rpl::duplicate(title),
83 state->repeated->shownValue(),
84 state->repeated->widthValue()
85 ) | rpl::on_next([=](int outer, auto&&, bool shown, int badge) {
86 const auto repeated = shown ? badge : 0;
87 const auto skip = st::boostTitleBadgeSkip;
88 const auto available = outer - repeated - skip;
89 const auto use = std::min(state->title->textMaxWidth(), available);
90 state->title->resizeToWidth(use);
91 const auto left = centered
92 ? (outer - use - skip - repeated) / 2
93 : 0;
94 state->title->moveToLeft(left, 0);
95 const auto mleft = st::boostTitleBadge.margin.left();
96 const auto mtop = st::boostTitleBadge.margin.top();
97 state->repeated->moveToLeft(left + use + skip + mleft, mtop);
98 }, result->lifetime());
99
100 const auto badge = state->repeated;
101 badge->paintRequest() | rpl::on_next([=] {
102 auto p = QPainter(badge);
103 auto hq = PainterHighQualityEnabler(p);
104 const auto radius = std::min(badge->width(), badge->height()) / 2;
105 p.setPen(Qt::NoPen);
106 p.setBrush(st::premiumButtonBg2);
107 p.drawRoundedRect(badge->rect(), radius, radius);
108 }, badge->lifetime());

Callers 1

BoostBoxFunction · 0.70

Calls 14

resizeMethod · 0.80
moveToLeftMethod · 0.80
QPainterClass · 0.50
isEmptyMethod · 0.45
dataMethod · 0.45
showMethod · 0.45
widthMethod · 0.45
widthValueMethod · 0.45
shownValueMethod · 0.45
resizeToWidthMethod · 0.45
topMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected