2019-10-28 06:34 AM
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
Solved! Go to Solution.
2019-11-04 02:25 AM
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...
2019-10-31 06:32 AM
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
2019-10-31 06:33 AM
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.
2019-10-31 06:58 AM
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
2019-11-04 02:25 AM
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...
2019-11-06 12:43 AM
Hello
thank a lot for your reply
Best regard
2020-03-04 07:38 AM
@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).