diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index db97bfe72..24992aa38 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -436,7 +436,7 @@ QPointer AbstractBox::addTopButton(const style::IconButton &st, return result; } -void AbstractBox::setDimensions(int newWidth, int maxHeight) { +void AbstractBox::setDimensions(int newWidth, int maxHeight, bool forceCenterPosition) { _maxContentHeight = maxHeight; auto fullHeight = countFullHeight(); @@ -447,8 +447,13 @@ void AbstractBox::setDimensions(int newWidth, int maxHeight) { resize(newWidth, countRealHeight()); auto newGeometry = geometry(); auto parentHeight = parentWidget()->height(); - if (newGeometry.top() + newGeometry.height() + st::boxVerticalMargin > parentHeight) { - auto newTop = qMax(parentHeight - int(st::boxVerticalMargin) - newGeometry.height(), (parentHeight - newGeometry.height()) / 2); + if (newGeometry.top() + newGeometry.height() + st::boxVerticalMargin > parentHeight + || forceCenterPosition) { + const auto top1 = parentHeight - int(st::boxVerticalMargin) - newGeometry.height(); + const auto top2 = (parentHeight - newGeometry.height()) / 2; + const auto newTop = forceCenterPosition + ? std::min(top1, top2) + : std::max(top1, top2); if (newTop != newGeometry.top()) { move(newGeometry.left(), newTop); } diff --git a/Telegram/SourceFiles/boxes/abstract_box.h b/Telegram/SourceFiles/boxes/abstract_box.h index 22f13015d..dec783340 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.h +++ b/Telegram/SourceFiles/boxes/abstract_box.h @@ -44,7 +44,10 @@ public: object_ptr box, LayerOptions options, anim::type animated) = 0; - virtual void setDimensions(int newWidth, int maxHeight) = 0; + virtual void setDimensions( + int newWidth, + int maxHeight, + bool forceCenterPosition = false) = 0; virtual void setNoContentMargin(bool noContentMargin) = 0; virtual bool isBoxShown() const = 0; virtual void closeBox() = 0; @@ -158,8 +161,11 @@ protected: } getDelegate()->setNoContentMargin(noContentMargin); } - void setDimensions(int newWidth, int maxHeight) { - getDelegate()->setDimensions(newWidth, maxHeight); + void setDimensions( + int newWidth, + int maxHeight, + bool forceCenterPosition = false) { + getDelegate()->setDimensions(newWidth, maxHeight, forceCenterPosition); } void setDimensionsToContent( int newWidth, @@ -264,7 +270,10 @@ public: void updateButtonsPositions() override; QPointer outerContainer() override; - void setDimensions(int newWidth, int maxHeight) override; + void setDimensions( + int newWidth, + int maxHeight, + bool forceCenterPosition = false) override; void setNoContentMargin(bool noContentMargin) override { if (_noContentMargin != noContentMargin) { diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 501782779..a652831a5 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -500,7 +500,7 @@ void EditCaptionBox::updateBoxSize() { } else { newHeight += st::boxTitleFont->height; } - setDimensions(st::boxWideWidth, newHeight); + setDimensions(st::boxWideWidth, newHeight, true); } int EditCaptionBox::errorTopSkip() const {