cancel
Showing results for 
Search instead for 
Did you mean: 

Update a text area with a string and sting has \n newline char

FJB2069
Senior

I am trying to update a text area called textTestArea with a string and I want to be able to format the string with a newline character.    Ex "I went to the store \n to buy food"

 

I created a texts called genericText that uses a default font that has wildcard range 0x00-0xFF ,  I also tried having range 0x20-0x7e and wildcard character 0x0A (/n)

here is the text and typography:

FJB2069_1-1753307815267.png

FJB2069_2-1753307861147.png

 

 

Here is the screen with text area:

FJB2069_0-1753307614317.png

FJB2069_3-1753307902728.png

in baseview.cpp it creates:

 

 textTestArea.setPosition(397, 26, 237, 55);
    textTestArea.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
    textTestArea.setLinespacing(0);
    Unicode::snprintf(textTestAreaBuffer, TEXTTESTAREA_SIZE, "%s", touchgfx::TypedText(T_GENERICTEXT).getText());
    textTestArea.setWildcard(textTestAreaBuffer);
    textTestArea.setTypedText(touchgfx::TypedText(T___SINGLEUSE_E1ZC));
    add(textTestArea);

So now in my view.cpp:

	static const uint16_t TEXTBUFFER_SIZE = 64;
			Unicode::UnicodeChar textBuffer[TEXTBUFFER_SIZE];



		Unicode::snprintf(textBuffer, TEXTBUFFER_SIZE, "I went to store \n to but food");

		textTestArea.setTypedText(TypedText(T___SINGLEUSE_81C4));  // Must match your Texts View ID
		textTestArea.setWildcard(textBuffer);
		textTestArea.setWideTextAction(WIDE_TEXT_WORDWRAP);
		textTestArea.resizeToCurrentText();
		textTestArea.invalidate();

I get "test"  Not I went to the store....

 

I have tried 100 iterations.  I have gotten it to print "I went to the store \n to buy food", but can not get it to acknowledge the \n character.

How is this implemented correctly?

 

4 REPLIES 4
FJB2069
Senior

Could it be the font I am using dies not have the newline character defined?  I read something about creating special characters as glyphs?

Could you use typed text in TouchGFX instead of programmatically assembling a multiline string? That's how I've been doing it, with no problems. 

I tried using vendana font, no difference.

 

So I am able to use this code and it prints a:  

Unicode::snprintf(textTestAreaBuffer, TEXTTESTAREA_SIZE, "%s", "a");
		textTestArea.invalidate();

 this is how the generated textTestArea is in viewbase.cpp

   textTestArea.setXY(397, 26);
    textTestArea.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
    textTestArea.setLinespacing(0);
    textTestArea.setWideTextAction(WIDE_TEXT_WORDWRAP);
    Unicode::snprintf(textTestAreaBuffer, TEXTTESTAREA_SIZE, "%s", touchgfx::TypedText(T___SINGLEUSE_J85U).getText());
    textTestArea.setWildcard(textTestAreaBuffer);
    textTestArea.resizeToCurrentText();
    textTestArea.setTypedText(touchgfx::TypedText(T___SINGLEUSE_45YP));
    add(textTestArea);
}

 

But if I try to print  a \n a:  I get ??a

 

	Unicode::snprintf(textTestAreaBuffer, TEXTTESTAREA_SIZE, "%s", "a \n a");
		textTestArea.invalidate();

   Not sure what to try?

like this?

 

FJB2069_0-1753322598238.png

It still will not acknowledge \n

wait I can make it like this:

FJB2069_1-1753322773545.png