Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/gui/gui2_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ GuiElement* GuiElement::setMargins(float left, float top, float right, float bot
return this;
}

GuiElement* GuiElement::setParent(GuiContainer* new_parent)
{
if (GuiContainer* old_owner = this->getOwner())
{
// Works only if both the old owner and new parent are valid.
if (new_parent && old_owner != new_parent)
{
// Remove from old owner's children list.
old_owner->children.remove(this);

// Add to new owner's children list.
new_parent->children.push_back(this);

// Update owner pointer.
this->owner = new_parent;
}
else
LOG(Debug, "GuiElement::setParent called, but new parent is invalid.");
}
else
LOG(Debug, "GuiElement::setParent called, but old owner is invalid.");

return this;
}

GuiElement* GuiElement::setPosition(float x, float y, sp::Alignment alignment)
{
layout.position.x = x;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/gui2_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class GuiElement : public GuiContainer
GuiContainer* getTopLevelContainer();
const string& getID() { return id; }

// Change this element's owner/container safely (removes from old owner and adds to new owner)
GuiElement* setParent(GuiContainer* new_owner);

//Have this GuiElement destroyed, but at a safe point&time in the code. (handled by the container)
void destroy();

Expand Down
Loading