mirror of
https://github.com/Chatterino/chatterino2.git
synced 2026-08-24 10:04:53 -05:00
fix: Update pined message height if viewport resized (#7114)
If the split is not 100dp wide, the calculated message height can be wrong. If the split is larger than 100dp and the message would wrap at that size, the widget would be too tall. And vice versa for splits smaller than 100dp. We do calculate the height in our resize event, but we use the size of our children. Their resize events are delivered after we're resized. So we check if we need to resize after we show the widget. This does result in a small flash where the content is sized incorrectly, but better than it being incorrect the entire time. Parent-pr: 7014 Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -319,6 +319,7 @@ void PinnedMessageWidget::refresh()
|
||||
this->menuButton_->setVisible(isMod);
|
||||
|
||||
this->show();
|
||||
this->updateMessageHeightIfNeeded();
|
||||
|
||||
this->autoHideTimer_->stop();
|
||||
if (!getSettings()->alwaysShowPinnedMessage && !this->userToggled_)
|
||||
@@ -340,6 +341,7 @@ void PinnedMessageWidget::toggleUserPinned()
|
||||
this->userToggled_ = true;
|
||||
this->autoHideTimer_->stop();
|
||||
this->show();
|
||||
this->updateMessageHeightIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,8 +353,9 @@ void PinnedMessageWidget::updateMessageHeight()
|
||||
}
|
||||
|
||||
// Wrapped height of the label at the current viewport width.
|
||||
const int width = this->messageScrollArea_->viewport()->width();
|
||||
int contentH = this->messageLabel_->heightForWidth(width);
|
||||
this->lastViewportWidth_ = this->messageScrollArea_->viewport()->width();
|
||||
int contentH =
|
||||
this->messageLabel_->heightForWidth(this->lastViewportWidth_);
|
||||
if (contentH <= 0)
|
||||
{
|
||||
contentH = this->messageLabel_->sizeHint().height();
|
||||
@@ -363,6 +366,15 @@ void PinnedMessageWidget::updateMessageHeight()
|
||||
qBound(1, contentH, this->messageMaxHeight_));
|
||||
}
|
||||
|
||||
void PinnedMessageWidget::updateMessageHeightIfNeeded()
|
||||
{
|
||||
if (this->lastViewportWidth_ !=
|
||||
this->messageScrollArea_->viewport()->width())
|
||||
{
|
||||
this->updateMessageHeight();
|
||||
}
|
||||
}
|
||||
|
||||
void PinnedMessageWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
BaseWidget::resizeEvent(event);
|
||||
|
||||
@@ -58,6 +58,12 @@ private:
|
||||
/// (scaled) maximum height. A vertical scrollbar appears past the cap.
|
||||
void updateMessageHeight();
|
||||
|
||||
/// If the scroll viewport width has changed since the last time
|
||||
/// updateMessageHeight() was called, update the height again, because
|
||||
/// resize events for children are delivered after resize events for
|
||||
/// ourselves when showing the widget.
|
||||
void updateMessageHeightIfNeeded();
|
||||
|
||||
TwitchChannel *channel_ = nullptr;
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
|
||||
@@ -80,6 +86,8 @@ private:
|
||||
bool userToggled_ = false;
|
||||
/// Invalid when no end time.
|
||||
QDateTime pinEndsAt_;
|
||||
|
||||
int lastViewportWidth_ = -1;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user