cancel
Showing results for 
Search instead for 
Did you mean: 

2 fonts for a text area

Professional
Senior

Hello

is it possible to set 2 fonts for a text, for exemple i have following text that must be i the middle of the screen:

<value>%

I want value wildcard to be in 17px and % char in 20px, is it possible ?

If it is not possible, i have to use 2 text areas;

How can i center these 2 text areas (how an i calculate the length...) ?

Thank for any support

Best regards

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

You can:

myTextArea.resizeToCurrentText(); 
myTextArea.getWidth();
 
//Or if your textarea is wider than your text string you can simply use
myTextArea.getTextWidth();

 So if you wanted to Center the concatenated text you would then add the lengths of the textareas together and use that to offset where to place the first textarea (followed by the rest). Something like:

uint16_t _length = ta1.getWidth() + ta2.getWidth() + ta3.getWidth();
 
ta1.setXY( HAL::DISPLAY_WIDTH /2 - _length / 2, ta1.getY()); 
ta2.setXY(ta1.getRect().right,......
 

Or yould use a Horizontal ListLayout to add the textareas one after the other...

View solution in original post

6 REPLIES 6
Martin KJELDSEN
Chief III

Hi @Professional​,

That's not possible. You'll have to create two seperate TextAreas. One Typography, One TextArea. We've considered doing something about that very recently.

/Martin

Martin KJELDSEN
Chief III

The downside to using multiple TextAreas is that you'll pay some memory for another TextArea instance. Your scenario is not one that we run into very often, but in some cases it's highly relevant.

Professional
Senior

Hello

thank you for your reply

How can i calculate the length of the 2 text areas so that i can center the whole concatanated text areas (each one with a different font) ?

Best regards

Martin KJELDSEN
Chief III

You can:

myTextArea.resizeToCurrentText(); 
myTextArea.getWidth();
 
//Or if your textarea is wider than your text string you can simply use
myTextArea.getTextWidth();

 So if you wanted to Center the concatenated text you would then add the lengths of the textareas together and use that to offset where to place the first textarea (followed by the rest). Something like:

uint16_t _length = ta1.getWidth() + ta2.getWidth() + ta3.getWidth();
 
ta1.setXY( HAL::DISPLAY_WIDTH /2 - _length / 2, ta1.getY()); 
ta2.setXY(ta1.getRect().right,......
 

Or yould use a Horizontal ListLayout to add the textareas one after the other...

Professional
Senior

Hello

thank a lot for your reply

Best regard

@Martin KJELDSEN​ 

I noticed you said "We've considered doing something about that very recently".

Is this still being considered?

Another thing I would like to be considered is being able to dynamically change the font of a specific textArea. Currently changing a font causes the changing all textArea's using that font.

My application will use wildcards more than anything else, so I need to be able to reduce size of the text of a specific textArea if the current font does not fit in that textArea (rather than changing the size of the text area itself).