Fix layer height updating in poll results.

This commit is contained in:
John Preston 2022-04-27 15:19:52 +04:00
parent 4062912a98
commit 823fc25fa8
2 changed files with 34 additions and 14 deletions

View file

@ -82,7 +82,11 @@ void LayerWidget::setupHeightConsumers() {
_content->scrollTillBottomChanges( _content->scrollTillBottomChanges(
) | rpl::filter([this] { ) | rpl::filter([this] {
return !_inResize; if (!_inResize) {
return true;
}
_pendingResize = true;
return false;
}) | rpl::start_with_next([this] { }) | rpl::start_with_next([this] {
resizeToWidth(width()); resizeToWidth(width());
}, lifetime()); }, lifetime());
@ -125,8 +129,11 @@ void LayerWidget::setContentHeight(int height) {
if (_contentHeight == height) { if (_contentHeight == height) {
return; return;
} }
_contentHeight = height; _contentHeight = height;
if (_content && !_inResize) { if (_inResize) {
_pendingResize = true;
} else if (_content) {
resizeToWidth(width()); resizeToWidth(width());
} }
} }
@ -240,9 +247,29 @@ int LayerWidget::resizeGetHeight(int newWidth) {
if (!parentWidget() || !_content) { if (!parentWidget() || !_content) {
return 0; return 0;
} }
_inResize = true; constexpr auto kMaxAttempts = 5;
auto guard = gsl::finally([&] { _inResize = false; }); 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 parentSize = parentWidget()->size();
auto windowWidth = parentSize.width(); auto windowWidth = parentSize.width();
auto windowHeight = parentSize.height(); auto windowHeight = parentSize.height();
@ -282,16 +309,7 @@ int LayerWidget::resizeGetHeight(int newWidth) {
contentHeight, contentHeight,
}, expanding, additionalScroll); }, expanding, additionalScroll);
auto newGeometry = QRect(newLeft, newTop, newWidth, desiredHeight); return QRect(newLeft, newTop, newWidth, desiredHeight);
if (newGeometry != geometry()) {
_content->forceContentRepaint();
}
if (newGeometry.topLeft() != geometry().topLeft()) {
move(newGeometry.topLeft());
}
floatPlayerUpdatePositions();
return desiredHeight;
} }
void LayerWidget::doSetInnerFocus() { void LayerWidget::doSetInnerFocus() {

View file

@ -69,6 +69,7 @@ private:
void setupHeightConsumers(); void setupHeightConsumers();
void setContentHeight(int height); void setContentHeight(int height);
[[nodiscard]] QRect countGeometry(int newWidth);
not_null<Window::SessionController*> _controller; not_null<Window::SessionController*> _controller;
object_ptr<WrapWidget> _content; object_ptr<WrapWidget> _content;
@ -80,6 +81,7 @@ private:
Ui::Animations::Simple _savedHeightAnimation; Ui::Animations::Simple _savedHeightAnimation;
bool _heightAnimated = false; bool _heightAnimated = false;
bool _inResize = false; bool _inResize = false;
bool _pendingResize = false;
bool _tillBottom = false; bool _tillBottom = false;
bool _floatPlayerDelegateRestored = false; bool _floatPlayerDelegateRestored = false;