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
|
mode: queued
|
||||||
parameters:
|
parameters:
|
||||||
component: string
|
component: string
|
||||||
text: string
|
text_to_display: string
|
||||||
line_length_limit: uint
|
line_length_limit: uint
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
int startPos = 0;
|
int startPos = 0;
|
||||||
int endPos = 0;
|
int endPos = 0;
|
||||||
std::string wrappedText = "";
|
std::string wrappedText = "";
|
||||||
while (startPos < text.length()) {
|
while (startPos < text_to_display.length()) {
|
||||||
while (text[startPos] == ' ' and startPos < text.length()) { startPos++; }
|
while (text_to_display[startPos] == ' ' and startPos < text_to_display.length()) { startPos++; }
|
||||||
int endPos = startPos + line_length_limit;
|
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
|
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
|
if (endPos == startPos) endPos = startPos + line_length_limit; // Handle case of long word
|
||||||
}
|
}
|
||||||
wrappedText += text.substr(startPos, endPos-startPos);
|
wrappedText += text_to_display.substr(startPos, endPos-startPos);
|
||||||
if (endPos < text.length())
|
if (endPos < text_to_display.length())
|
||||||
{
|
{
|
||||||
while (text[endPos] == ' ') { endPos--; }
|
while (text_to_display[endPos] == ' ') { endPos--; }
|
||||||
if (endPos >= startPos) wrappedText += "\\r";
|
if (endPos >= startPos) wrappedText += "\\r";
|
||||||
}
|
}
|
||||||
startPos = endPos + 1; // Skip the space
|
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());
|
disp1->set_component_text_printf(component.c_str(), "%s", wrappedText.c_str());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user