Skip to content

Commit 4e2178c

Browse files
authored
nsluke
mlbdivstandings: add a 64x64 layout
2 parents fca7a59 + f8208b3 commit 4e2178c

2 files changed

Lines changed: 141 additions & 2 deletions

File tree

‎apps/mlbdivstandings/manifest.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ tags:
1212
- mlb
1313
- baseball
1414
published: '2023-09-06T13:53:38Z'
15-
updated: '2025-12-02T19:30:22Z'
15+
updated: '2026-09-03T04:50:13Z'

‎apps/mlbdivstandings/mlbdivstandings.star‎

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ load("images/tb_logo.png", TB_LOGO_ASSET = "file")
4040
load("images/tex_logo.png", TEX_LOGO_ASSET = "file")
4141
load("images/tor_logo.png", TOR_LOGO_ASSET = "file")
4242
load("images/was_logo.png", WAS_LOGO_ASSET = "file")
43-
load("render.star", "render")
43+
load("render.star", "canvas", "render")
4444
load("schema.star", "schema")
4545
load("time.star", "time")
4646

@@ -93,6 +93,11 @@ def main(config):
9393

9494
standings = get_Standings(division_id, year)
9595

96+
# square panels get a second tier: the same card carousel up top
97+
# plus the whole division table underneath
98+
if is_square():
99+
return render_square(standings, division_id, year)
100+
96101
# if we have some widgets, we can display them now
97102
if len(standings) > 0:
98103
return render.Root(
@@ -147,6 +152,12 @@ def build_keyframe(offset, pct):
147152
curve = "ease_in_out",
148153
)
149154

155+
def is_square():
156+
"""Branch on canvas SHAPE, not size: a 2x wide panel reports 128x64 and a
157+
2x square one 128x128, so a bare height test gets both wrong."""
158+
w, h = canvas.size()
159+
return h == w
160+
150161
def get_schema():
151162
options = [
152163
schema.Option(
@@ -376,6 +387,134 @@ def render_record_info(team, clinched, wins, losses, games_back, div_rank):
376387
render_rainbow_word("CHAMP", SMALL_FONT),
377388
]
378389

390+
def render_square(standings, division_id, year):
391+
# zero-state, square edition: marquee below the league image
392+
# instead of on top of it
393+
if len(standings) == 0:
394+
return render.Root(
395+
child = render.Column(
396+
children = [
397+
render.Image(
398+
src = MLB_LEAGUE_IMAGE,
399+
),
400+
render.Box(
401+
height = 32,
402+
width = 64,
403+
child = render.Marquee(
404+
width = 64,
405+
child = render.Text(
406+
content = "No standings to display for league year " + year,
407+
color = SMALL_FONT_COLOR,
408+
font = SMALL_FONT,
409+
),
410+
),
411+
),
412+
],
413+
),
414+
)
415+
416+
# breathing room between the carousel and the table
417+
table_rows = [render.Box(height = 1, width = 64)]
418+
for info in standings:
419+
table_rows.append(render_table_row(info))
420+
421+
return render.Root(
422+
delay = 80,
423+
show_full_animation = True,
424+
child = render.Column(
425+
children = [
426+
render.Row(
427+
children = [
428+
render_lefter(division_id),
429+
animation.Transformation(
430+
duration = 180,
431+
width = 295,
432+
height = 32,
433+
keyframes = [
434+
build_keyframe(0, 0.0),
435+
build_keyframe(0, 0.08),
436+
build_keyframe(-59, 0.25),
437+
build_keyframe(-118, 0.50),
438+
build_keyframe(-177, 0.75),
439+
build_keyframe(-236, 0.9),
440+
build_keyframe(-236, 1.0),
441+
],
442+
child = render_DivisionStandings(standings),
443+
wait_for_child = True,
444+
),
445+
],
446+
),
447+
] + table_rows,
448+
),
449+
)
450+
451+
def render_table_row(info):
452+
team = TEAM_INFO[info.TeamId]
453+
if info.Clinched:
454+
# clinchers get the same rainbow treatment the card gives them
455+
abbrev = render_rainbow_word(team.Abbreviation, SMALL_FONT)
456+
else:
457+
abbrev = render.Text(
458+
content = team.Abbreviation,
459+
font = SMALL_FONT,
460+
color = team.ForegroundColor,
461+
)
462+
return render.Box(
463+
height = 6,
464+
width = 64,
465+
color = team.BackgroundColor,
466+
child = render.Row(
467+
expanded = True,
468+
main_align = "start",
469+
cross_align = "center",
470+
children = [
471+
render.Box(
472+
width = 1,
473+
height = 5,
474+
),
475+
render.Box(
476+
width = 13,
477+
height = 5,
478+
child = render.Row(
479+
expanded = True,
480+
main_align = "start",
481+
children = [abbrev],
482+
),
483+
),
484+
render.Box(
485+
width = 27,
486+
height = 5,
487+
child = render.Row(
488+
expanded = True,
489+
main_align = "end",
490+
children = [
491+
render.Text(
492+
content = "{}-{}".format(info.Wins, info.Losses),
493+
font = SMALL_FONT,
494+
color = team.ForegroundColor,
495+
),
496+
],
497+
),
498+
),
499+
render.Box(
500+
width = 22,
501+
height = 5,
502+
child = render.Row(
503+
expanded = True,
504+
main_align = "end",
505+
children = [
506+
render.Text(
507+
content = info.GamesBack.removesuffix(".0"),
508+
font = SMALL_FONT,
509+
color = team.ForegroundColor,
510+
),
511+
],
512+
),
513+
),
514+
],
515+
),
516+
)
517+
379518
#################
380519
## TEAM CONFIG ##
381520
#################

0 commit comments

Comments
 (0)