git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

commit40a086458ad7928984ca360d449020525b73e483
parent31bf093f88
authorLucas Galante <[email protected]>
date2026-06-19 15:53
Robust scrollbar thumb height calculation to prevent clamp panics

 src/widget/container/scroll_box.rs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/widget/container/scroll_box.rs b/src/widget/container/scroll_box.rs
index a72106e..6636325 100644
--- a/src/widget/container/scroll_box.rs
+++ b/src/widget/container/scroll_box.rs
@@ -141,7 +141,11 @@ impl Element for ScrollBox {
 
             // Thumb
             let visible_ratio = self.viewport_h / self.content_h;
-            let thumb_h = (sb_track_h * visible_ratio).clamp(20.0, sb_track_h);
+            let thumb_h = if sb_track_h <= 20.0 {
+                sb_track_h
+            } else {
+                (sb_track_h * visible_ratio).clamp(20.0, sb_track_h)
+            };
             let max_scroll = (self.content_h - self.viewport_h).max(0.0);
             let scroll_ratio = if max_scroll > 0.0 { self.scroll_y / max_scroll } else { 0.0 };
             let thumb_y = sb_track_y + scroll_ratio * (sb_track_h - thumb_h);