info_profile_text.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "info/profile/info_profile_text.h"
  8. #include <rpl/before_next.h>
  9. #include <rpl/filter.h>
  10. #include <rpl/after_next.h>
  11. #include "ui/widgets/labels.h"
  12. #include "ui/wrap/slide_wrap.h"
  13. #include "ui/wrap/vertical_layout.h"
  14. #include "styles/style_info.h"
  15. namespace Info {
  16. namespace Profile {
  17. TextWithLabel CreateTextWithLabel(
  18. QWidget *parent,
  19. rpl::producer<TextWithEntities> &&label,
  20. rpl::producer<TextWithEntities> &&text,
  21. const style::FlatLabel &labelSt,
  22. const style::FlatLabel &textSt,
  23. const style::margins &padding) {
  24. auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
  25. parent,
  26. object_ptr<Ui::VerticalLayout>(parent),
  27. padding);
  28. result->setDuration(st::infoSlideDuration);
  29. auto layout = result->entity();
  30. auto nonEmptyText = rpl::duplicate(
  31. text
  32. ) | rpl::before_next([slide = result.data()](
  33. const TextWithEntities &value) {
  34. if (value.text.isEmpty()) {
  35. slide->hide(anim::type::normal);
  36. }
  37. }) | rpl::filter([](const TextWithEntities &value) {
  38. return !value.text.isEmpty();
  39. }) | rpl::after_next([slide = result.data()](
  40. const TextWithEntities &value) {
  41. slide->show(anim::type::normal);
  42. });
  43. const auto labeled = layout->add(object_ptr<Ui::FlatLabel>(
  44. layout,
  45. std::move(nonEmptyText),
  46. textSt));
  47. std::move(text) | rpl::start_with_next([=] {
  48. labeled->resizeToWidth(layout->width());
  49. }, labeled->lifetime());
  50. labeled->setSelectable(true);
  51. layout->add(Ui::CreateSkipWidget(layout, st::infoLabelSkip));
  52. const auto subtext = layout->add(object_ptr<Ui::FlatLabel>(
  53. layout,
  54. std::move(
  55. label
  56. ) | rpl::after_next([=] {
  57. layout->resizeToWidth(layout->widthNoMargins());
  58. }),
  59. labelSt));
  60. result->finishAnimating();
  61. return { std::move(result), labeled, subtext };
  62. }
  63. } // namespace Profile
  64. } // namespace Info