Change label for a string.gadget dynamically (after window is opened)
Post date
Sat, 08/17/2024 - 10:28
I have a very special case where the label text of a string.gadgets CHILD_label
should be changed after the window is open. For this purpose I set a GA_Id
for the CHILD_label
. Here is how the string.gadget and its the CHILD_label
are craeted:
...
LAYOUT_AddChild, m_ppGadgets[GID_STRING_INPUT] = NewObject(STRING_GetClass(), NULL,
GA_ID, GID_STRING_INPUT,
GA_ReadOnly, TRUE,
GA_RelVerify, TRUE,
GA_TabCycle, TRUE,
ICA_TARGET, ICTARGET_IDCMP,
TAG_DONE),
CHILD_Label, m_ppGadgets[GID_LABEL_LONGEST_ITEM] = NewObject(LABEL_GetClass(), NULL,
GA_ID, GID_LABEL_LONGEST_ITEM,
LABEL_Text, (ULONG)"Abcdefg",
TAG_DONE),
...
At a later point the window is opened:
pIntuiWindow = (struct Window*) DoMethod(pWinObject, WM_OPEN, NULL)
And after this was successful, I want to change the label text:
if(pIntuiWindow)
{
SetGadgetAttrs((struct Gadget *) m_ppGadgets[GID_LABEL_LONGEST_ITEM], pIntuiWindow, NULL,
LABEL_Text, (ULONG)"The proper label text",
TAG_DONE);
}
The window opens, but the displayed label text still is "Abcdefg".
So, (how) can the label text be changed dynamically?
Online Status
A label is meant to be immutable so it is not meant to be changed. The label is an image rather than a gadget and, as you can see in the autodocs, nothing can be set after it is originally rendered.
You could remove and add the label with updated text and then refresh, but that is very heavy on the system.
The best thing to do is use something like a button gadget with no bevel that you do not allow to be selected and does not show highlighting. That can then have its text updated via GA_Text.