feat: Implement scrolling camera with layout-aware filtering

- Rename VERTICAL camera mode to FEED (rapid single-item view)
- Add SCROLL camera mode with float accumulation for smooth movie-credits style scrolling
- Add estimate_block_height() for cheap layout calculation without full rendering
- Replace ViewportFilterStage with layout-aware filtering that tracks camera position
- Add render caching to FontStage to avoid re-rendering items
- Fix CameraStage to use global canvas height for scrolling bounds
- Add horizontal padding in Camera.apply() to prevent ghosting
- Add get_dimensions() to MultiDisplay for proper viewport sizing
- Fix PygameDisplay to auto-detect viewport from window size
- Update presets to use scroll camera with appropriate speeds
This commit is contained in:
2026-03-17 00:21:18 -07:00
parent 4c97cfe6aa
commit 57de835ae0
12 changed files with 303 additions and 66 deletions

View File

@@ -13,6 +13,50 @@ from engine import config
from engine.sources import NO_UPPER, SCRIPT_FONTS, SOURCE_LANGS
from engine.translate import detect_location_language, translate_headline
def estimate_block_height(title: str, width: int, fnt=None) -> int:
"""Estimate rendered block height without full PIL rendering.
Uses font bbox measurement to count wrapped lines, then computes:
height = num_lines * RENDER_H + (num_lines - 1) + 2
Args:
title: Headline text to measure
width: Terminal width in characters
fnt: Optional PIL font (uses default if None)
Returns:
Estimated height in terminal rows
"""
if fnt is None:
fnt = font()
text = re.sub(r"\s+", " ", title.upper())
words = text.split()
lines = 0
cur = ""
for word in words:
test = f"{cur} {word}".strip() if cur else word
bbox = fnt.getbbox(test)
if bbox:
img_h = bbox[3] - bbox[1] + 8
pix_h = config.RENDER_H * 2
scale = pix_h / max(img_h, 1)
term_w = int((bbox[2] - bbox[0] + 8) * scale)
else:
term_w = 0
max_term_w = width - 4 - 4
if term_w > max_term_w and cur:
lines += 1
cur = word
else:
cur = test
if cur:
lines += 1
if lines == 0:
lines = 1
return lines * config.RENDER_H + max(0, lines - 1) + 2
# ─── FONT LOADING ─────────────────────────────────────────
_FONT_OBJ = None
_FONT_OBJ_KEY = None