2020-07-14 11:28 PM
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.
Solved! Go to Solution.
2020-07-15 12:23 AM
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
2020-07-15 12:03 AM
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
2020-07-15 12:09 AM
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?
2020-07-15 12:23 AM
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
2020-07-15 12:27 AM
Thanks. It started working when I got rid of mainTxt.resizeHeightToCurrentText();
2020-07-15 12:30 AM
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
2020-07-15 12:45 AM
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.
2020-07-17 06:18 AM
@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
2020-07-17 06:48 AM
A working project that shows what is discussed in this thread?
2020-07-17 06:50 AM
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.