mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Added to AbstractBox ability to center box when changing dimensions.
- Added using of force center for edit_caption_box.
This commit is contained in:
parent
145dda843e
commit
468975e9f3
3 changed files with 22 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue