cancel
Showing results for 
Search instead for 
Did you mean: 

How to declare TextArea without using touchGFX Designer?

Wrend.1
Senior
	TextAreaWithOneWildcard textIllustration;
	Unicode::UnicodeChar txtBuffer[40];
	textIllustration.setXY(0, 0);
	textIllustration.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
	textIllustration.setLinespacing(0);
	textIllustration.setWildcard(txtBuffer);
	Unicode::snprintf(txtBuffer, 40, "%s", "hello world!");
	textIllustration.invalidate();
	add(textIllustration);

I want to ​declare a TextArea without using touchGFX Designer.

So I use the code like this.

Of course,it crashed.

What am I miss?Or It's illegal.

3 REPLIES 3
Romain DIELEMAN
ST Employee

HI,

It is possible to add widgets without using Designer, this is how you can add your custom widgets as well.

Where did you put this code? I would also use setPosition instead of setXY. Did you include all the necessary header files?

/Romain

Thanks very much for your reply.

I put it in

mainScreenView::mainScreenView()
{
     ...//my code
}

​And I have another quesetion, the Wildcard need to be specified with Typographies. But I can not find how to set it.

You'll need to add it as a class member/field - if that's the constructor it's going to be declared on the stack and removed as soon as the constructor invocation finishes.

I've found the way to do the wildcard with typography is to get it declared in the designer, which associates it with the typography. Then use the database file (excel sheet) to figure out what it's ID is. Code then looks like this:

item->setTypedText(touchgfx::TypedText(T_SINGLEUSEID30));

Of course, that may very well not be correct either. The TypedText class and the Texts class (which represents the database for the current language) does not expose any methods that support modifying the internal data, and it does not appear that TypedText supports that.

I've noticed (just now) the following statement at the top of the documentation (https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_text_area_with_one_wildcard) though:

 the text converter tool converts the <...> to ascii value 2 which is then being replaced by a wildcard text.

Following that, it seems a string containing a character with the value of 2 would do the trick. I'm going to test this out - I'll report back.