fix: overflow when computing scrollbar rect (#6547)

Co-authored-by: Kasia <zneix@zneix.eu>
This commit is contained in:
nerix
2025-10-21 17:17:49 +02:00
committed by GitHub
parent 4be0e13883
commit 346327a0d4
3 changed files with 20 additions and 15 deletions
+1
View File
@@ -8,6 +8,7 @@
- Minor: Added link support to plugin message API. (#6386) - Minor: Added link support to plugin message API. (#6386)
- Minor: Added a description for the logging option under moderation tab. (#6514) - Minor: Added a description for the logging option under moderation tab. (#6514)
- Bugfix: Expose the "Extra extension IDs" setting on non-Windows systems too. (#6509) - Bugfix: Expose the "Extra extension IDs" setting on non-Windows systems too. (#6509)
- Bugfix: Fixed scrollbar rect cmputation potentially resulting in overflows. (#6547)
- Dev: Update release documentation. (#6498) - Dev: Update release documentation. (#6498)
- Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493) - Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493)
- Dev: Remove unused QTextCodec includes. (#6487) - Dev: Remove unused QTextCodec includes. (#6487)
+10 -9
View File
@@ -465,16 +465,17 @@ void Scrollbar::updateScroll()
{ {
this->trackHeight_ = this->height() - MIN_THUMB_HEIGHT - 1; this->trackHeight_ = this->height() - MIN_THUMB_HEIGHT - 1;
auto div = std::max<qreal>(0.0000001, this->maximum_ - this->minimum_); auto nMessages = std::max<qreal>(1.0, this->maximum_ - this->minimum_);
this->thumbRect_ = this->thumbRect_ = QRect{
QRect(0, 0,
static_cast<int>((this->getRelativeCurrentValue()) / div * static_cast<int>((this->getRelativeCurrentValue()) / nMessages *
this->trackHeight_) + this->trackHeight_) +
1, 1,
this->width(), this->width(),
static_cast<int>(this->pageSize_ / div * this->trackHeight_) + static_cast<int>(this->pageSize_ / nMessages * this->trackHeight_) +
MIN_THUMB_HEIGHT); MIN_THUMB_HEIGHT,
};
this->update(); this->update();
} }
+9 -6
View File
@@ -35,18 +35,21 @@ class ChannelView;
/// index is computed by `scrollbarPos - minimum` - thus a scrollbar position /// index is computed by `scrollbarPos - minimum` - thus a scrollbar position
/// of a message is at `index + minimum. /// of a message is at `index + minimum.
/// ///
/// @cond src-only
///
/// The following illustrates a scrollbar in a channel view with seven /// The following illustrates a scrollbar in a channel view with seven
/// messages. The scrollbar is at the bottom. No animation is active, thus /// messages. The scrollbar is at the bottom. No animation is active, thus
/// `currentValue = desiredValue`. /// `currentValue = desiredValue`.
/// ///
/// ```text
/// ┌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┐←╌╌╌ minimum /// ┌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┐←╌╌╌ minimum
/// Alice: This message is quite = 0 /// Bob: Ugh, I can't see this = 0
/// message, it's outside of my
/// ChannelView
/// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
/// Alice: Your message is quite
/// ┬ ╭─────────────────────────────────╮←╮ /// ┬ ╭─────────────────────────────────╮←╮
/// │ │ long, so it gets wrapped │ ┆ /// │ │ long, so it gets wrapped │ ┆
/// │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ ╰╌╌╌ currentValue /// │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ ╰╌╌╌ currentValue
/// │ │ Bob: are you sure? │ = 0.5 /// │ │ Bob: are you sure? │ = 1.5
/// │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ = desiredValue /// │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ = desiredValue
/// pageSize ╌╌╌┤ │ Alice: Works for me... try for │ = maximum /// pageSize ╌╌╌┤ │ Alice: Works for me... try for │ = maximum
/// = 6.5 │ │ yourself │ - pageSize /// = 6.5 │ │ yourself │ - pageSize
@@ -63,8 +66,8 @@ class ChannelView;
/// ┴╭→╰─────────────────────────────────╯ /// ┴╭→╰─────────────────────────────────╯
/// ┆ /// ┆
/// maximum /// maximum
/// = 7 /// = 8
/// @endcond /// ```
/// ///
/// When messages are added at the bottom, both maximum and minimum are offset /// When messages are added at the bottom, both maximum and minimum are offset
/// by 1 and after a layout, the desired value is updated, causing the content /// by 1 and after a layout, the desired value is updated, causing the content