Skip to main content
FTkal.1
Associate II
July 15, 2020
Solved

TextArea word wrap

  • July 15, 2020
  • 14 replies
  • 4977 views

I'm not able top get word wrap working with the TextArea widget.

I'm using the TextArea sample. I've changed the text resource "Main_text" to be a single line of text. I've editted the Screen1View() constructor and added...

mainTxt.setWideTextAction(touchgfx::WIDE_TEXT_WORDWRAP);

mainTxt.resizeHeightToCurrentText();

as suggested by another post, but I only get one line of text, truncated within the box.

Any suggestions?

Edit: And I set line spacing to 5.

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Yes. The width, basically. Sorry for being convoluted/philosophical =)

It works on my desk, i just took my own medicine. The following is enough for me.

1) Autosize-off - Adjust width manually to where i want the text to break.

2) set the word wrap action in gui/screen1_screen/Screen1View.cpp.

Screen1View::Screen1View()
{
 textArea1.setWideTextAction(touchgfx::WIDE_TEXT_WORDWRAP);
}

 /Martin

14 replies

Martin KJELDSEN
Principal III
July 15, 2020

Ensure that you have "Auto size" off in the attributes pane for the text area in the designer and then define the "confines" of the textArea (the width) which determine where to "break" the lines. You'll have your line breaks then.

/Martin

FTkal.1
FTkal.1Author
Associate II
July 15, 2020

Auto size is off.

In the sample, Screen1ViewBase.cpp constructor sets...

  mainTxt.setPosition(50, 88, 205, 78);

Is that what you mean by the confines?

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
July 15, 2020

Yes. The width, basically. Sorry for being convoluted/philosophical =)

It works on my desk, i just took my own medicine. The following is enough for me.

1) Autosize-off - Adjust width manually to where i want the text to break.

2) set the word wrap action in gui/screen1_screen/Screen1View.cpp.

Screen1View::Screen1View()
{
 textArea1.setWideTextAction(touchgfx::WIDE_TEXT_WORDWRAP);
}

 /Martin

FTkal.1
FTkal.1Author
Associate II
July 15, 2020

Thanks. It started working when I got rid of mainTxt.resizeHeightToCurrentText();

Martin KJELDSEN
Principal III
July 15, 2020

Great. Actually, it should still work with the following (does for me).

Screen1View::Screen1View()
{
 textArea1.setWideTextAction(touchgfx::WIDE_TEXT_WORDWRAP);
 textArea1.resizeHeightToCurrentText();
}

This will prevent TouchGFX from invalidating a larger area than required. e.g. if your wordwrap only wraps to half of the height you specified manually. That's why you can resizeHeightToCurrentText();

/Martin

RMoha.2
Associate III
July 17, 2020

@Martin KJELDSEN​ Would it be possible to share a sample working project?

Have not been able to get it to work, thinking something to do with text settings/typographies

Martin KJELDSEN
Principal III
July 17, 2020

A working project that shows what is discussed in this thread?

FTkal.1
FTkal.1Author
Associate II
July 15, 2020

I added

mainTxt.resizeHeightToCurrentText();

back, and it still fails. But if I force the widget height...

mainTxt.setHeight(mainTxt.getHeight() + 5);

It works. My linespacing is set to 5.

Setting linespacing to 0, then it works without the setHeight.