From 9a0be43ef565841ee352c75e024e32ce74ec30fa Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Jan 2022 20:00:18 +0300 Subject: [PATCH] Align reactions outside of the bubble. --- .../SourceFiles/dialogs/dialogs_widget.cpp | 1 + .../SourceFiles/history/history_widget.cpp | 28 +++++++++++-------- .../history/view/history_view_message.cpp | 3 ++ .../history/view/history_view_reactions.cpp | 17 +++++++---- .../history/view/history_view_reactions.h | 1 + .../history/view/media/history_view_gif.cpp | 27 ++++++++++++------ .../media/history_view_media_unwrapped.cpp | 4 +-- 7 files changed, 54 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 74ccca11e..8535fad4d 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -593,6 +593,7 @@ void Widget::checkUpdateStatus() { Core::checkReadyUpdate(); App::restart(); }); + _connecting->raise(); } else { if (!_updateTelegram) return; _updateTelegram.destroy(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index f3d85ffff..ed9273eab 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -479,18 +479,6 @@ HistoryWidget::HistoryWidget( Window::ActivateWindow(controller); }); - controller->adaptive().changes( - ) | rpl::start_with_next([=] { - if (_history) { - _history->forceFullResize(); - if (_migrated) { - _migrated->forceFullResize(); - } - updateHistoryGeometry(); - update(); - } - }, lifetime()); - session().data().newItemAdded( ) | rpl::start_with_next([=](not_null item) { newItemAdded(item); @@ -2151,6 +2139,16 @@ void HistoryWidget::showHistory( object_ptr(this, _scroll, controller(), _history)); _list->show(); + controller()->adaptive().changes( + ) | rpl::start_with_next([=] { + _history->forceFullResize(); + if (_migrated) { + _migrated->forceFullResize(); + } + updateHistoryGeometry(); + update(); + }, _list->lifetime()); + if (_chooseForReport && _chooseForReport->active) { _list->setChooseReportReason(_chooseForReport->reason); } @@ -2243,6 +2241,12 @@ void HistoryWidget::setHistory(History *history) { return; } unregisterDraftSources(); + if (_history) { + _history->forceFullResize(); + } + if (_migrated) { + _migrated->forceFullResize(); + } _history = history; _migrated = _history ? _history->migrateFrom() : nullptr; registerDraftSource(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 3ed7fd0ed..11f26416b 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -2798,6 +2798,9 @@ int Message::resizeContentGetHeight(int newWidth) { : contentWidth; newHeight += st::mediaInBubbleSkip + _reactions->resizeGetHeight(reactionsWidth); + if (hasOutLayout() && !delegate()->elementIsChatWide()) { + _reactions->flipToRight(); + } } if (const auto keyboard = item->inlineReplyKeyboard()) { diff --git a/Telegram/SourceFiles/history/view/history_view_reactions.cpp b/Telegram/SourceFiles/history/view/history_view_reactions.cpp index e82712c0a..7723f36d4 100644 --- a/Telegram/SourceFiles/history/view/history_view_reactions.cpp +++ b/Telegram/SourceFiles/history/view/history_view_reactions.cpp @@ -127,7 +127,7 @@ QSize InlineList::countOptimalSize() { const auto height = padding.top() + size + padding.bottom(); for (auto &button : _buttons) { const auto width = widthBase + button.countTextWidth; - button.geometry = QRect(x, 0, width, height); + button.geometry.setSize({ width, height }); x += width + between; } return QSize( @@ -136,13 +136,13 @@ QSize InlineList::countOptimalSize() { } QSize InlineList::countCurrentSize(int newWidth) { - if (newWidth >= maxWidth() || _buttons.empty()) { + if (_buttons.empty()) { return optimalSize(); } + using Flag = InlineListData::Flag; const auto between = st::reactionBottomBetween; - const auto left = (_data.flags & InlineListData::Flag::InBubble) - ? st::reactionBottomInBubbleLeft - : 0; + const auto inBubble = (_data.flags & Flag::InBubble); + const auto left = inBubble ? st::reactionBottomInBubbleLeft : 0; auto x = left; auto y = 0; for (auto &button : _buttons) { @@ -161,6 +161,13 @@ QSize InlineList::countCurrentSize(int newWidth) { return { newWidth, height + add }; } +void InlineList::flipToRight() { + for (auto &button : _buttons) { + button.geometry.moveLeft( + width() - button.geometry.x() - button.geometry.width()); + } +} + int InlineList::placeAndResizeGetHeight(QRect available) { const auto result = resizeGetHeight(available.width()); for (auto &button : _buttons) { diff --git a/Telegram/SourceFiles/history/view/history_view_reactions.h b/Telegram/SourceFiles/history/view/history_view_reactions.h index ef9c2b60c..63d034212 100644 --- a/Telegram/SourceFiles/history/view/history_view_reactions.h +++ b/Telegram/SourceFiles/history/view/history_view_reactions.h @@ -49,6 +49,7 @@ public: void update(Data &&data, int availableWidth); QSize countCurrentSize(int newWidth) override; [[nodiscard]] int placeAndResizeGetHeight(QRect available); + void flipToRight(); void updateSkipBlock(int width, int height); void removeSkipBlock(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 454842d4b..d40ee5852 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -360,9 +360,12 @@ void Gif::draw(Painter &p, const PaintContext &context) const { auto via = separateRoundVideo ? item->Get() : nullptr; auto reply = separateRoundVideo ? _parent->displayedReply() : nullptr; auto forwarded = separateRoundVideo ? item->Get() : nullptr; + const auto rightAligned = separateRoundVideo + && outbg + && !_parent->delegate()->elementIsChatWide(); if (via || reply || forwarded) { usew = maxWidth() - additionalWidth(via, reply, forwarded); - if (outbg) { + if (rightAligned) { usex = width() - usew; } } @@ -588,7 +591,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const { if (reply) { recth += st::msgReplyBarSize.height(); } - int rectx = outbg ? 0 : (usew + st::msgReplyPadding.left()); + int rectx = rightAligned ? 0 : (usew + st::msgReplyPadding.left()); int recty = painty; if (rtl()) rectx = width() - rectx - rectw; @@ -624,7 +627,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const { } else { maxRight -= st::msgMargin.left(); } - if (isRound && !outbg) { + if (isRound && !rightAligned) { auto infoWidth = _parent->infoWidth(); // This is just some arbitrary point, @@ -766,9 +769,12 @@ TextState Gif::textState(QPoint point, StateRequest request) const { auto via = separateRoundVideo ? item->Get() : nullptr; auto reply = separateRoundVideo ? _parent->displayedReply() : nullptr; auto forwarded = separateRoundVideo ? item->Get() : nullptr; + const auto rightAligned = separateRoundVideo + && outbg + && !_parent->delegate()->elementIsChatWide(); if (via || reply || forwarded) { usew = maxWidth() - additionalWidth(via, reply, forwarded); - if (outbg) { + if (rightAligned) { usex = width() - usew; } } @@ -788,7 +794,7 @@ TextState Gif::textState(QPoint point, StateRequest request) const { if (reply) { recth += st::msgReplyBarSize.height(); } - auto rectx = outbg ? 0 : (usew + st::msgReplyPadding.left()); + auto rectx = rightAligned ? 0 : (usew + st::msgReplyPadding.left()); auto recty = painty; if (rtl()) rectx = width() - rectx - rectw; @@ -857,7 +863,7 @@ TextState Gif::textState(QPoint point, StateRequest request) const { } else { maxRight -= st::msgMargin.left(); } - if (isRound && !outbg) { + if (isRound && !rightAligned) { auto infoWidth = _parent->infoWidth(); // This is just some arbitrary point, @@ -1177,13 +1183,15 @@ QRect Gif::contentRectForReactions() const { auto paintx = 0, painty = 0, paintw = width(), painth = height(); auto usex = 0, usew = paintw; const auto outbg = _parent->hasOutLayout(); + const auto rightAligned = outbg + && !_parent->delegate()->elementIsChatWide(); const auto item = _parent->data(); const auto via = item->Get(); const auto reply = _parent->displayedReply(); const auto forwarded = item->Get(); if (via || reply || forwarded) { usew = maxWidth() - additionalWidth(via, reply, forwarded); - if (outbg) { + if (rightAligned) { usex = width() - usew; } } @@ -1204,7 +1212,10 @@ std::optional Gif::reactionButtonCenterOverride() const { maxRight -= st::msgMargin.left(); } const auto infoWidth = _parent->infoWidth(); - if (!_parent->hasOutLayout()) { + const auto outbg = _parent->hasOutLayout(); + const auto rightAligned = outbg + && !_parent->delegate()->elementIsChatWide(); + if (!rightAligned) { // This is just some arbitrary point, // the main idea is to make info left aligned here. fullRight += infoWidth - st::normalFont->height; diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index 479a12c02..51a6dd431 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -112,7 +112,7 @@ void UnwrappedMedia::draw(Painter &p, const PaintContext &context) const { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { return; } - const auto rightAligned = _parent->hasOutLayout() + const auto rightAligned = context.outbg && !_parent->delegate()->elementIsChatWide(); const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); @@ -183,7 +183,7 @@ void UnwrappedMedia::drawSurrounding( const HistoryMessageForwarded *forwarded) const { const auto st = context.st; const auto sti = context.imageStyle(); - const auto rightAligned = _parent->hasOutLayout() + const auto rightAligned = context.outbg && !_parent->delegate()->elementIsChatWide(); const auto rightActionSize = _parent->rightActionSize(); const auto fullRight = calculateFullRight(inner);