From df8176d67152843c53f9ef1986e5cd66d1199907 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 28 Dec 2022 12:41:30 +0400 Subject: [PATCH] Fix non-shown group thumb in media viewer. --- .../media/view/media_view_group_thumbs.cpp | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 37b5e2ae7f..6568df3b0b 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -190,18 +190,19 @@ public: Data::FileOrigin origin, Fn handler); - int leftToUpdate() const; - int rightToUpdate() const; + [[nodiscard]] int leftToUpdate() const; + [[nodiscard]] int rightToUpdate() const; void animateToLeft(not_null next); void animateToRight(not_null prev); void setState(State state); - State state() const; - bool removed() const; + [[nodiscard]] State state() const; + [[nodiscard]] bool inited() const; + [[nodiscard]] bool removed() const; void paint(QPainter &p, int x, int y, int outerWidth, float64 progress); - ClickHandlerPtr getState(QPoint point) const; + [[nodiscard]] ClickHandlerPtr getState(QPoint point) const; private: QSize wantedPixSize() const; @@ -400,6 +401,10 @@ auto GroupThumbs::Thumb::state() const -> State { return _state; } +bool GroupThumbs::Thumb::inited() const { + return _fullWidth != 0; +} + bool GroupThumbs::Thumb::removed() const { return (_state == State::Dying) && _hiding && !_opacity.current(); } @@ -819,21 +824,27 @@ void GroupThumbs::paint(QPainter &p, int x, int y, int outerWidth) { : _animation.value(1.); x += (_width / 2); y += st::mediaviewGroupPadding.top(); + auto initedCurrentIndex = int(_items.size()); for (auto i = _cache.begin(); i != _cache.end();) { - const auto &thumb = i->second; + const auto thumb = not_null{ i->second.get() }; + const auto inited = thumb->inited(); thumb->paint(p, x, y, outerWidth, progress); if (thumb->removed()) { - _dying.erase( - ranges::remove( - _dying, - thumb.get(), - [](not_null thumb) { return thumb.get(); }), - _dying.end()); + _dying.erase(ranges::remove(_dying, thumb), _dying.end()); i = _cache.erase(i); } else { + if (!inited + && thumb->inited() + && thumb->state() == Thumb::State::Current) { + initedCurrentIndex = ranges::find(_items, thumb) + - begin(_items); + } ++i; } } + if (initedCurrentIndex < _items.size()) { + animateAliveItems(initedCurrentIndex); + } } ClickHandlerPtr GroupThumbs::getState(QPoint point) const {