Align reactions outside of the bubble.

This commit is contained in:
John Preston 2022-01-03 20:00:18 +03:00
parent c1d948ef63
commit 9a0be43ef5
7 changed files with 54 additions and 27 deletions

View file

@ -593,6 +593,7 @@ void Widget::checkUpdateStatus() {
Core::checkReadyUpdate();
App::restart();
});
_connecting->raise();
} else {
if (!_updateTelegram) return;
_updateTelegram.destroy();

View file

@ -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<HistoryItem*> item) {
newItemAdded(item);
@ -2151,6 +2139,16 @@ void HistoryWidget::showHistory(
object_ptr<HistoryInner>(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();

View file

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

View file

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

View file

@ -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();

View file

@ -360,9 +360,12 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
auto via = separateRoundVideo ? item->Get<HistoryMessageVia>() : nullptr;
auto reply = separateRoundVideo ? _parent->displayedReply() : nullptr;
auto forwarded = separateRoundVideo ? item->Get<HistoryMessageForwarded>() : 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<HistoryMessageVia>() : nullptr;
auto reply = separateRoundVideo ? _parent->displayedReply() : nullptr;
auto forwarded = separateRoundVideo ? item->Get<HistoryMessageForwarded>() : 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<HistoryMessageVia>();
const auto reply = _parent->displayedReply();
const auto forwarded = item->Get<HistoryMessageForwarded>();
if (via || reply || forwarded) {
usew = maxWidth() - additionalWidth(via, reply, forwarded);
if (outbg) {
if (rightAligned) {
usex = width() - usew;
}
}
@ -1204,7 +1212,10 @@ std::optional<int> 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;

View file

@ -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);