cancel
Showing results for 
Search instead for 
Did you mean: 

Example of how to use Resources ID in Text

MDi D.1
Associate II

Is there a guide/tutorial that shows how to use it? How, for example, to invoke a specific "Resource ID" in order to fill a TextArea?

Thanks

4 REPLIES 4
Osman SOYKURT
ST Employee

Hello MDi D.1,

We don't have a tutorial, but we have this documentation that can help you.

I'll show you the basics of how use resources under TouchGFX Designer :

1- Create you project and go "Text" on the left panel.

0693W00000LyaUzQAJ.png 

2- Click on "Add new text" and edit the resource you want. You can modify the 'id" of your resource, the "typography", the "alignment", and finally your text. "GB" is already here by default and it's your text in English language, you can add an other language by clicking on the "+" button.

0693W00000LyaFBQAZ.png0693W00000LyaFbQAJ.pngTry to edit it like this :

0693W00000LyaHMQAZ.png 

3- Go back to your canvas and add a new text widget

0693W00000LyaMqQAJ.png 

4- In right panel, click on the loupe under the "Text" section

0693W00000LyaP1QAJ.png 

5- Click on "Group1" and click on the new resource we just created.

0693W00000LyaPuQAJ.png 

6- Enjoy 🙂

0693W00000LyaR2QAJ.png 

(7- If you want to change the language of your text, go to "Config" on the left panel, and under General, change the "Selected Language", then the change will automatically take place on you canvas)

0693W00000LyaS5QAJ.png 

0693W00000LyaSZQAZ.png 

Hope this helps 😉

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX
MDi D.1
Associate II

Thanks for the explanation.

If I want to change the content of the TextArea to runtime, how do I edit it using a multilanguage resource that I added in the designer.

Obviously writing code 🙂

thank you

Osman SOYKURT
ST Employee

Hello MDi D.1,

That's very easy thing 🙂

Let's take an example.

You have a new TextArea, called textToChangeRuntime. When you add a textArea in the Designer, it will automatically generate some code :

In Screen1ViewBase.hpp

touchgfx::TextArea textToChangeRuntime;

And in Screen1ViewBase.cpp :

textToChangeRuntime.setTypedText(touchgfx::TypedText(T___SINGLEUSE_CT1B));

T___SINGLEUSE_CT1B is the enum referencing the resource which is automatically created when you create a TextArea. What we want is to to tell the application not to use this T___SINGLEUSE_CT1B anymore but the enum referencing the resource you've created instead. With the example of my previous post, you should have a resource called "myFirstRessource" and the enum for this would be T_MYFIRSTRESSOURCE. You can check that in your "generated\texts\include\texts\TextKeysAndLanguagfe.hpp" file.

So let's change the value of your textArea.

Go to your Screen1View.cpp, and add this line under setupScreen() function

void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
    
    textToChangeRuntime.setTypedText(touchgfx::TypedText(T_MYFIRSTRESSOURCE));
    textToChangeRuntime.invalidate();
}

and also the right include :

#include <texts/TextKeysAndLanguages.hpp>

And that's it ! 🙂

You're free to create function dedicated to this, for my example I used setupScreen() function to stay simple.

Also, if you want to switch between languages, you can add this, near the previous line :

Texts::setLanguage(ITALIAN);

in argument of this function, it's also an enum (LANGUAGES in TextKeysAndLanguages.hpp)

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX
MDi D.1
Associate II

Thank you for your support!.

I'll try your code asap.

Ciao