cancel
Showing results for 
Search instead for 
Did you mean: 

One TextArea has the ability to change fonts from a list on RUNTIME

A.Qasim
Associate II

0693W00000QKJi6QAH.jpgHi,

I am trying to achieve the functionality of a dropdown list having multiple fonts listed and upon selecting the desired font the textArea font gets changed at runtime.

As shown in Image the Selected font is "Times New Roman" and I want to make the textArea "EC:\> Hello World" written in that font and able to change it vice versa.

6 REPLIES 6
Osman SOYKURT
ST Employee

Hello A.Qasim,

There's multiple way to do it, but the easiest would be to create multiple languages where you'll have the same translation but a different typography. Then you can call the setLanguage() function to switch between your fonts.

0693W00000QKOe9QAH.png 

0693W00000QKOexQAH.png0693W00000QKOf2QAH.png 

void Screen1View::ChangeFontCourrier()
{
    Texts::setLanguage(COURRIER);
    textArea1.invalidate();
    textArea1.resizeToCurrentText();
    textArea1.invalidate();
    
}

Don't forget this include this :

#include <texts/TextKeysAndLanguages.hpp>

I attached a project, you can use that for reference for your own project. Tell me if you succeed on it, that's an interesting project =)

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX
Osman SOYKURT
ST Employee

Attached : Example.zip

Osman SOYKURT
ST Software Developer | TouchGFX

Hi Osman,

Thanks a lot for your help. One thing I am facing is that I want to keep the original text and want that text to be available in every font and that text is dynamic i.e., can be changed by the user.

I am thinking of using wildcard can that be possible? Is there any way to deal with this complexity? also if possible kindly point toward other methods to change the font.

Regards

-Arslan

Hi Arslan,

Yes you can totally use wildcard to do that. But remember to add the wildcard range to allow the letters you want, and this for each of your language/font.

0693W00000QKSG1QAP.png 

Then a simple strncpy would be enough.

    Unicode::strncpy(textArea1Buffer, "Hello Vivaldi", TEXTAREA1_SIZE);

0693W00000QKSH9QAP.png 

The other method I have in mind is to use binary fonts. We have an article about how to use it, I invite you to have a look at it 🙂

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

Thanks Alot Bro You're Great.

You're welcome !

Osman SOYKURT
ST Software Developer | TouchGFX