mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-01 08:48:05 +00:00
fix(layout): scoreboard_regions reserves real center space at 2:1 aspect ratios
logo_slot = min(height, width // 2) has a blind spot: at exactly 2:1 aspect ratio (width == 2 * height -- a very common shape: two, four, or more square modules stacked into a taller panel) width // 2 and height are equal, so the two logo slots claim the ENTIRE width and leave zero pixels for a center column, no matter how large the panel gets. Not a 'small panel' problem -- 96x48, 128x64, and 256x128 (all exactly 2:1) hit it identically, while the 128x32 design baseline and panels like 192x48 or 256x32 never do, because height is already the tighter constraint there. Two new parameters fix it in the one shared helper every scoreboard-style plugin composes through: - min_center_fraction / min_center_design_px reserve at least max(width * fraction, design_px * ctx.scale) for the center column, capping logo_slot further when needed. The scaled design-px term matters on small panels where a flat fraction alone reserves too little absolute space. - score_bleed_fraction extends the score's own fit box (not the logo slots themselves) a controlled amount into each side -- the same way real broadcast scoreboards let a big score number's edges cross into the team marks flanking it. Without this the reserve alone can still be too narrow for a short score to render without truncating. score_area is now genuinely narrower than the full card width (previously identical to status_band/detail_band, which still span the full width and overlay the logos -- short text there was never the problem). Verified against the full harness size spread: a real game score like '17-21' never needs ellipsis at any tested 2:1-or-tighter aspect ratio (test_score_never_needs_ellipsis_for_a_short_score), and wide panels (128x32/192x48/256x32-style) are provably unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,7 @@ class TestScoreboardRegions:
|
||||
@pytest.mark.parametrize("w,h", DEFAULT_TEST_SIZES + [(8, 8)])
|
||||
def test_invariants_at_all_sizes(self, w, h):
|
||||
regs = scoreboard_regions(Region(0, 0, w, h))
|
||||
assert regs.logo_slot == min(h, w // 2)
|
||||
assert regs.logo_slot <= min(h, w // 2)
|
||||
# slots hug the edges and never overlap the center column
|
||||
assert regs.away_slot.x == 0 and regs.home_slot.right == w
|
||||
assert regs.away_slot.right <= regs.center_col.x or regs.center_col.w == 0
|
||||
@@ -106,6 +106,55 @@ class TestScoreboardRegions:
|
||||
assert reg.x >= 0 and reg.y >= 0
|
||||
assert reg.right <= w and reg.bottom <= h
|
||||
|
||||
@pytest.mark.parametrize("w,h", [(96, 48), (128, 64), (256, 128), (64, 32), (128, 96)])
|
||||
def test_2to1_aspect_gets_a_center_reserve(self, w, h):
|
||||
"""These sizes are all <= 2:1 aspect, where the raw min(h, w//2)
|
||||
formula claims the entire width for logos and leaves zero pixels
|
||||
for a center column — the bug this reserve exists to fix."""
|
||||
regs = scoreboard_regions(Region(0, 0, w, h))
|
||||
assert regs.center_col.w >= int(w * 0.15) - 1 # -1 for int() rounding
|
||||
|
||||
@pytest.mark.parametrize("w,h", [(128, 32), (192, 48), (256, 32)])
|
||||
def test_wide_panels_unaffected_by_center_reserve(self, w, h):
|
||||
"""Wide (>= ~4:1) panels already have height as the tighter
|
||||
constraint, so the center reserve must be a no-op there — the
|
||||
design-size baseline's proportions shouldn't shift."""
|
||||
regs = scoreboard_regions(Region(0, 0, w, h))
|
||||
assert regs.logo_slot == min(h, w // 2)
|
||||
|
||||
def test_center_reserve_fraction_is_configurable(self):
|
||||
# min_center_design_px=0 isolates the fraction term (otherwise the
|
||||
# scaled absolute floor can dominate and mask a fraction change).
|
||||
regs_default = scoreboard_regions(Region(0, 0, 128, 64), min_center_design_px=0)
|
||||
regs_wider = scoreboard_regions(Region(0, 0, 128, 64), min_center_fraction=0.5,
|
||||
min_center_design_px=0)
|
||||
assert regs_wider.center_col.w > regs_default.center_col.w
|
||||
assert regs_wider.logo_slot < regs_default.logo_slot
|
||||
|
||||
def test_score_bleed_extends_past_center_col(self):
|
||||
regs = scoreboard_regions(Region(0, 0, 128, 64), score_bleed_fraction=0.5)
|
||||
assert regs.score_area.w > regs.center_col.w
|
||||
assert regs.score_area.x < regs.center_col.x
|
||||
assert regs.score_area.right > regs.center_col.right
|
||||
|
||||
def test_score_bleed_zero_matches_center_col(self):
|
||||
regs = scoreboard_regions(Region(0, 0, 128, 64), score_bleed_fraction=0.0)
|
||||
assert regs.score_area.w == regs.center_col.w
|
||||
assert regs.score_area.x == regs.center_col.x
|
||||
|
||||
@pytest.mark.parametrize("w,h", [(64, 32), (96, 48), (128, 64), (256, 128), (128, 96)])
|
||||
def test_score_never_needs_ellipsis_for_a_short_score(self, w, h, font_manager):
|
||||
"""The concrete regression this whole reserve/bleed system exists to
|
||||
prevent: a real game score like '17-21' must always render in full,
|
||||
never truncated, at every 2:1-or-tighter aspect ratio in the sample."""
|
||||
ctx = LayoutContext(w, h, font_manager)
|
||||
regs = scoreboard_regions(Region(0, 0, w, h), ctx=ctx)
|
||||
height_scale = h / 32.0
|
||||
fit = ctx.fit_text_proportional("17-21", regs.score_area, base_size_px=10,
|
||||
ladder=LADDER_ARCADE, scale=height_scale)
|
||||
assert fit.text == "17-21"
|
||||
assert fit.fits
|
||||
|
||||
def test_ctx_scales_band_heights(self, font_manager):
|
||||
small = scoreboard_regions(Region(0, 0, 128, 32),
|
||||
ctx=LayoutContext(128, 32, font_manager))
|
||||
|
||||
Reference in New Issue
Block a user