I know this is not technical the correct place but I’m not a member on any other programming forum so am hopping you can help me out. I have the follow code.
uicomponates.Add(
new UiFrame("design", ScreenHelper.Size, AnchorState.All)
{
BgColour = Color.Transparent, //dont display the background
Componates = new List<UiClass>()
{
new Button("bntOk", new Vector2(100,50), parent),
}
});
Now what I am trying to do is pass in the uifram class in to the button class where you see the variable ‘parent’
Now I know I can do this another way by create the Uiframe. Then create the button and pass uiframe in.
What I am interested in is if there is any way to do it in the above method?
Is your question: how to make an object be aware of its parent ?
What are you using for your UI ? Without information it is hard to tell, some libraries provide some mechanisms to achieve this.
It would be easier and less error prone if you do what you suggest: create Uiframe, then Button. This way you will avoid many mistakes (this ? Parent ? etc).
Not in the manner you describe above. Create them separately.
var uiFrame = new UiFrame("design", ScreenHelper.Size, AnchorState.All)
{
BgColour = Color.Transparent, //dont display the background
Componates = new List<UiClass>();
};
var button = new Button("bntOk", new Vector2(100,50), uiFrame);
Ideally, the Button constructor would add itself to the parent since the parent has been passed to it.
On my GUI implementation parent child have a relationship definition:
it will be nice if you can inquire any GUI if it is a parent or not, if child GUI you can
inquire the parent.
If an item has a parent, IsChild is useless. Same goes for IsParent, if it has children.
Unless IsChild and IsParent are properties, checking Children and Parent != null/none.
Like this they seems to be duplicates to me.