Skip to main content
Associate II
September 4, 2025
Solved

box resize but fill colour does not change

  • September 4, 2025
  • 2 replies
  • 459 views

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?

Best answer by JohanAstrup

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

2 replies

Graduate II
September 4, 2025

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

 

JohanAstrupBest answer
ST Employee
September 8, 2025

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

Eddie1066Author
Associate II
September 8, 2025

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