@@ -108,6 +108,10 @@ def _thumb_rect(self):
108
108
else scroll_area .surface .width - scroll_area .content_width
109
109
)
110
110
111
+ if scroll_range <= 0 :
112
+ # content is smaller than the scroll area, no need for a thumb
113
+ return XYWH (0 , 0 , 0 , 0 )
114
+
111
115
scroll_progress = - scroll_value / scroll_range
112
116
113
117
content_size = self .content_height if self .vertical else self .content_width
@@ -319,13 +323,17 @@ def on_event(self, event: UIEvent) -> Optional[bool]:
319
323
# clip scrolling to canvas size
320
324
if not self .overscroll_x :
321
325
# clip scroll_x between 0 and -(self.surface.width - self.width)
326
+ scroll_range = int (self .content_width - self .surface .width )
327
+ scroll_range = min (0 , scroll_range ) # clip to 0 if content is smaller than surface
322
328
self .scroll_x = min (0 , self .scroll_x )
323
- self .scroll_x = max (self .scroll_x , - int ( self . surface . width - self . content_width ) )
329
+ self .scroll_x = max (self .scroll_x , scroll_range )
324
330
325
331
if not self .overscroll_y :
326
332
# clip scroll_y between 0 and -(self.surface.height - self.height)
333
+ scroll_range = int (self .content_height - self .surface .height )
334
+ scroll_range = min (0 , scroll_range ) # clip to 0 if content is smaller than surface
327
335
self .scroll_y = min (0 , self .scroll_y )
328
- self .scroll_y = max (self .scroll_y , - int ( self . surface . height - self . content_height ) )
336
+ self .scroll_y = max (self .scroll_y , scroll_range )
329
337
330
338
return True
331
339
0 commit comments