Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to handle long text #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions MMM-Sonos.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@
.sonos ul.flip {
direction: rtl;
}
.iso-marquee {
overflow: hidden;
}
.iso-marquee span {
display: inline-block;
white-space: nowrap;
width: var(--tw);
text-shadow: var(--tw) 0 currentcolor,
calc(var(--tw) * 2) 0 currentcolor,
calc(var(--tw) * 3) 0 currentcolor,
calc(var(--tw) * 4) 0 currentcolor;
will-change: transform;
animation: iso-marquee var(--ad) linear infinite;
animation-play-state: play;
}

@keyframes iso-marquee {
0% { transform: translateX(0); }
100% { transform: translateX(-100%); }
}
14 changes: 14 additions & 0 deletions MMM-Sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
showAlbumArt: true,
albumArtLocation: 'right',
showRoomName: true,
maxTextLength: undefined,
scrollSpeed: 0,
animationSpeed: 1000,
updateInterval: 0.5, // every 0.5 minutes
apiBase: 'http://localhost',
Expand Down Expand Up @@ -51,6 +53,7 @@
},
updateRoomList: function (data) {
const roomList = []
const maxTextLength = this.config.maxTextLength
data.forEach(function (item) {
const roomName = this.getRoomName(item)
if (roomName !== '') {
Expand All @@ -71,11 +74,20 @@
track = ''
}

if (maxTextLength && this.config.scrollSpeed <= 0) {
if (artist.length > maxTextLength) {
artist = `${artist.substring(0, maxTextLength)}...`
}
if (track.length > maxTextLength) {
track = `${track.substring(0, maxTextLength)}...`
}
}

roomList.push({
name: roomName,
state: this.isInTVMode(artist, track, cover) ? 'TV' : item.coordinator.state.playbackState,
artist: artist,

Check warning on line 89 in MMM-Sonos.js

View workflow job for this annotation

GitHub Actions / ESLint

Expected property shorthand
track: track,

Check warning on line 90 in MMM-Sonos.js

View workflow job for this annotation

GitHub Actions / ESLint

Expected property shorthand
albumArt: cover
})
}
Expand All @@ -97,6 +109,8 @@
return {
flip: this.data.position.startsWith('left'),
loaded: this.loaded,
maxTextLength: this.config.maxTextLength,
scrollSpeed: this.config.scrollSpeed,
showAlbumArtRight:
this.config.showAlbumArt && this.config.albumArtLocation !== 'left',
showAlbumArtLeft:
Expand Down
16 changes: 15 additions & 1 deletion MMM-Sonos.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<style>
.iso-marquee {
max-width: {{ maxTextLength }}em;
}
</style>

<div class="sonos">
{% if loaded %}
<ul class={{ "flip" if flip else "" }}>
Expand All @@ -10,7 +16,15 @@
<img src="{{ room.albumArt }}"/>
</div>
{% endif %}
<div class="name normal medium">
{% if scrollSpeed > 0 and room.artist.length > maxTextLength and room.track.length > maxTextLength %}
{% if room.artist.length > room.track.length %}
<div class="name normal medium iso-marquee" style="--tw:{{ room.artist.length * 1.1 }}ch; --ad:{{scrollSpeed}}s;">
{% else %}
<div class="name normal medium iso-marquee" style="--tw:{{ room.track.length * 1.1 }}ch; --ad:{{scrollSpeed}}s;">
{% endif %}
{% else %}
<div class="name normal medium">
{% endif %}
<div>{{ room.artist }}</div>
<div>{{ room.track }}</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ You also can set some options to hide different parts of the module.
|`showAlbumArt`|Trigger the visualization of the album art.|`true`|
|`albumArtLocation`|Specifies on which side of the text the album art is rendered. Possible values: `left`, `right`.|`right`|
|`showRoomName`|Trigger the visualization of the room name.|`true`|
|`maxTextLength`|The maximum length of the displayed text.|`undefined`|
|`scrollSpeed`|If `maxTextLength` and `scrollSpeed` is set to a value above 0, the text will not be truncated but scroll in the allocated space instead. A recommended start value is `30`, and then you can tune this value up or down according to your preferences.|`0`|

### Known Issues

Expand Down
Loading