Fix comments layout bug for narrow photos.

This commit is contained in:
John Preston 2020-10-01 14:05:26 +03:00
parent 415990c913
commit 92dbd7089b
5 changed files with 43 additions and 28 deletions

View file

@ -262,6 +262,9 @@ public:
virtual bool hasOutLayout() const;
virtual bool drawBubble() const;
virtual bool hasBubble() const;
virtual int minWidthForMedia() const {
return 0;
}
virtual bool hasFastReply() const;
virtual bool displayFastReply() const;
virtual std::optional<QSize> rightActionSize() const;

View file

@ -421,30 +421,7 @@ QSize Message::performCountOptimalSize() {
minHeight += entry->minHeight();
}
}
if (item->repliesAreComments() && !views->replies.text.isEmpty()) {
const auto limit = HistoryMessageViews::kMaxRecentRepliers;
const auto single = st::historyCommentsUserpicSize;
const auto shift = st::historyCommentsUserpicOverlap;
const auto added = single
+ (limit - 1) * (single - shift)
+ st::historyCommentsSkipLeft
+ st::historyCommentsSkipRight
+ st::historyCommentsSkipText
+ st::historyCommentsOpenOutSelected.width()
+ st::historyCommentsSkipRight
+ st::mediaUnreadSkip
+ st::mediaUnreadSize;
accumulate_max(maxWidth, added + views->replies.textWidth);
} else if (item->externalReply()) {
const auto added = st::historyCommentsIn.width()
+ st::historyCommentsSkipLeft
+ st::historyCommentsSkipRight
+ st::historyCommentsSkipText
+ st::historyCommentsOpenOutSelected.width()
+ st::historyCommentsSkipRight;
accumulate_max(maxWidth, added + st::semiboldFont->width(
tr::lng_replies_view_original(tr::now)));
}
accumulate_max(maxWidth, minWidthForMedia());
} else if (media) {
media->initDimensions();
maxWidth = media->maxWidth();
@ -2028,6 +2005,36 @@ bool Message::hasBubble() const {
return drawBubble();
}
int Message::minWidthForMedia() const {
auto result = infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x());
const auto views = data()->Get<HistoryMessageViews>();
if (data()->repliesAreComments() && !views->replies.text.isEmpty()) {
const auto limit = HistoryMessageViews::kMaxRecentRepliers;
const auto single = st::historyCommentsUserpicSize;
const auto shift = st::historyCommentsUserpicOverlap;
const auto added = single
+ (limit - 1) * (single - shift)
+ st::historyCommentsSkipLeft
+ st::historyCommentsSkipRight
+ st::historyCommentsSkipText
+ st::historyCommentsOpenOutSelected.width()
+ st::historyCommentsSkipRight
+ st::mediaUnreadSkip
+ st::mediaUnreadSize;
accumulate_max(result, added + views->replies.textWidth);
} else if (data()->externalReply()) {
const auto added = st::historyCommentsIn.width()
+ st::historyCommentsSkipLeft
+ st::historyCommentsSkipRight
+ st::historyCommentsSkipText
+ st::historyCommentsOpenOutSelected.width()
+ st::historyCommentsSkipRight;
accumulate_max(result, added + st::semiboldFont->width(
tr::lng_replies_view_original(tr::now)));
}
return result;
}
bool Message::hasFastReply() const {
if (context() == Context::Replies) {
if (data()->isDiscussionPost()) {

View file

@ -91,6 +91,7 @@ public:
bool hasOutLayout() const override;
bool drawBubble() const override;
bool hasBubble() const override;
int minWidthForMedia() const override;
bool hasFastReply() const override;
bool displayFastReply() const override;
bool displayRightActionComments() const;

View file

@ -82,7 +82,7 @@ QSize Location::countOptimalSize() {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
}
auto minWidth = qMax(st::minPhotoSize, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
auto minWidth = qMax(st::minPhotoSize, _parent->minWidthForMedia());
auto maxWidth = qMax(tw, minWidth);
auto minHeight = qMax(th, st::minPhotoSize);
@ -118,7 +118,7 @@ QSize Location::countCurrentSize(int newWidth) {
} else {
newWidth = tw;
}
auto minWidth = qMax(st::minPhotoSize, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
auto minWidth = qMax(st::minPhotoSize, _parent->minWidthForMedia());
accumulate_max(newWidth, minWidth);
accumulate_max(newHeight, st::minPhotoSize);
if (_parent->hasBubble()) {

View file

@ -154,7 +154,9 @@ QSize Photo::countOptimalSize() {
if (_serviceWidth > 0) {
return { _serviceWidth, _serviceWidth };
}
const auto minWidth = qMax((_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
const auto minWidth = qMax(
(_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize),
_parent->minWidthForMedia());
const auto maxActualWidth = qMax(tw, minWidth);
maxWidth = qMax(maxActualWidth, th);
minHeight = qMax(th, st::minPhotoSize);
@ -194,7 +196,9 @@ QSize Photo::countCurrentSize(int newWidth) {
if (_pixw < 1) _pixw = 1;
if (_pixh < 1) _pixh = 1;
auto minWidth = qMax((_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
auto minWidth = qMax(
(_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize),
_parent->minWidthForMedia());
newWidth = qMax(_pixw, minWidth);
auto newHeight = qMax(_pixh, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {