From e2bca0a7ff01a66ecc14e4903409750ba9325b8d Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 12 Sep 2022 09:35:28 +0400 Subject: [PATCH] Fix media with caption in a narrow window. --- .../history/view/media/history_view_extended_preview.cpp | 5 +++-- Telegram/SourceFiles/history/view/media/history_view_gif.cpp | 2 +- .../SourceFiles/history/view/media/history_view_photo.cpp | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp index 1994c5b54..b0bdac7bf 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp @@ -123,12 +123,13 @@ QSize ExtendedPreview::countOptimalSize() { QSize ExtendedPreview::countCurrentSize(int newWidth) { const auto &preview = _invoice->extendedPreview; const auto dimensions = preview.dimensions; + const auto thumbMaxWidth = std::min(newWidth, st::maxMediaSize); const auto minWidth = std::clamp( _parent->minWidthForMedia(), (_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), - std::min(newWidth, st::maxMediaSize)); + thumbMaxWidth); const auto scaled = (preview.videoDuration >= 0) ? CountMediaSize( CountDesiredMediaSize(dimensions), @@ -145,7 +146,7 @@ QSize ExtendedPreview::countCurrentSize(int newWidth) { (st::msgPadding.left() + _caption.maxWidth() + st::msgPadding.right())); - newWidth = qMax(newWidth, maxWithCaption); + newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth); const auto captionw = newWidth - st::msgPadding.left() - st::msgPadding.right(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index cf423498f..151d3825d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -207,7 +207,7 @@ QSize Gif::countCurrentSize(int newWidth) { (st::msgPadding.left() + _caption.maxWidth() + st::msgPadding.right())); - newWidth = qMax(newWidth, maxWithCaption); + newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth); const auto captionw = newWidth - st::msgPadding.left() - st::msgPadding.right(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 8f2259851..0d2eee4bf 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -176,10 +176,11 @@ QSize Photo::countCurrentSize(int newWidth) { if (_serviceWidth) { return { _serviceWidth, _serviceWidth }; } + const auto thumbMaxWidth = qMin(newWidth, st::maxMediaSize); const auto minWidth = std::clamp( _parent->minWidthForMedia(), (_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), - std::min(newWidth, st::maxMediaSize)); + thumbMaxWidth); auto pix = CountPhotoMediaSize( CountDesiredMediaSize({ _data->width(), _data->height() }), newWidth, @@ -192,7 +193,7 @@ QSize Photo::countCurrentSize(int newWidth) { (st::msgPadding.left() + _caption.maxWidth() + st::msgPadding.right())); - newWidth = qMax(newWidth, maxWithCaption); + newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth); const auto captionw = newWidth - st::msgPadding.left() - st::msgPadding.right();