fix: use integers for message layout bounds (#6254)

This commit is contained in:
nerix
2025-06-07 12:54:53 +02:00
committed by GitHub
parent 37a752a231
commit c2e0fd8efe
5 changed files with 30 additions and 29 deletions
+1 -1
View File
@@ -34,7 +34,7 @@
- Bugfix: Fixed a crash that could occur an eventsub connection's keepalive timer would run after the connection was dead, causing the keepalive timer to use-itself-after-free. (#6204) - Bugfix: Fixed a crash that could occur an eventsub connection's keepalive timer would run after the connection was dead, causing the keepalive timer to use-itself-after-free. (#6204)
- Bugfix: Fixed a crash that could occur when an image started loading mid app shutdown. (#6213) - Bugfix: Fixed a crash that could occur when an image started loading mid app shutdown. (#6213)
- Bugfix: Fixed some minor typos. (#6196) - Bugfix: Fixed some minor typos. (#6196)
- Bugfix: Fixed inconsistent spaces in messages when using fractional scaling. (#6231) - Bugfix: Fixed inconsistent spaces in messages when using fractional scaling. (#6231, #6254)
- Dev: Mini refactor of Split. (#6148) - Dev: Mini refactor of Split. (#6148)
- Dev: Conan will no longer generate a `CMakeUserPresets.json` file. (#6117) - Dev: Conan will no longer generate a `CMakeUserPresets.json` file. (#6117)
- Dev: Pass `--force-openssl` when installing from CMake in Qt 6.8+. (#6129) - Dev: Pass `--force-openssl` when installing from CMake in Qt 6.8+. (#6129)
+14 -14
View File
@@ -56,14 +56,14 @@ const MessagePtr &MessageLayout::getMessagePtr() const
} }
// Height // Height
qreal MessageLayout::getHeight() const int MessageLayout::getHeight() const
{ {
return this->container_.getHeight(); return static_cast<int>(this->container_.getHeight());
} }
qreal MessageLayout::getWidth() const int MessageLayout::getWidth() const
{ {
return this->container_.getWidth(); return static_cast<int>(this->container_.getWidth());
} }
// Layout // Layout
@@ -236,7 +236,7 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
} }
// draw on buffer // draw on buffer
ctx.painter.drawPixmap(QPointF{0, ctx.y}, *pixmap); ctx.painter.drawPixmap(QPoint{0, ctx.y}, *pixmap);
// draw gif emotes // draw gif emotes
result.hasAnimatedElements = result.hasAnimatedElements =
@@ -246,11 +246,11 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
if (this->message_->flags.has(MessageFlag::Disabled)) if (this->message_->flags.has(MessageFlag::Disabled))
{ {
ctx.painter.fillRect( ctx.painter.fillRect(
QRectF{ QRect{
0, 0,
ctx.y, ctx.y,
static_cast<qreal>(pixmap->width()), pixmap->width(),
static_cast<qreal>(pixmap->height()), pixmap->height(),
}, },
ctx.messageColors.disabled); ctx.messageColors.disabled);
} }
@@ -259,11 +259,11 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
ctx.preferences.fadeMessageHistory) ctx.preferences.fadeMessageHistory)
{ {
ctx.painter.fillRect( ctx.painter.fillRect(
QRectF{ QRect{
0, 0,
ctx.y, ctx.y,
static_cast<qreal>(pixmap->width()), pixmap->width(),
static_cast<qreal>(pixmap->height()), pixmap->height(),
}, },
ctx.messageColors.disabled); ctx.messageColors.disabled);
} }
@@ -274,11 +274,11 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
ctx.preferences.enableRedeemedHighlight) ctx.preferences.enableRedeemedHighlight)
{ {
ctx.painter.fillRect( ctx.painter.fillRect(
QRectF{ QRect{
0, 0,
ctx.y, ctx.y,
this->scale_ * 4, static_cast<int>(this->scale_ * 4),
static_cast<qreal>(pixmap->height()), pixmap->height(),
}, },
*ColorProvider::instance().color(ColorType::RedeemedHighlight)); *ColorProvider::instance().color(ColorType::RedeemedHighlight));
} }
+4 -2
View File
@@ -52,8 +52,10 @@ public:
const Message *getMessage(); const Message *getMessage();
const MessagePtr &getMessagePtr() const; const MessagePtr &getMessagePtr() const;
qreal getHeight() const; /// In contrast to other metrics, the height and width are integers because
qreal getWidth() const; /// this is how the backing pixmap is measured - it needs whole integers.
int getHeight() const;
int getWidth() const;
MessageLayoutFlags flags; MessageLayoutFlags flags;
@@ -76,7 +76,7 @@ struct MessagePaintContext {
const bool isMentions{}; const bool isMentions{};
// y coordinate we're currently painting at // y coordinate we're currently painting at
qreal y{}; int y{};
// Index of the message that is currently being painted // Index of the message that is currently being painted
// This index refers to the snapshot being used in the painting // This index refers to the snapshot being used in the painting
+10 -11
View File
@@ -764,7 +764,7 @@ void ChannelView::updateScrollbar(
{ {
this->scrollBar_->setPageSize( this->scrollBar_->setPageSize(
static_cast<qreal>(messages.size() - i) + static_cast<qreal>(messages.size() - i) +
(h / std::max(1.0, message->getHeight()))); (h / std::max(1, message->getHeight())));
showScrollbar = true; showScrollbar = true;
break; break;
@@ -1608,8 +1608,9 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area)
.isMentions = this->underlyingChannel_ == .isMentions = this->underlyingChannel_ ==
getApp()->getTwitch()->getMentionsChannel(), getApp()->getTwitch()->getMentionsChannel(),
.y = -(messagesSnapshot[start]->getHeight() * .y = -static_cast<int>(
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1))), messagesSnapshot[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1))),
.messageIndex = start, .messageIndex = start,
.isLastReadMessage = false, .isLastReadMessage = false,
@@ -1646,25 +1647,23 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area)
{ {
animationArea = QRect{ animationArea = QRect{
0, 0,
static_cast<int>(ctx.y), ctx.y,
static_cast<int>(layout->getWidth()), layout->getWidth(),
static_cast<int>(layout->getHeight()), layout->getHeight(),
}; };
} }
else else
{ {
animationArea.setBottom( animationArea.setBottom((ctx.y + layout->getHeight()));
static_cast<int>(ctx.y + layout->getHeight()));
animationArea.setWidth( animationArea.setWidth(
std::max(static_cast<int>(layout->getWidth()), std::max(layout->getWidth(), animationArea.width()));
animationArea.width()));
} }
} }
if (this->highlightedMessage_ == layout) if (this->highlightedMessage_ == layout)
{ {
painter.fillRect( painter.fillRect(
QRectF{ QRect{
0, 0,
ctx.y, ctx.y,
layout->getWidth(), layout->getWidth(),