Update CustomContainer children TouchGFX

1.7k Views Asked by At

if I have a CustomContainer with 2 Text Areas, is it possible to update the text for those text areas at run-time? please note that the custom container is in a scroll list.

1

There are 1 best solutions below

0
On

Yes it is possible. Maybe this late answer can help someone.

I have a screen with a list of custom widgets of actual failures. The custom container has 4 text areas: date, time, error component, error text. Here I set the texts in 3 ways, the text for date and time is generated from a numeric time value, the text for the caption is read from the resource, and the text for the error details text is read from the resource but values are filled in afterwards.

After the content on the screen is invalidated, either by scrolling or by calling invalidate, a callback function xxxUpdateItem is called automatically from touchgfx runtime. You have to override and implement it in your view class of the screen. This function is called with a reference to your custom widget and the actual index of the current item, like this:

void MessageScreenView::scrollList1UpdateItem(CustomContainerFailureOrInfo& item, int16_t itemIndex)  

From this you call a function of the custom widget which sets the new texts, e.g.:

void CustomContainerFailureOrInfo::setDetails(uint16_t itemIdx, uint32_t dateTime, uint16_t captionTextId, uint16_t detailTextId, const char16_t * templateF1, float f1, const char16_t * templateF2, float f2)
{
    setDateTime(dateTime);
    setCaption(captionTextId);
    setDetailText(detailTextId, templateF1, f1, templateF2, f2);
}

Text for Date and time is generated from a time_t value. The caption is read from the resource with the text widget's setTypedText function, e.g.:

void CustomContainerFailureOrInfo::setCaption(TypedTextId t)
{
    caption.setTypedText(TypedText(t));
    caption.setWideTextAction(WIDE_TEXT_WORDWRAP);
    caption.invalidate();
}

I had the problem, that some error messages should show error related values, while others should only show plein text. I solved it by using value wildcards and passing a format string and a value:

void CustomContainerFailureOrInfo::setDetailText(TypedTextId t, const char16_t * templateF1, float f1, const char16_t * templateF2, float f2)
{
    text.setTypedText(TypedText(t));
    Unicode::snprintf(textBuffer1, TEXTBUFFER1_SIZE, "");
    if (templateF1)
    {
        if (awiStrUtil::isPrintfFloatContained16(templateF1))
        {
            Unicode::snprintfFloat(textBuffer1, TEXTBUFFER1_SIZE, reinterpret_cast<const Unicode::UnicodeChar *> (templateF1), f1);
        }
        else
        {
            // attention: (const char16_t*)
            Unicode::snprintf(textBuffer1, TEXTBUFFER1_SIZE, reinterpret_cast<const Unicode::UnicodeChar *> (templateF1));
        }
    }
    // similar code removed: if (templateF2) ...
    text.setWideTextAction(WIDE_TEXT_WORDWRAP);
    text.invalidate();
}