Fix infinite scroll when content doesn't fill viewport

Detect when scrollbar max is 0 (no scroll needed) and auto-load
more posts. Checks after initial search and after each drain.
This commit is contained in:
pax 2026-04-05 17:35:01 -05:00
parent 21980fdbc7
commit ce92e6d57f

View File

@ -822,6 +822,18 @@ class BooruApp(QMainWindow):
if self._db.get_setting_bool("prefetch_adjacent") and posts: if self._db.get_setting_bool("prefetch_adjacent") and posts:
self._prefetch_adjacent(0) self._prefetch_adjacent(0)
# Infinite scroll: if first page doesn't fill viewport, load more
if self._infinite_scroll and posts:
QTimer.singleShot(200, self._check_viewport_fill)
def _check_viewport_fill(self) -> None:
"""If content doesn't fill the viewport, trigger infinite scroll."""
if not self._infinite_scroll or self._loading or getattr(self, '_infinite_exhausted', False):
return
sb = self._grid.verticalScrollBar()
if sb.maximum() == 0:
self._on_reached_bottom()
def _on_search_append(self, posts: list) -> None: def _on_search_append(self, posts: list) -> None:
"""Queue posts and add them one at a time as thumbnails arrive.""" """Queue posts and add them one at a time as thumbnails arrive."""
if not posts: if not posts:
@ -875,10 +887,11 @@ class BooruApp(QMainWindow):
self._loading = False self._loading = False
if self._db.get_setting_bool("prefetch_adjacent"): if self._db.get_setting_bool("prefetch_adjacent"):
self._prefetch_adjacent(idx) self._prefetch_adjacent(idx)
# Check if still at bottom — trigger next load # Check if still at bottom or content doesn't fill viewport
sb = self._grid.verticalScrollBar() sb = self._grid.verticalScrollBar()
from .grid import THUMB_SIZE, THUMB_SPACING from .grid import THUMB_SIZE, THUMB_SPACING
if sb.maximum() > 0 and sb.value() >= sb.maximum() - (THUMB_SIZE + THUMB_SPACING * 2): threshold = THUMB_SIZE + THUMB_SPACING * 2
if sb.maximum() == 0 or sb.value() >= sb.maximum() - threshold:
self._on_reached_bottom() self._on_reached_bottom()
def _fetch_thumbnail(self, index: int, url: str) -> None: def _fetch_thumbnail(self, index: int, url: str) -> None: