GUI Parent/Child visibility
GUI Parent/Child visibility
Hi,
this is just a quick question about a problem I'm having.
I'd like to have a GUI element (an IGUIImage to be specific) as a parent for several buttons, in order to switch them on and off via only a single setVisibility() call to the parent image.
Now the parent image switches on/off just fine, however the child buttons are never to be seen, regardles of the parent's visibility state.
(They are seen when the parent is just set to NULL, so it's not the children's fault.)
Is there any way to make this work via parent-child relationships between GUI elements? (It works for windows. Calling setVisibility() for an IGUIWindow also disables all child elements.. or is this a special case for GUI elements?)
this is just a quick question about a problem I'm having.
I'd like to have a GUI element (an IGUIImage to be specific) as a parent for several buttons, in order to switch them on and off via only a single setVisibility() call to the parent image.
Now the parent image switches on/off just fine, however the child buttons are never to be seen, regardles of the parent's visibility state.
(They are seen when the parent is just set to NULL, so it's not the children's fault.)
Is there any way to make this work via parent-child relationships between GUI elements? (It works for windows. Calling setVisibility() for an IGUIWindow also disables all child elements.. or is this a special case for GUI elements?)
Wanted: Schrödingers Cat. Dead or alive.
It should already work by setting the parent visibility. Windows and images work the same in this regard (as does every other gui-element). I suppose there is some other problem in your code. If you post it we might be able to help.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Here goes:
All ommitted parameters are just constants which should be fine since all is displayed correctly, only the two elements don't seem to be linked.
(If this doesn't help, I can post the actual code as well.)
Code: Select all
// parent element
IGUIImage* parent = gui->addImage( rect<s32>(..),0,-1, .. );
parent->setVisible( false );
parent->setUseAlphaChannel( true );
// child element
IGUIButton* child = gui->addButton( rect<s32>(..), parent, .. );
child->setImage( .. );
child->setPressedImage( .. );
child->setDrawBorder( false );
child->setUseAlphaChannel( true );
Code: Select all
// event receiver part to toggle parent
if( <visible> )
parent->setVisible( false );
else
parent->setVisible( true );
(If this doesn't help, I can post the actual code as well.)
Wanted: Schrödingers Cat. Dead or alive.
Well, we can't test the code until it runs. So yes, actual code would be better. But maybe it's clipping. If the rect of your image is too small then the child-buttons might simply get clipped away.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ok, I simplified my example to a case that still doesn't work:
This should be correct, however only the parent rectangle is actually drawn.
When I change the following line:toThen both rectangles are drawn, and the only difference should be the parent-child link?
Code: Select all
// parent element
IGUIImage* parent = gui->addImage( rect<s32>(10,10,50,50),0 );
parent->setVisible( true );
parent->setUseAlphaChannel( true );
// child element
IGUIButton* child = gui->addButton( rect<s32>(50,50,90,90), parent);
child->setImage( driver->getTexture("textures/buttons/box_std.png") );
child->setPressedImage( driver->getTexture("textures/buttons/box_mc.png") );
child->setDrawBorder( false );
child->setUseAlphaChannel( true );
When I change the following line:
Code: Select all
IGUIButton* child = gui->addButton( rect<s32>(50,50,90,90), parent);
Code: Select all
IGUIButton* child = gui->addButton( rect<s32>(50,50,90,90), 0);
Wanted: Schrödingers Cat. Dead or alive.
Check the rect's. They are always relative to the parent so in this case the button is outside the parent area. So it will get clipped. Increase the image size and it should work.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien is right !!!
your image size is 40x40 and the button starts at position (50, 50) !!!
even if it was not relative to the parent your image ends at (50, 50) and the button starts at (50, 50) so the button could never be seen...
your image size is 40x40 and the button starts at position (50, 50) !!!
even if it was not relative to the parent your image ends at (50, 50) and the button starts at (50, 50) so the button could never be seen...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
ah nice, I had to figure out the same thing and now I read the solution.
But, is there any way to have the same parent-child behaviour like ISceneNodes have? Means, that I can have an IGUIElemtent as a child of another one but outside of the parents rect? So that the child-element moves along with the parent. Because I have some IGUIImages with captions and I dont want to calculate the coordinates of the text all the time I move the images.
greetings. Rob
But, is there any way to have the same parent-child behaviour like ISceneNodes have? Means, that I can have an IGUIElemtent as a child of another one but outside of the parents rect? So that the child-element moves along with the parent. Because I have some IGUIImages with captions and I dont want to calculate the coordinates of the text all the time I move the images.
greetings. Rob
Childs should already move with the parents. To have them drawn outside the parents rect you have to set childElemnt->setNotClipped(true).
I usually use another solution - I use a parent with a sufficiently large rect, but which is not drawing anything (like a statictext element without text, background and border).
I usually use another solution - I use a parent with a sufficiently large rect, but which is not drawing anything (like a statictext element without text, background and border).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm