How would I go about changing the below code to have each button be made in a loop with custom details (text, id, etc)?
if (!(Objects[GAD_BUTTONS_GROUP]=HGroupObject, LAYOUT_SpaceOuter, TRUE, LAYOUT_SpaceInner, TRUE, LAYOUT_AddChild, Objects[GAD_BUTTON1]=NewObject(ButtonClass,NULL, GA_ID, GAD_BUTTON1, GA_RelVerify, TRUE, GA_Text, "Button 1", TAG_END), LAYOUT_AddChild, Objects[GAD_BUTTON2]=NewObject(ButtonClass,NULL, GA_ID, GAD_BUTTON2, GA_RelVerify, TRUE, GA_Text, "Button 2", TAG_END), LAYOUT_AddChild, Objects[GAD_BUTTON3]=NewObject(ButtonClass,NULL, GA_ID, GAD_BUTTON3, GA_RelVerify, TRUE, GA_Text, "Button 3", TAG_END), EndHGroup)) return(FALSE); else return(TRUE);
Start with the HGroupObject.
Go through a for(...) loop to make each button.
Finish with EndHGroup.
if (!(Objects[GAD_BUTTONS_GROUP]=HGroupObject, LAYOUT_SpaceOuter, TRUE, LAYOUT_SpaceInner, TRUE, for(x=0; x<3; x++) { LAYOUT_AddChild, Objects[x]=NewObject(ButtonClass,NULL, GA_ID, x, GA_RelVerify, TRUE, GA_Text, Text[x], TAG_END), } EndHGroup)) return(FALSE); else return(TRUE);
THEN...later on how would I add another button to the end, and remove a button.
You can use LAYOUT_AddChild with SetAttrs():
Thanks. I figured it out after some sleep. Very similar to yours.
I changed the group settings to no space
When there is a button added to the group all is fine.
When there are no buttons added to the group, it still adds 2 vertical lines, even though the group is empty. Can a group have a space of 0 horiz and vert?
Actually it is
Can a LayoutClass not be 0x0 if nothing is in it?
Hi,
I'm a newbie in Reaction but I tried to use this snippet in my code without luck.
It displays only my fixed bitmap/buttons
I tried too to DoMethod(win, WM_RETHINK);...
Thank you for your help
In this code, the first 2 fixed buttons are well displayed but not the 3 dynamic last ones.
Hi I add a button to my already "created" ReAction window object (Object *win2;) this way:
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Thank you very much,
IDoMethod(OBJ(OBJ_BUT_GRP), LM_ADDCHILD, window, OBJ(OBJ_BUT), NULL);
DoMethod(win, WM_RETHINK);
works well.
But it works only with fix name objects, not in a "for" loop with Objects[x].
Thank you again !
Jabirulo fixed my problem.
He changed
WINDOW_Layout, VLayoutObject,
by
WINDOW_Layout, OBJ(OBJ_MAIN) = NewObject(NULL, "layout.gadget"
IDoMethod(OBJ(OBJ_MAIN), LM_ADDCHILD, window, OBJ(OBJ_BTN), NULL);
Thank you very much, Javier, very kind :)
But this adds the buttons to the vertical main group and not to the horizontal button group where they should appear.
Moreover LM_ADDCHILD is only needed if the window is already open. If you define the buttons before the window opens you can use SetAttrs as you did before.
Anyway here is a working example: http://thomas-rapp.homepage.t-online.de/examples/dyngrp.c
Thank you for your help, thomas.
It works well, buttons are well displayed horizontally or vertically by using the same
LAYOUT_Orientation for WINDOW_Layout and Button_Group layout.
WINDOW_Layout, OBJ(OBJ_MAIN) = NewObject(NULL, "layout.gadget",
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
LAYOUT_AddChild, OBJ(OBJ_BUT_GRP) = HGroupObject,
LAYOUT_AddChild, LayoutObject,
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
If the main group is horizontal then your entire GUI is horizontal, you are not able to place objects below that group. And of course your OBJ_BUT_GRP group becomes superfluous because it remains empty.
Yes, you are right for OBJ_BUT_GRP... And unfortunately for me, you are right too for orientation...
My window is very simple, empty and HORIZontal
When I try to insert 2 objects vertically aligned in this window (even the "parent" VERT layout OBJ_LAYOUT is useless), they are displayed horizontally.
Vertical orientation, all is OK
Is somebody know a way to insert a VGroup in an HGroup window/Layout ?
Thank you by advance ;)
See my example above.
Certainly that I missed something in your example, but I tried to reproduce it, it's the same problem.
My window is horizontal.
My objects are added horizontally. I would like that they were added by 2 by 2 vertically.
picture above his label | picture above his label | picture above his label ...
now there are
picture | label | picture | label | picture | label ...
Following, I think, your example, I tried
Thank you very much for your help.
Ok, now I understand, I didn't get your problem before.
A layout group can have only one orientation. If you want another orientation inside, you have to add another group or groups.
So what you have to do in your for() loop is to create a VGroup containing a Button and its Label and add that VGroup to the main HGroup.
Is it not what I tried here ?
http://www.os4coding.net/forum/create-buttons-loop#comment-2284
In this code, I added the 3 objects (VLayout, Button and Label) but I had tried to add only the VLayout without more luck.
Thank you for your patience.
This code does some bad things.
The first thing is very bad. You add the same buttons to two groups. This cannot work. An object can only be part of one group at a time. If you add it to another group without removing it first, it corrupts list pointers. It's pure luck that your test didn't crash.
The second thing you probably didn't notice or drew the wrong conclusion. You use a button object with CHILD_Label. This cannot work, either. CHILD_Label expects to get an object of a sub-class of imageclass, but buttons are objects of gadgetclass (that's why it's called button.gadget and not button.image).
If you want to use a button as a label, you should use LAYOUT_AddChild. If you insist on CHILD_Label, then you should use label.image instead of button.gadget.
But using CHILD_Label is part of your problem. Layout.gadget places the CHILD_Label always left or right of the object (depending on the value of LAYOUT_LabelColumn), never above or below. If you want the text to respect LAYOUT_Orientation, you have to use LAYOUT_AddChild or LAYOUT_AddImage (depending on whether you want to add a gadget or an image object).
Here is a new example with icons and labels below them: http://thomas-rapp.homepage.t-online.de/examples/iconbar.c
Thank you very much Thomas for your explanations and example.
Using it,
It works !