scroll_content_shadow.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "ui/effects/scroll_content_shadow.h"
  8. #include "ui/rp_widget.h"
  9. #include "ui/widgets/scroll_area.h"
  10. #include "ui/wrap/fade_wrap.h"
  11. #include "ui/ui_utility.h"
  12. namespace Ui {
  13. void SetupShadowsToScrollContent(
  14. not_null<Ui::RpWidget*> parent,
  15. not_null<Ui::ScrollArea*> scroll,
  16. rpl::producer<int> &&innerHeightValue) {
  17. using namespace rpl::mappers;
  18. const auto topShadow = Ui::CreateChild<Ui::FadeShadow>(parent.get());
  19. const auto bottomShadow = Ui::CreateChild<Ui::FadeShadow>(parent.get());
  20. scroll->geometryValue(
  21. ) | rpl::start_with_next_done([=](const QRect &geometry) {
  22. topShadow->resizeToWidth(geometry.width());
  23. topShadow->move(
  24. geometry.x(),
  25. geometry.y());
  26. bottomShadow->resizeToWidth(geometry.width());
  27. bottomShadow->move(
  28. geometry.x(),
  29. geometry.y() + geometry.height() - st::lineWidth);
  30. }, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] {
  31. Ui::DestroyChild(t.data());
  32. Ui::DestroyChild(b.data());
  33. }, topShadow->lifetime());
  34. topShadow->toggleOn(scroll->scrollTopValue() | rpl::map(_1 > 0));
  35. bottomShadow->toggleOn(rpl::combine(
  36. scroll->scrollTopValue(),
  37. scroll->heightValue(),
  38. std::move(innerHeightValue),
  39. _1 + _2 < _3));
  40. }
  41. } // namespace Ui