Skip to content

Commit d71ea18

Browse files
authored
gui: fix scrolling for small content (#2491)
1 parent 5d0ca3a commit d71ea18

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arcade/gui/experimental/scroll_area.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def _thumb_rect(self):
108108
else scroll_area.surface.width - scroll_area.content_width
109109
)
110110

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+
111115
scroll_progress = -scroll_value / scroll_range
112116

113117
content_size = self.content_height if self.vertical else self.content_width
@@ -319,13 +323,17 @@ def on_event(self, event: UIEvent) -> Optional[bool]:
319323
# clip scrolling to canvas size
320324
if not self.overscroll_x:
321325
# 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
322328
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)
324330

325331
if not self.overscroll_y:
326332
# 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
327335
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)
329337

330338
return True
331339

0 commit comments

Comments
 (0)