From c2e0fd8efea3d69c904d081d84c7dde3beb27405 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 7 Jun 2025 12:54:53 +0200 Subject: [PATCH] fix: use integers for message layout bounds (#6254) --- CHANGELOG.md | 2 +- src/messages/layouts/MessageLayout.cpp | 28 +++++++++---------- src/messages/layouts/MessageLayout.hpp | 6 ++-- src/messages/layouts/MessageLayoutContext.hpp | 2 +- src/widgets/helper/ChannelView.cpp | 21 +++++++------- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 403eee2a..5eb1fbee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 when an image started loading mid app shutdown. (#6213) - 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: Conan will no longer generate a `CMakeUserPresets.json` file. (#6117) - Dev: Pass `--force-openssl` when installing from CMake in Qt 6.8+. (#6129) diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 031629e9..ad51b830 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -56,14 +56,14 @@ const MessagePtr &MessageLayout::getMessagePtr() const } // Height -qreal MessageLayout::getHeight() const +int MessageLayout::getHeight() const { - return this->container_.getHeight(); + return static_cast(this->container_.getHeight()); } -qreal MessageLayout::getWidth() const +int MessageLayout::getWidth() const { - return this->container_.getWidth(); + return static_cast(this->container_.getWidth()); } // Layout @@ -236,7 +236,7 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx) } // draw on buffer - ctx.painter.drawPixmap(QPointF{0, ctx.y}, *pixmap); + ctx.painter.drawPixmap(QPoint{0, ctx.y}, *pixmap); // draw gif emotes result.hasAnimatedElements = @@ -246,11 +246,11 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx) if (this->message_->flags.has(MessageFlag::Disabled)) { ctx.painter.fillRect( - QRectF{ + QRect{ 0, ctx.y, - static_cast(pixmap->width()), - static_cast(pixmap->height()), + pixmap->width(), + pixmap->height(), }, ctx.messageColors.disabled); } @@ -259,11 +259,11 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx) ctx.preferences.fadeMessageHistory) { ctx.painter.fillRect( - QRectF{ + QRect{ 0, ctx.y, - static_cast(pixmap->width()), - static_cast(pixmap->height()), + pixmap->width(), + pixmap->height(), }, ctx.messageColors.disabled); } @@ -274,11 +274,11 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx) ctx.preferences.enableRedeemedHighlight) { ctx.painter.fillRect( - QRectF{ + QRect{ 0, ctx.y, - this->scale_ * 4, - static_cast(pixmap->height()), + static_cast(this->scale_ * 4), + pixmap->height(), }, *ColorProvider::instance().color(ColorType::RedeemedHighlight)); } diff --git a/src/messages/layouts/MessageLayout.hpp b/src/messages/layouts/MessageLayout.hpp index 84637fda..45380d7a 100644 --- a/src/messages/layouts/MessageLayout.hpp +++ b/src/messages/layouts/MessageLayout.hpp @@ -52,8 +52,10 @@ public: const Message *getMessage(); const MessagePtr &getMessagePtr() const; - qreal getHeight() const; - qreal getWidth() const; + /// In contrast to other metrics, the height and width are integers because + /// this is how the backing pixmap is measured - it needs whole integers. + int getHeight() const; + int getWidth() const; MessageLayoutFlags flags; diff --git a/src/messages/layouts/MessageLayoutContext.hpp b/src/messages/layouts/MessageLayoutContext.hpp index ef610855..c8088f89 100644 --- a/src/messages/layouts/MessageLayoutContext.hpp +++ b/src/messages/layouts/MessageLayoutContext.hpp @@ -76,7 +76,7 @@ struct MessagePaintContext { const bool isMentions{}; // y coordinate we're currently painting at - qreal y{}; + int y{}; // Index of the message that is currently being painted // This index refers to the snapshot being used in the painting diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index e36fcd20..36534d90 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -764,7 +764,7 @@ void ChannelView::updateScrollbar( { this->scrollBar_->setPageSize( static_cast(messages.size() - i) + - (h / std::max(1.0, message->getHeight()))); + (h / std::max(1, message->getHeight()))); showScrollbar = true; break; @@ -1608,8 +1608,9 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area) .isMentions = this->underlyingChannel_ == getApp()->getTwitch()->getMentionsChannel(), - .y = -(messagesSnapshot[start]->getHeight() * - (fmod(this->scrollBar_->getRelativeCurrentValue(), 1))), + .y = -static_cast( + messagesSnapshot[start]->getHeight() * + (fmod(this->scrollBar_->getRelativeCurrentValue(), 1))), .messageIndex = start, .isLastReadMessage = false, @@ -1646,25 +1647,23 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area) { animationArea = QRect{ 0, - static_cast(ctx.y), - static_cast(layout->getWidth()), - static_cast(layout->getHeight()), + ctx.y, + layout->getWidth(), + layout->getHeight(), }; } else { - animationArea.setBottom( - static_cast(ctx.y + layout->getHeight())); + animationArea.setBottom((ctx.y + layout->getHeight())); animationArea.setWidth( - std::max(static_cast(layout->getWidth()), - animationArea.width())); + std::max(layout->getWidth(), animationArea.width())); } } if (this->highlightedMessage_ == layout) { painter.fillRect( - QRectF{ + QRect{ 0, ctx.y, layout->getWidth(),