mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix webpage layout with ViewButton.
This commit is contained in:
parent
27a9b61f72
commit
8b4a95826c
2 changed files with 40 additions and 37 deletions
|
@ -312,18 +312,11 @@ QSize Message::performCountOptimalSize() {
|
||||||
auto maxWidth = 0;
|
auto maxWidth = 0;
|
||||||
auto minHeight = 0;
|
auto minHeight = 0;
|
||||||
|
|
||||||
|
updateViewButtonExistence();
|
||||||
updateMediaInBubbleState();
|
updateMediaInBubbleState();
|
||||||
refreshEditedBadge();
|
refreshEditedBadge();
|
||||||
refreshRightBadge();
|
refreshRightBadge();
|
||||||
|
|
||||||
auto mediaOnBottom = (logEntryOriginal() != nullptr)
|
|
||||||
|| (media && media->isDisplayed() && media->isBubbleBottom());
|
|
||||||
if (mediaOnBottom) {
|
|
||||||
// remove skip
|
|
||||||
} else {
|
|
||||||
// add skip
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drawBubble()) {
|
if (drawBubble()) {
|
||||||
const auto forwarded = item->Get<HistoryMessageForwarded>();
|
const auto forwarded = item->Get<HistoryMessageForwarded>();
|
||||||
const auto reply = displayedReply();
|
const auto reply = displayedReply();
|
||||||
|
@ -349,7 +342,7 @@ QSize Message::performCountOptimalSize() {
|
||||||
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
|
||||||
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
|
||||||
|
|
||||||
if (mediaOnBottom) {
|
if (mediaOnBottom || (mediaDisplayed && _viewButton)) {
|
||||||
if (item->_text.removeSkipBlock()) {
|
if (item->_text.removeSkipBlock()) {
|
||||||
item->_textWidth = -1;
|
item->_textWidth = -1;
|
||||||
item->_textHeight = 0;
|
item->_textHeight = 0;
|
||||||
|
@ -531,6 +524,9 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
||||||
if (data()->repliesAreComments() || data()->externalReply()) {
|
if (data()->repliesAreComments() || data()->externalReply()) {
|
||||||
localMediaBottom -= st::historyCommentsButtonHeight;
|
localMediaBottom -= st::historyCommentsButtonHeight;
|
||||||
}
|
}
|
||||||
|
if (_viewButton) {
|
||||||
|
localMediaBottom -= st::mediaInBubbleSkip + _viewButton->height();
|
||||||
|
}
|
||||||
if (!mediaOnBottom) {
|
if (!mediaOnBottom) {
|
||||||
localMediaBottom -= st::msgPadding.bottom();
|
localMediaBottom -= st::msgPadding.bottom();
|
||||||
}
|
}
|
||||||
|
@ -605,18 +601,25 @@ void Message::draw(Painter &p, const PaintContext &context) const {
|
||||||
|
|
||||||
auto inner = g;
|
auto inner = g;
|
||||||
paintCommentsButton(p, inner, context);
|
paintCommentsButton(p, inner, context);
|
||||||
if (ensureViewButton()) {
|
|
||||||
|
auto trect = inner.marginsRemoved(st::msgPadding);
|
||||||
|
if (_viewButton) {
|
||||||
_viewButton->draw(
|
_viewButton->draw(
|
||||||
p,
|
p,
|
||||||
_viewButton->countRect(inner),
|
_viewButton->countRect(inner),
|
||||||
context);
|
context);
|
||||||
|
// Inner should contain _viewButton height, because info is
|
||||||
|
// painted below the _viewButton.
|
||||||
|
//
|
||||||
|
// inner.setHeight(inner.height() - _viewButton->height());
|
||||||
|
trect.setHeight(trect.height() - _viewButton->height());
|
||||||
|
if (mediaDisplayed) {
|
||||||
|
trect.setHeight(trect.height() - st::mediaInBubbleSkip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto trect = inner.marginsRemoved(st::msgPadding);
|
|
||||||
if (mediaOnBottom) {
|
if (mediaOnBottom) {
|
||||||
trect.setHeight(trect.height()
|
trect.setHeight(trect.height() + st::msgPadding.bottom());
|
||||||
+ st::msgPadding.bottom()
|
|
||||||
- viewButtonHeight());
|
|
||||||
}
|
}
|
||||||
if (mediaOnTop) {
|
if (mediaOnTop) {
|
||||||
trect.setY(trect.y() - st::msgPadding.top());
|
trect.setY(trect.y() - st::msgPadding.top());
|
||||||
|
@ -1960,27 +1963,29 @@ int Message::viewButtonHeight() const {
|
||||||
return _viewButton ? _viewButton->height() : 0;
|
return _viewButton ? _viewButton->height() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Message::ensureViewButton() const {
|
void Message::updateViewButtonExistence() {
|
||||||
if (data()->isSponsored()
|
const auto has = [&] {
|
||||||
|| (data()->media()
|
const auto item = data();
|
||||||
&& ViewButton::MediaHasViewButton(data()->media()))) {
|
if (item->isSponsored()) {
|
||||||
if (_viewButton) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto callback = [=] { history()->owner().requestViewRepaint(this); };
|
const auto media = item->media();
|
||||||
_viewButton = data()->isSponsored()
|
return media && ViewButton::MediaHasViewButton(media);
|
||||||
? std::make_unique<ViewButton>(
|
}();
|
||||||
data()->displayFrom(),
|
if (!has) {
|
||||||
std::move(callback))
|
_viewButton = nullptr;
|
||||||
: std::make_unique<ViewButton>(
|
return;
|
||||||
data()->media(),
|
} else if (_viewButton) {
|
||||||
std::move(callback));
|
return;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (_viewButton) {
|
auto callback = [=] { history()->owner().requestViewRepaint(this); };
|
||||||
_viewButton.reset(nullptr);
|
_viewButton = data()->isSponsored()
|
||||||
}
|
? std::make_unique<ViewButton>(
|
||||||
return false;
|
data()->displayFrom(),
|
||||||
|
std::move(callback))
|
||||||
|
: std::make_unique<ViewButton>(
|
||||||
|
data()->media(),
|
||||||
|
std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Message::initLogEntryOriginal() {
|
void Message::initLogEntryOriginal() {
|
||||||
|
@ -2384,7 +2389,7 @@ void Message::updateMediaInBubbleState() {
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
const auto media = this->media();
|
const auto media = this->media();
|
||||||
|
|
||||||
auto mediaHasSomethingBelow = false;
|
auto mediaHasSomethingBelow = (_viewButton != nullptr);
|
||||||
auto mediaHasSomethingAbove = false;
|
auto mediaHasSomethingAbove = false;
|
||||||
auto getMediaHasSomethingAbove = [&] {
|
auto getMediaHasSomethingAbove = [&] {
|
||||||
return displayFromName()
|
return displayFromName()
|
||||||
|
@ -2643,9 +2648,7 @@ int Message::resizeContentGetHeight(int newWidth) {
|
||||||
if (item->repliesAreComments() || item->externalReply()) {
|
if (item->repliesAreComments() || item->externalReply()) {
|
||||||
newHeight += st::historyCommentsButtonHeight;
|
newHeight += st::historyCommentsButtonHeight;
|
||||||
}
|
}
|
||||||
if (ensureViewButton()) {
|
newHeight += viewButtonHeight();
|
||||||
newHeight += viewButtonHeight();
|
|
||||||
}
|
|
||||||
} else if (mediaDisplayed) {
|
} else if (mediaDisplayed) {
|
||||||
newHeight = media->height();
|
newHeight = media->height();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -213,7 +213,7 @@ private:
|
||||||
[[nodiscard]] int plainMaxWidth() const;
|
[[nodiscard]] int plainMaxWidth() const;
|
||||||
[[nodiscard]] int monospaceMaxWidth() const;
|
[[nodiscard]] int monospaceMaxWidth() const;
|
||||||
|
|
||||||
[[nodiscard]] bool ensureViewButton() const;
|
[[nodiscard]] void updateViewButtonExistence();
|
||||||
[[nodiscard]] int viewButtonHeight() const;
|
[[nodiscard]] int viewButtonHeight() const;
|
||||||
|
|
||||||
WebPage *logEntryOriginal() const;
|
WebPage *logEntryOriginal() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue