mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-02 01:08:05 +00:00
Vegas mode: render plugins narrower, space rows by measured separation
Trimming reclaims blank margins but cannot compact a layout that genuinely spans the display — a five-column forecast, a progress bar drawn at 100% width, a stat block with the panel's whole width between its elements. Those need the plugin to make different layout decisions, which means telling it the screen is narrower while it renders. DisplayManager.render_size() presents a smaller logical canvas for the duration of a Vegas content fetch, reusing the same _LogicalMatrix indirection double-sided mode already relies on so plugins see a consistent size from every accessor. Plugins that size themselves from matrix.width need no changes at all; one that wants to be explicit can read the new BasePlugin.get_vegas_render_width(). Width is a percentage so a single setting travels across panel sizes: vegas_scroll.render_width_pct globally, or vegas_width_pct in an individual plugin's config. Measured on a 512x64 panel with real data: ledmatrix-weather 1536px -> 576px (forecast becomes narrow cards) youtube-stats 353px -> 199px (2% blank left, so genuinely compact) geochron 453px -> 153px (ink density rises to 100%) ledmatrix-flights 950px -> 740px The youtube-stats figure is the clearest evidence the layout itself changed rather than being cropped: at full width the content had to be trimmed from 512px to 353px, whereas at 40% it arrives with almost no blank to reclaim. Row spacing is now measured rather than added. A flat gap gets it wrong in both directions at once — content drawn flush to its own edges ends up nearly touching (reported for recent sports scores, which sat 8px apart), while content already carrying wide margins gets pushed even further out. separation_gap() measures the blank each pair already has and adds only the shortfall, up to min_content_separation (default 24). intra_plugin_gap stays as a floor applied regardless. Two tests shipped in the previous commit encoded the old flat-gap arithmetic and are updated to the measured semantics, including one renamed to reflect that zero intra_plugin_gap alone no longer butts rows together. Also fixes a real bug found while testing: the harness display manager had no render_size(), and because the adapter catches broadly that surfaced as "no content" rather than an error, silently dropping five plugins. Added the context to VisualTestDisplayManager for parity, and _render_at() now degrades to a no-op on any display manager lacking it, so a third-party or older harness loses the narrowing rather than the content. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KEZK1P1Q1fu5pcuVrkrCFZ
This commit is contained in:
@@ -9,6 +9,8 @@ from src.vegas_mode.geometry import (
|
||||
column_has_ink,
|
||||
content_bounds,
|
||||
dead_window_stats,
|
||||
edge_blank,
|
||||
separation_gap,
|
||||
trim_to_content,
|
||||
window_coverage_stats,
|
||||
)
|
||||
@@ -271,3 +273,49 @@ class TestLongestRunHelper:
|
||||
def test_run_lengths(self, flags, expected):
|
||||
from src.vegas_mode.geometry import _longest_true_run
|
||||
assert _longest_true_run(np.array(flags, dtype=bool)) == expected
|
||||
|
||||
|
||||
class TestEdgeBlank:
|
||||
def test_measures_both_edges(self):
|
||||
assert edge_blank(paint(make_img(100), 20, 60)) == (20, 40)
|
||||
|
||||
def test_flush_content_has_no_blank(self):
|
||||
assert edge_blank(paint(make_img(50), 0, 50)) == (0, 0)
|
||||
|
||||
def test_blank_image_reports_full_width_both_sides(self):
|
||||
# No ink means nothing to be close to.
|
||||
assert edge_blank(make_img(64)) == (64, 64)
|
||||
|
||||
|
||||
class TestSeparationGap:
|
||||
def test_flush_edges_get_the_full_target(self):
|
||||
a = paint(make_img(50), 0, 50)
|
||||
b = paint(make_img(50), 0, 50)
|
||||
assert separation_gap(a, b, target=24) == 24
|
||||
|
||||
def test_existing_margins_reduce_the_added_gap(self):
|
||||
# 8px blank on each facing edge already covers 16 of the 24 target.
|
||||
a = paint(make_img(50), 0, 42)
|
||||
b = paint(make_img(50), 8, 50)
|
||||
assert separation_gap(a, b, target=24) == 8
|
||||
|
||||
def test_ample_existing_margin_adds_nothing(self):
|
||||
a = paint(make_img(100), 0, 60)
|
||||
b = paint(make_img(100), 40, 100)
|
||||
assert separation_gap(a, b, target=24) == 0
|
||||
|
||||
def test_minimum_is_a_floor(self):
|
||||
a = paint(make_img(100), 0, 60)
|
||||
b = paint(make_img(100), 40, 100)
|
||||
assert separation_gap(a, b, target=24, minimum=4) == 4
|
||||
|
||||
def test_never_negative(self):
|
||||
a = paint(make_img(200), 0, 10)
|
||||
b = paint(make_img(200), 190, 200)
|
||||
assert separation_gap(a, b, target=8) == 0
|
||||
|
||||
def test_sports_card_case_gets_real_separation(self):
|
||||
# The reported problem: cards drawn edge to edge sat 8px apart under a
|
||||
# flat gap; measured separation lifts them to the 24px target.
|
||||
card = paint(make_img(150), 0, 150)
|
||||
assert separation_gap(card, card, target=24, minimum=8) == 24
|
||||
|
||||
Reference in New Issue
Block a user