Change parameter of display_wrapped_text
To add compatibility to ESPHome 2023.11 Solves #1247
This commit is contained in:
@@ -1971,30 +1971,30 @@ script:
|
||||
mode: queued
|
||||
parameters:
|
||||
component: string
|
||||
text: string
|
||||
text_to_display: string
|
||||
line_length_limit: uint
|
||||
then:
|
||||
- lambda: |-
|
||||
int startPos = 0;
|
||||
int endPos = 0;
|
||||
std::string wrappedText = "";
|
||||
while (startPos < text.length()) {
|
||||
while (text[startPos] == ' ' and startPos < text.length()) { startPos++; }
|
||||
while (startPos < text_to_display.length()) {
|
||||
while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; }
|
||||
int endPos = startPos + line_length_limit;
|
||||
if (endPos >= text.length()) endPos = text.length();
|
||||
if (endPos >= text_to_display.length()) endPos = text_to_display.length();
|
||||
else
|
||||
{
|
||||
while (endPos > startPos && text[endPos] != ' ') { endPos--; }
|
||||
while (endPos > startPos && text_to_display[endPos] != ' ') { endPos--; }
|
||||
if (endPos == startPos) endPos = startPos + line_length_limit; // Handle case of long word
|
||||
}
|
||||
wrappedText += text.substr(startPos, endPos-startPos);
|
||||
if (endPos < text.length())
|
||||
wrappedText += text_to_display.substr(startPos, endPos-startPos);
|
||||
if (endPos < text_to_display.length())
|
||||
{
|
||||
while (text[endPos] == ' ') { endPos--; }
|
||||
while (text_to_display[endPos] == ' ') { endPos--; }
|
||||
if (endPos >= startPos) wrappedText += "\\r";
|
||||
}
|
||||
startPos = endPos + 1; // Skip the space
|
||||
while (text[startPos] == ' ' and startPos < text.length()) { startPos++; }
|
||||
while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; }
|
||||
}
|
||||
disp1->set_component_text_printf(component.c_str(), "%s", wrappedText.c_str());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user