Skip to main content
Wrend.1
Associate III
December 2, 2020
Solved

The last line of text was lost when I use textArea.resizeHeightToCurrentText().

  • December 2, 2020
  • 1 reply
  • 1621 views
seasoningText.setWideTextAction(touchgfx::WIDE_TEXT_CHARWRAP_DOUBLE_ELLIPSIS);
seasoningText.setLinespacing(10);
seasoningText.setIndentation(5);
seasoningText.resizeHeightToCurrentText(); // When I comment out this line, I can see the newline content
seasoningText.invalidate();

I use a textArea and switch off the "Auto-size" option, and put it in a scrollableContainer.

I want it to wrap automatically and adjust the height. But when I use the function "resizeHeightToCurrentText()", the second line is invisible.(When the text area is about to leave the screen, the second line appears)

If I don't use the function "resizeHeightToCurrentText()", the second line will always appear. But I don't know the current height of textArea.:sad_but_relieved_face:

So how can I use the use the function "resizeHeightToCurrentText()" normally?

This topic has been closed for replies.
Best answer by Wrend.1

OK, now I find the reason. It seems like the function "resizeHeightToCurrentText" calc the wrong value for the height and It lead to the last line disappear. I repalce the ​code like this:

//seasoningText.resizeHeightToCurrentText();
seasoningText.setHeight(seasoningText.calculateTextHeight(seasoningTextBuffer)+ seasoningText.getLinespacing());

And it works.

1 reply

Wrend.1
Wrend.1AuthorBest answer
Associate III
December 7, 2020

OK, now I find the reason. It seems like the function "resizeHeightToCurrentText" calc the wrong value for the height and It lead to the last line disappear. I repalce the ​code like this:

//seasoningText.resizeHeightToCurrentText();
seasoningText.setHeight(seasoningText.calculateTextHeight(seasoningTextBuffer)+ seasoningText.getLinespacing());

And it works.

David S.
Visitor II
July 20, 2023

Hi, I get the same behavior with the proposed solution:

 

textArea.setWideTextAction(touchgfx::WideTextAction::WIDE_TEXT_WORDWRAP);
textArea.setLinespacing(3);
textArea.setHeight(textArea.calculateTextHeight(textBuffer) + textArea.getLinespacing());

 

nowrap.jpg

textArea.setWideTextAction(touchgfx::WideTextAction::WIDE_TEXT_WORDWRAP);
//textArea.setLinespacing(3);
textArea.setHeight(textArea.calculateTextHeight(textBuffer) + textArea.getLinespacing());

wrap.jpg