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

Function MakeLinkLabel

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

Source from the content-addressed store, hash-verified

575}
576
577object_ptr<Ui::RpWidget> MakeLinkLabel(
578 not_null<QWidget*> parent,
579 rpl::producer<QString> text,
580 rpl::producer<QString> link,
581 std::shared_ptr<Ui::Show> show,
582 object_ptr<Ui::RpWidget> right) {
583 auto result = object_ptr<Ui::AbstractButton>(parent);
584 const auto raw = result.data();
585
586 const auto rawRight = right.release();
587 if (rawRight) {
588 rawRight->setParent(raw);
589 rawRight->show();
590 }
591
592 struct State {
593 State(
594 not_null<QWidget*> parent,
595 rpl::producer<QString> value,
596 rpl::producer<QString> link)
597 : text(std::move(value))
598 , link(std::move(link))
599 , label(parent, text.value(), st::giveawayGiftCodeLink)
600 , bg(st::roundRadiusLarge, st::windowBgOver) {
601 }
602
603 rpl::variable<QString> text;
604 rpl::variable<QString> link;
605 Ui::FlatLabel label;
606 Ui::RoundRect bg;
607 };
608
609 const auto state = raw->lifetime().make_state<State>(
610 raw,
611 rpl::duplicate(text),
612 std::move(link));
613 state->label.setSelectable(true);
614
615 rpl::combine(
616 raw->widthValue(),
617 std::move(text)
618 ) | rpl::on_next([=](int outer, const auto&) {
619 const auto textWidth = state->label.textMaxWidth();
620 const auto skipLeft = st::giveawayGiftCodeLink.margin.left();
621 const auto skipRight = rawRight
622 ? rawRight->width()
623 : st::giveawayGiftCodeLink.margin.right();
624 const auto available = outer - skipRight - skipLeft;
625 const auto use = std::min(textWidth, available);
626 state->label.resizeToWidth(use);
627 const auto forCenter = (outer - use) / 2;
628 const auto x = (forCenter < skipLeft)
629 ? skipLeft
630 : (forCenter > outer - skipRight - use)
631 ? (outer - skipRight - use)
632 : forCenter;
633 state->label.moveToLeft(x, st::giveawayGiftCodeLink.margin.top());
634 }, raw->lifetime());

Callers 4

AskBoostBoxFunction · 0.70
GiftCodeBoxFunction · 0.50
GiftCodePendingBoxFunction · 0.50

Calls 15

moveToLeftMethod · 0.80
resizeMethod · 0.80
QPainterClass · 0.50
dataMethod · 0.45
releaseMethod · 0.45
showMethod · 0.45
widthValueMethod · 0.45
widthMethod · 0.45
resizeToWidthMethod · 0.45
topMethod · 0.45
paintMethod · 0.45
rectMethod · 0.45

Tested by

no test coverage detected