cancel
Showing results for 
Search instead for 
Did you mean: 

Fine-tuning Text Positions in Different Fonts and Resolving TypedText Validity Issues

ouchou
Associate

I need to fine-tune the positions of text in different fonts. The method I have in mind is to create a setPosition function in TextArea.hpp. Inside this function, I obtain the FontId through this, and then set a fixed offset value according to the FontId.

 

 

void setPosition(int16_t x, int16_t y, int16_t width, int16_t height) { int new_Y = y; if(this->getTypedText().hasValidId()) { int fontId =this->getTypedText().getFontId(); } if(fontId ==0) { new_Y+= offset1; }else if(fontId ==1){ new_Y+= offset2; }else if(fontId ==2){ new_Y+= offset3; }else if(fontId ==3){ new_Y+= offset4; }else if(fontId ==4){ new_Y+= offset5; }else if(fontId ==5){ new_Y+= offset6; }else{ // } Drawable::setPosition(x, new_Y, width, height); }

 

 

 

Now, my problem is that many TextArea's hasValidId in the screen are false. As a result, the positions of many text areas cannot be set again. If I don't confirm through hasValidId, the following error will occur.

File: C\git\07\..\EWARM/../Middlewares/ST/touchgfx/framework/include\touchgfx\TypedText.hpp Line: 109 The expression failed: hasValidId()& "typedTextId larger than numberOfTypedTexts."

My question is, is it possible to set TypedText to a proper value for TextArea? How to set it? Thank you.

 

 

1 REPLY 1

Hi

Not sure, if I fully understand. Could you do something like:

if (!this->getTypedText().hasValidId())
{
   Drawable::setPosition(x,y,width,height);
}
else
{
   // calculate offset and setPosition
   int ynew = ...
   Drawable::setPosition(x, ynew, width, height);
}

Otherwise, create an empty text (just space) for all your typographies and set them on the textarea. Then you never have an invalid textid.
Could you share why you need to fine tune? Are you aligning different fonts?