Bug in string.gadget/label.image

A forum for general AmigaOS 4.x support questions that are not platform-specific
Post Reply
User avatar
Raziel
Posts: 1170
Joined: Sat Jun 18, 2011 4:00 pm
Location: a dying planet

Bug in string.gadget/label.image

Post by Raziel »

The author of AmigaAmp found a discrepancy/bug in (what he believes) might be label.image (as child called from string.gadget).

If a (string.gadget) label gets renamed, the old name stays where it is and instead the new name is added to the end of it.

See the attached examples

In the picture you can see what happens after clicking a few times on "change".
Instead of changing the gadget label name to "string 3" it gets added to the end of "string2" (over and over again) which looks wrong.

This happens with both
label.image 53.14 and 47.5
string.gadget 53.22 and 47.22

Thank you for any pointers.
Attachments
LabelTest.lha
(7.66 KiB) Downloaded 192 times
LabelTest.png
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
TomSoniq
Posts: 13
Joined: Sun Jun 19, 2011 2:03 pm

Re: Bug in string.gadget/label.image

Post by TomSoniq »

Thanks Raziel for starting this thread. :D
Here are some more details.

What I do:
Call SetAttrs() for a label gadget with tag LABEL_Text = a new string (in this example "String _3").

What I'd expect:
The label changes from whatever it was before to "String _3".

What happens:
Each time I call SetAttrs() the string "String _3" is appended to the lebel's current text. :o

Can you please tell me...
  • if this is a bug or a feature?
  • if I'm doing something wrong?
  • how to do it right?
Thanks,
Tom
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: Bug in string.gadget/label.image

Post by javierdlr »

Hi, not sure if you can SetAttrs to a LABEL/CHILD object, maybe you need LM_MODIFYCHILD (layout autodocs). You can see an example in ReAction source examples Layout/dynamicexample.c
Attachments
dynamicexample_SRC.7z
dynamicexample.c
(2.22 KiB) Downloaded 219 times
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Bug in string.gadget/label.image

Post by broadblues »

TomSoniq wrote: Thu Jul 28, 2022 5:49 pm What I do:
Call SetAttrs() for a label gadget with tag LABEL_Text = a new string (in this example "String _3").

What I'd expect:
The label changes from whatever it was before to "String _3".
This is correct behaviour. You build up the lines of a label by adding multiple LABEL_Text call, each can have different styles applied, or you could have, text images text etc

If you want to replsce the label, you need to remove it and add a new one. Or use an alternate approach, for example the label could be a borferless readonly string gadet, or Spa e gadet with rendethook
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Bug in string.gadget/label.image

Post by broadblues »

BTW It's a, label.image not gadget.

Images an gadgets have differing behaviours, this being one of them....
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: Bug in string.gadget/label.image

Post by thomasrapp »

broadblues wrote: Fri Jul 29, 2022 12:41 am This is correct behaviour.
If this is true, it is bad and unintuitive design. A call to SetAttrs should always set the new value of the given attibute, replacing the old one.

If you want SetAttrs to append text to the label, then you should introduce a new tag which tells the developer what it does, for example LABEL_AppendText.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Bug in string.gadget/label.image

Post by broadblues »

thomasrapp wrote: Fri Jul 29, 2022 1:18 pm
broadblues wrote: Fri Jul 29, 2022 12:41 am This is correct behaviour.
If this is true, it is bad and unintuitive design. A call to SetAttrs should always set the new value of the given attibute, replacing the old one.

If you want SetAttrs to append text to the label, then you should introduce a new tag which tells the developer what it does, for example LABEL_AppendText.
You have a valid point, and I'm not defending the design, just explaining how it works :-)

Problem is this image has been about for ages, the design mistake predates OS4 by some time and even if the better named new tags were added, existing software would need the old behaviour to remain.

It *is* documented.
IA_Data (CONST_STRPTR)
LABEL_Text (CONST_STRPTR)
A text string to render. A '\n' in the string will cause the
text position to move to a new line. The first underscore ('_')
in the string will be used to underline the following character
in the string. Any number of text strings and images can be
provided in a label mixed at will.

Applicability is (OM_NEW)
LABEL_Image (struct Image *)
An image to render. Any number of text strings and images can
be provided in a label mixed at will.

Applicability is (OM_NEW)
Actually based on the documentation phrasing, you could argue that the tags should not be accepted by OM_SET at all, and the fact that it is, is a bug.

Personally I would not use a label for displaying dynamic content.
TomSoniq
Posts: 13
Joined: Sun Jun 19, 2011 2:03 pm

Re: Bug in string.gadget/label.image

Post by TomSoniq »

broadblues wrote: Mon Aug 01, 2022 6:28 pm Personally I would not use a label for displaying dynamic content.
Alright, good point.

Do you think it's worth a try using two different sting gadgets, each with its own static label, and only displaying one of them while removing the other?

Thanks,
Tom
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Bug in string.gadget/label.image

Post by broadblues »

TomSoniq wrote: Tue Aug 02, 2022 9:02 am
broadblues wrote: Mon Aug 01, 2022 6:28 pm Personally I would not use a label for displaying dynamic content.
Alright, good point.

Do you think it's worth a try using two different sting gadgets, each with its own static label, and only displaying one of them while removing the other?

Thanks,
Tom
I'm not 100% sure what you are trying to do. Why do you need to change the label on the string gadget?

If you have two different contexts (different file or media type perhaps?) where you need a slightly different GUI foreach one then yes, I would create two layouts, and use LM_ADDCHILD / LM_REMOVECHILD to switch them in and out. Remember to set CHILD_NoDispose to TRUE, otherwise the sublayouts will get disposed when you remove them.

I do this to display different pluging settings for the different tools in SketchBlock.
Post Reply