/* 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 "ui/effects/animations.h" #include "base/flat_map.h" namespace Main { class Session; } // namespace Main namespace Ui { class ThanosEffect; class ScrollArea; struct ChatPaintContext; } // namespace Ui namespace HistoryView { class Element; } // namespace HistoryView class HistoryItem; namespace Ui { struct CollapseGap { int absY = -1; int height = 0; friend bool operator==(const CollapseGap&, const CollapseGap&) = default; }; class ThanosEffectController final { public: struct Delegate { Fn)> viewForItem; Fn)> itemTop; Fn visibleAreaTop; Fn visibleAreaBottom; Fn contentWidth; Fn preparePaintContext; Fn window; Fn()> scrollArea; Fn scrollToY; Fn)> setCollapseGaps; }; ThanosEffectController( not_null session, Delegate delegate, rpl::lifetime &lifetime); ~ThanosEffectController(); void captureOnRemoval(not_null item); void clearPreCaptured(); [[nodiscard]] const std::vector &renderGaps() const { return _renderGaps; } private: struct PreCapturedView { int height = 0; int top = 0; }; struct CollapseGapState { int absY = -1; int startHeight = 0; int currentHeight = 0; int originalHeight = 0; }; void captureItemsBatch( const std::vector> &items); [[nodiscard]] bool captureView( not_null view, int viewHeight, int viewTop); void startCollapseAnimation(int height, int itemTop); void collapseAnimationCallback(); void syncCollapseGapsToHost(); void ensureScrollBaseline(); const not_null _session; const Delegate _delegate; std::unique_ptr _thanosEffect; base::flat_map _preCaptured; std::vector _renderGaps; std::vector _collapseGaps; Animations::Simple _collapseAnimation; int _savedScrollTop = 0; bool _restoreScrollPending = false; }; } // namespace Ui