How to toggle button's visibility?

7 posts / 0 new
Last post
jap
jap's picture
Offline
Last seen: 9 months 2 weeks ago
Joined: 2011-06-04 05:53
How to toggle button's visibility?

Hi,

In ReAction GUI, is it possible to create a hidden button that can be made visible when needed?

What I'd like to do is to show an image button (busy indicator) when my program is processing data and then hide the button when the program has finished processing the data.

According to autodocs, gadgetclass has a boolean attribute GA_Hidden for hiding gadgets. However, that attribute doesn't seem to work for a button.gadget.

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 4 days ago
Joined: 2013-05-30 00:53
Re: How to toggle button's visibility?

Hi, you can try with GA_Disabled,TRUE/FALSE and see if it suits your needs.
Or just create the button object and use LM_ADDCHILD/LM_REMOVECHILD to show/hide button.

  1. /*
  2. OBJ(OBJ_BTN3) = IIntuition->NewObject(ButtonClass, NULL,
  3.   GA_ID, OBJ_BTN3,
  4.   GA_RelVerify, TRUE,
  5.   GA_Underscore, ~0,
  6.   BUTTON_BevelStyle, BVS_THIN,
  7.   //BUTTON_Transparent, TRUE,
  8.   BUTTON_RenderImage, OBJ(GID_KM3) = IIntuition->NewObject(BitMapClass, NULL,
  9.   IA_Width, IMG_W + 8,
  10.   IA_Height, IMG_H + 8,
  11.   IA_Scalable, dd->scaleflag > 1.0? TRUE:FALSE,
  12.   BITMAP_SourceFile, keymap2Flag,
  13.   BITMAP_Screen, dd->scr,
  14.   BITMAP_Masking, TRUE,
  15.   //BITMAP_Transparent,TRUE,
  16.   TAG_DONE),
  17.   TAG_DONE);
  18. ...
  19.   IIntuition->IDoMethod(OBJ(OBJ_MAIN), LM_ADDCHILD, window2, OBJ(OBJ_BTN3), NULL);

That is what I use in (sources included) http://www.os4depot.net/share/utility/docky/keymapswitcher_docky.lha

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

Rigo
Rigo's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2011-01-24 21:55
Re: How to toggle button's visibility?

You might also try the GA_Hidden tag, although I've never used it, or whether it even works for ReAction gadgets...

Simon

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: How to toggle button's visibility?

The GA_Hidden tag exists solely for use by page.gadget to tell if gadgets are on a page that is currently not visible and is not usable as a general mechanism for hiding objects in a layout.

It should however be possible to add/remove a gadget using the LM_ADDCHILD/LM_REMOVECHILD methods (make sure to also invoke the WM_RETHINK method on the window object afterwards). When removing use the CHILD_NoDispose tag (set to TRUE) if you don't want the gadget to be disposed.

jap
jap's picture
Offline
Last seen: 9 months 2 weeks ago
Joined: 2011-06-04 05:53
Re: How to toggle button's visibility?

The GA_Hidden tag made the button non-functional but it didn't hide it.

After various experiments I decided to hide the image button by changing its image to a transparent one. An info text should appear in place of the button when it's invisible. I thought I'd need to hide/remove the button and put a label in its place, but then I realised that I just needed to use a transparent image and set the button's text.

The only downside is that I can't display multiple text lines on the button.

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 4 days ago
Joined: 2013-05-30 00:53
Re: How to toggle button's visibility?

IIRC you can create an "image" of text using label.image class and the add it to the button as an image.

  1. ...
  2. Object *imageP = IIntuition->NewObject(LabelClass, NULL,
  3. IA_Font, // needs (struct TextAttr *)
  4. LABEL_DisposeImage,TRUE, LABEL_Underscore,0,
  5. LABEL_Text,"foo\nbar", TAG_END);

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: How to toggle button's visibility?

@jap

After various experiments I decided to hide the image button by changing its image to a transparent one.

But clicking on the (now invisible) button area will still generate Intuition input, right? That's not what you want.

In my GUIs, when I need to hide an element I usually use a page.gadget. The "dynamic" area of my window layout is represented by a page.gadget object with two alternating pages: one with all elements, and the other with the given element missing. When it's time to "hide" the element I simply switch the pages via SetAttrs() - not SetGadgetAttrs(), to avoid an unnecessary refresh - and then invoke WM_RETHINK on the window object.

The GA_Hidden tag made the button non-functional but it didn't hide it.

That's strange. Looks like a bug in button.gadget to me: the class should have ignored the unsupported tag.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

Log in or register to post comments