Here’s an initial stab at using a dictionary for layout details:
# Screen layout details
LAYOUT = \
{ ADisplay.DEFAULT :
{
# Artwork position and size
"thumb" : { "pos": (5, 5), "size": thumb_height },
# Progress bar. Two versions are possible, short and long,
# depending upon the MusicPlayer.Time string.
"prog" : { "pos": (150, 7),
"short_len": 104, "long_len": 164,
"height": 8 },
# All other text fields, including any labels
"fields" :
[
{ "name": "MusicPlayer.Time", "pos": (148, 20), "font": font7S, "fill":color7S },
{ "name": "MusicPlayer.TrackNumber", "pos": (148, 73), "font": font7S, "fill": color7S,
"label": "Track", "lpos": (148, 60), "lfont": font_tiny, "lfill": "white" },
{ "name": "MusicPlayer.Duration", "pos": (230, 60), "font": font_tiny, "fill": "white" },
{ "name": "codec", "pos": (230, 74), "font": font_tiny, "fill": "white" },
{ "name": "MusicPlayer.Genre", "pos": (230, 88), "font": font_tiny, "fill": "white", "trunc":1 },
{ "name": "MusicPlayer.Year", "pos": (230,102), "font": font_tiny, "fill": "white" },
{ "name": "MusicPlayer.Title", "pos": (5, 152), "font": font_main, "fill": "white", "trunc":1},
{ "name": "MusicPlayer.Album", "pos": (5, 180), "font": font_sm, "fill": "white", "trunc":1 },
{ "name": "MusicPlayer.Artist", "pos": (5, 205), "font": font_sm, "fill": color_artist, "trunc":1 },
]
}
}
The corresponding code in audio_screens()
isn’t entirely generic, since it has special treatment for the codec field (another dictionary lookup) and Artist field (substitution with Composer possible). Nevertheless, it is now mostly a for-loop over the “fields” array above.
I need to deploy this on the C4 and see how it does for speed.