2025-09-04 1:52 AM
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?
Solved! Go to Solution.
2025-09-08 7:05 AM
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
2025-09-04 10:06 AM
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
2025-09-08 7:05 AM
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
2025-09-08 7:18 AM
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