Added to AbstractBox ability to center box when changing dimensions.

- Added using of force center for edit_caption_box.
This commit is contained in:
23rd 2019-03-30 22:56:17 +03:00 committed by John Preston
parent 145dda843e
commit 468975e9f3
3 changed files with 22 additions and 8 deletions

View file

@ -436,7 +436,7 @@ QPointer<Ui::IconButton> 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);
}

View file

@ -44,7 +44,10 @@ public:
object_ptr<BoxContent> 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<QWidget> 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) {

View file

@ -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 {