From 823fc25fa8d0fb1ef0169236001fdede4495a43e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Apr 2022 15:19:52 +0400 Subject: [PATCH] Fix layer height updating in poll results. --- .../SourceFiles/info/info_layer_widget.cpp | 46 +++++++++++++------ Telegram/SourceFiles/info/info_layer_widget.h | 2 + 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp index de511c6e5..8d4bfa7ed 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.cpp +++ b/Telegram/SourceFiles/info/info_layer_widget.cpp @@ -82,7 +82,11 @@ void LayerWidget::setupHeightConsumers() { _content->scrollTillBottomChanges( ) | rpl::filter([this] { - return !_inResize; + if (!_inResize) { + return true; + } + _pendingResize = true; + return false; }) | rpl::start_with_next([this] { resizeToWidth(width()); }, lifetime()); @@ -125,8 +129,11 @@ void LayerWidget::setContentHeight(int height) { if (_contentHeight == height) { return; } + _contentHeight = height; - if (_content && !_inResize) { + if (_inResize) { + _pendingResize = true; + } else if (_content) { resizeToWidth(width()); } } @@ -240,9 +247,29 @@ int LayerWidget::resizeGetHeight(int newWidth) { if (!parentWidget() || !_content) { return 0; } - _inResize = true; - auto guard = gsl::finally([&] { _inResize = false; }); + constexpr auto kMaxAttempts = 5; + auto attempts = 0; + while (true) { + _inResize = true; + const auto newGeometry = countGeometry(newWidth); + _inResize = false; + if (!_pendingResize) { + const auto oldGeometry = geometry(); + if (newGeometry != oldGeometry) { + _content->forceContentRepaint(); + } + if (newGeometry.topLeft() != oldGeometry.topLeft()) { + move(newGeometry.topLeft()); + } + floatPlayerUpdatePositions(); + return newGeometry.height(); + } + _pendingResize = false; + Assert(attempts++ < kMaxAttempts); + } +} +QRect LayerWidget::countGeometry(int newWidth) { auto parentSize = parentWidget()->size(); auto windowWidth = parentSize.width(); auto windowHeight = parentSize.height(); @@ -282,16 +309,7 @@ int LayerWidget::resizeGetHeight(int newWidth) { contentHeight, }, expanding, additionalScroll); - auto newGeometry = QRect(newLeft, newTop, newWidth, desiredHeight); - if (newGeometry != geometry()) { - _content->forceContentRepaint(); - } - if (newGeometry.topLeft() != geometry().topLeft()) { - move(newGeometry.topLeft()); - } - - floatPlayerUpdatePositions(); - return desiredHeight; + return QRect(newLeft, newTop, newWidth, desiredHeight); } void LayerWidget::doSetInnerFocus() { diff --git a/Telegram/SourceFiles/info/info_layer_widget.h b/Telegram/SourceFiles/info/info_layer_widget.h index 60d947e21..0f4af7e08 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.h +++ b/Telegram/SourceFiles/info/info_layer_widget.h @@ -69,6 +69,7 @@ private: void setupHeightConsumers(); void setContentHeight(int height); + [[nodiscard]] QRect countGeometry(int newWidth); not_null _controller; object_ptr _content; @@ -80,6 +81,7 @@ private: Ui::Animations::Simple _savedHeightAnimation; bool _heightAnimated = false; bool _inResize = false; + bool _pendingResize = false; bool _tillBottom = false; bool _floatPlayerDelegateRestored = false;