cancel
Showing results for 
Search instead for 
Did you mean: 

box resize but fill colour does not change

Eddie1066
Associate II

I'm using a coloured box as a background for some dynamic text. I would like the background to match the width of the text when it changes.
I can change the width of the box to match the text width, but the box's fill colour will not fill to match the new box width.

This is the code I'm using.

memset(&textValueBuffer, 0, sizeof(textValueBuffer));
Unicode::fromUTF8((const uint8_t*)it->second.data(), textValueBuffer, it->second.length());
textValue.resizeToCurrentText();
textValue.invalidate();

box1.setWidth(textValue.getWidth());
box1.invalidate();

 Is this possible in TouchGFX?

1 ACCEPTED SOLUTION

Accepted Solutions
JohanAstrup
ST Employee

Hello @Eddie1066.

I tried the following, which works for me.

box1.invalidate();

if (textArea1.getTypedText().getId() == T_SHORTTEXT)
{
	textArea1.setTypedText(T_LONGTEXT);
}
else
{
	textArea1.setTypedText(T_SHORTTEXT);
}

textArea1.resizeToCurrentText();
box1.setWidth(textArea1.getWidth());
box1.invalidate();

Could you share your project? It does not make sense to me that your procedure does not work when the width of the text area is properly updated.

Best regards,
Johan

View solution in original post

3 REPLIES 3
JTP1
Lead

Hello

Try to invalidate textValue and box1 also BEFORE risizing them. It might be needed especially if you make text shorter.

Hope this helps.

Br JTP

 

JohanAstrup
ST Employee

Hello @Eddie1066.

I tried the following, which works for me.

box1.invalidate();

if (textArea1.getTypedText().getId() == T_SHORTTEXT)
{
	textArea1.setTypedText(T_LONGTEXT);
}
else
{
	textArea1.setTypedText(T_SHORTTEXT);
}

textArea1.resizeToCurrentText();
box1.setWidth(textArea1.getWidth());
box1.invalidate();

Could you share your project? It does not make sense to me that your procedure does not work when the width of the text area is properly updated.

Best regards,
Johan

I managed to track down the issue. It was my error; my boxes had slightly similar names, which meant I was making changes to the wrong box. Thank you for your time and effort; it is much appreciated.

Much thanks,

Eddie