Closed riyuk closed 12 months ago
Hi,
the texts that are rendered to the button image are created as an SVG graphics. Allowing new-line characters to be parsed and converted into new text lines sounds easy but is a real pain. So unfortunatelly i will not support this in the near future :(
wouldnt something like that work? @cgiesche
// svgUtils.js
const text = (text, lineNr) => {
if (text.indexOf("\n") > -1) {
let lines = text.split("\n");
for (let i = lineNr; i < (lines.length + lineNr); i++) {
drawText(lines[i-lineNr], i);
}
return;
}
drawText(text, lineNr);
}
const drawText = (text, lineNr) => {
this.snap.text(0, 26 + lineNr * 36, text)
.attr(this.lineAttr)
.transform(`translateX(${this.halfRes})`);
}
@cgiesche i can confirm that this works. it was a mess to edit the compiled js but in the end it works. it would be great if you can do something like that. i can also do a pull request if you like.
btw a example on where to use it: i have one button on stream deck which now displays the inside & outside temperature. the sensor for that is a template sensor like that:
- name: streamdecktemperature
state: "{{ states('sensor.aqara_outside_weather_temperature') | int }}° Outside{{- '\n' -}}{{ states('sensor.aqara_weather_temperature') | int }}° Inside"
it was a mess to edit the compiled js
lul
wouldnt something like that work?
Ok, you are right. This seems to be easier than i expected. The painful experience of programming SVG in JavaScript has discouraged me :D
If you open a PR, i will accept it and build a prerelease. The official release to the store will take some time as it is a manual process including hand written mails to elgato. I always wait until enough changes have accumulated before asking Elgato to publish the plugin.
If you have a template sensor which has a newline in it
{{- '\n' -}}
the icon is still displaying everything in one line. This actually is very useful if you want to display multiple sensor values in one button.