cancel
Showing results for 
Search instead for 
Did you mean: 

TextArea word wrap

FTkal.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

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

View solution in original post

14 REPLIES 14
Martin KJELDSEN
Chief III

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
Associate II

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
Chief III

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
Associate II

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

Martin KJELDSEN
Chief III

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

FTkal.1
Associate II

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.

@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

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

I'm leaving the office now and taking some vacation so i won't have time right now, but ... just add the code that i shared/is discussed in this thread. It will wrap the long text on the edge of the textarea defined on your canvas in the Designer. e.g. you manually adjust the width to 100 px and set WIDE_TEXT_WORDWRAP, then your string which is 10000000000000px long will be wrapped so that each line is 100px long.