Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
63 user(s) are online (40 user(s) are browsing Forums)

Members: 1
Guests: 62

rjd324, more...

Headlines

 
  Register To Post  

[SOLVED] [Reaction] How to dynamically add Objects ?
Just can't stay away
Just can't stay away


See User information
Hi,
I am trying to dynamically add objects to my Reaction Layout but without success.

I read http://www.os4coding.net/forum/create-buttons-loop but I certainly missed something (I'm even worst on Reaction than I'm on MUI and Qt )

I'm trying to dynamically add 3 buttons AFTER that the window is created
but it displays me only the 2 first fixed buttons

I tried too to DoMethod(win, WM_RETHINK); after the setAttrs(LAYOUT_AddChild)...


Resized Image


I cross-posted this question on OS4Coding too

Thank you, by advance, for your help
Guillaume

void make_window()
{
 
win NewObject(NULL"window.class",         
        
WINDOW_Position,       WPOS_CENTERSCREEN,
        
WINDOW_Layout,         VLayoutObject,
 
 
         LAYOUT_AddChild
,  OBJ(OBJ_BUT_GRP) = HGroupObject,
            
LAYOUT_AddChild,  LayoutObject,
                
LAYOUT_VertAlignment,  LALIGN_CENTER,
                
LAYOUT_HorizAlignmentLALIGN_CENTER,
 
                LAYOUT_AddChild
,  OBJ(OBJ_IBUT_1) = ButtonObject,
                    
GA_ID,               OBJ_IBUT_1,
                    
GA_RelVerify,        TRUE,                
                    
BUTTON_BevelStyle,   BVS_NONE,
                    
BUTTON_Transparent,  TRUE,
                    
BUTTON_RenderImage,  OBJ(OBJ_SEL_1) = BitMapObject,
                        
BITMAP_SourceFile,         "images/pdf",
                        
BITMAP_DisabledSourceFile"images/pdf_g",
                        
BITMAP_Screen,             screen,
                        
BITMAP_Masking,            TRUE,
                    
BitMapEnd,
                    
BUTTON_SelectImage,  OBJ(OBJ_UNSEL_1) = BitMapObject,
                        
BITMAP_SourceFile,  "images/pdf_s",
                        
BITMAP_Screen,      screen,
                        
BITMAP_Masking,     TRUE,
                    
BitMapEnd,
                
ButtonEnd,
                
LAYOUT_AddChild,  OBJ(OBJ_IBUT_2) = ButtonObject,
                    
GA_ID,               OBJ_IBUT_2,
                    
GA_RelVerify,        TRUE,                
                    
BUTTON_BevelStyle,   BVS_NONE,
                    
BUTTON_Transparent,  TRUE,
                    
BUTTON_RenderImage,  OBJ(OBJ_SEL_2) = BitMapObject,
                        
BITMAP_SourceFile,         "images/picture",
                        
BITMAP_DisabledSourceFile"images/picture_g",
                        
BITMAP_Screen,             screen,
                        
BITMAP_Masking,            TRUE,
                    
BitMapEnd,
                    
BUTTON_SelectImage,  OBJ(OBJ_UNSEL_2) = BitMapObject,
                        
BITMAP_SourceFile,  "images/picture_s",
                        
BITMAP_Screen,      screen,
                        
BITMAP_Masking,     TRUE,
                    
BitMapEnd,
                
ButtonEnd,  
 
                LabelEnd
,  
 
            LayoutEnd
,
EndHGroup,
 
            CHILD_WeightedHeight
0,
 
        End
,   // VLayout
    
WindowEnd;
 
int x 
;
for(
03x++)
    {
        
Objects[x] = NewObject(NULL"button.gadget",
            
GA_ID,x,
            
GA_RelVerifyTRUE,
            
GA_Text,"xxx",
            
TAG_END);
 
        
if (Objects[x] == NULL
        {
            
DisposeObject(OBJ(OBJ_BUT_GRP));
            
Objects[OBJ_BUT_GRP] = NULL;
            return ;
        }
        
SetAttrs(OBJ(OBJ_BUT_GRP),
            
LAYOUT_AddChildObjects[x],
        
TAG_END);
        
printf("x %d \n",x);
    }
 
}


Edited by zzd10h on 2015/5/10 0:38:28
Edited by zzd10h on 2015/5/10 19:49:52
Go to top
Re: [Reaction] How to dynamically add Objects ?
Just can't stay away
Just can't stay away


See User information

Go to top
Re: [Reaction] How to dynamically add Objects ?
Amigans Defender
Amigans Defender


See User information
@zzd10h

You should be using the method rather than the tag under OS4. ie.

IDoMethod(OBJ(OBJ_BUT_GRP), LM_ADDCHILD,
   
windowObjects[x], NULL);


Then do:
FlushLayoutDomainCache(win);
RethinkLayout(winwindowNULLTRUE);


Where "window" is the Intuition Window pointer you get back when you open the window (can't see it in your code). You may be able to pass NULL if you've not opened the window yet, not sure.

Go to top
Re: [Reaction] How to dynamically add Objects ?
Just can't stay away
Just can't stay away


See User information
@Javier & Chris

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 !

Go to top
Re: [Reaction] How to dynamically add Objects ?
Just can't stay away
Just can't stay away


See User information
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 :)

Go to top
Re: [Reaction] How to dynamically add Objects ?
Amigans Defender
Amigans Defender


See User information
@zzd10h

Oh yes, my bad. I misread the source I was modifying and took what I changed to "win" to be the window object, when in fact it should have been the root layout object. I did wonder why it was originally cast to a struct Gadget *. Sorry for the confusion, glad you figured out the *ahem* delibrate mistake!

Go to top
Re: [Reaction] How to dynamically add Objects ?
Just can't stay away
Just can't stay away


See User information
@Chris

Héhé, no problem, thank you nevertheless for your help

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project