# Parent

### Introduction

The `Parent` variable allows UI elements to be positioned and sized according to other UI elements. Parenting hierarchies can go many levels deep and the parent/child relationship can be visualized by the white line connecting the parent to the child when the child is selected.

### Parents and Units

Parents control control the position of their children. Parents can also control the size of their objects depending on the child's `Width Units` and `Height Units`.

For example, if a parent is moved, its children move along with it. For more information on positioning children, see the [X Units](https://docs.flatredball.com/gum/gum-tool/gum-elements/general-properties/x-units) and [Y Units](https://docs.flatredball.com/gum/gum-tool/gum-elements/general-properties/y-units) pages.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-9594e3c953497628469b5d38b7e7b2704276a997%2F07_06%2043%2054.gif?alt=media" alt=""><figcaption><p>Moving a parent also moves its children</p></figcaption></figure>

Children can also be sized according to their parents. For more information on sizing children according to their parent, see the [Width Units](https://docs.flatredball.com/gum/gum-tool/gum-elements/general-properties/width-units) and [Height Units](https://docs.flatredball.com/gum/gum-tool/gum-elements/general-properties/height-units) pages.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-b9ebe6cb4c34954097917d7e76cd8fbb0777005c%2F07_06%2045%2058.gif?alt=media" alt=""><figcaption><p>Children can be resized according to their parent</p></figcaption></figure>

### Children Outside of Parent Bounds

Children can be placed outside of their parent's bounds. In the simplest case, a child can be dragged outside of its parent's bounds in the editor.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-e8eba406a5f0ffb63347ee160a5d01abc3e6a357%2F07_06%2048%2001.gif?alt=media" alt=""><figcaption><p>Children can be placed outside of their parents' bounds</p></figcaption></figure>

Children outside of their parent's bounds still follow all of the same rules for sizing and positioning, but there are some important things to keep in mind.

Children placed outside of a parent do not affect the parent's effective width or height. Any unit value that depends on children or parents only considers the **immediate child or parent** and does not look at sizes beyond the immediate relationship.

For example if a parent has 100 effective width, and its child is given an `X` of 200, the parent's effective width remains 100 (assuming the parent does not size itself according to its children). This is important when other children are sized or positioned according to the parent's width.

The following animation shows three instances:

1. A parent container
2. A blue rectangle which is sized according to the parent rectangle
3. A yellow rectangle which is moved outside of the bounds of its parent

Notice that when the parent resizes the blue rectangle is also resized, but when the yellow rectangle is moved outside of the parent bounds, the parent and blue rectangle are not resized.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-681ff67a4b61e4a7bc2202e44a2214a7bc10532c%2F07_06%2055%2018.gif?alt=media" alt=""><figcaption><p>Children can exist outside of the parent bounds without resizing the parent</p></figcaption></figure>

Children outside of bounds may not respond to click events unless the parent is explicitly checking for click events outside of its bounds. This is a property which is set at runtime. For more information see the [RaiseChildrenEventsOutsideOfBounds](https://docs.flatredball.com/gum/code/gum-code-reference/interactivegue/raisechildreneventsoutsideofbounds) page.

### Example - Drag+Drop in the Tree View

To change `Parent` in the **Project** tab:

1. Select a child
2. Drag+drop the child onto the desired parent

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-6dc353377d8417ab91ab2801b7caf00307011928%2F11_20%2021%2041.gif?alt=media" alt=""><figcaption><p>Drag+drop a child onto the desired parent</p></figcaption></figure>

The child can be detached from its `Parent` by drag+dropping it onto the Component.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-526675dc9bf454c153f9a8f025e1571349387045%2F11_20%2022%2036.gif?alt=media" alt=""><figcaption><p>Drag+drop a child onto its root component or screen to detach it from its current parent</p></figcaption></figure>

Drag+dropping onto a parent may set the `Parent` property to an instance inside of the parent's Component type sets its Default Child Container value. For more information see the [Default Child Container](https://docs.flatredball.com/gum/gum-tool/gum-elements/component/default-child-container) page.

### Example - Using the Dropdown

To set Parent by name:

1. Select the desired child
2. Change the `Parent` property to the desired parent:

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-ca94612839d289a082f2c9f182c47bf1e293a409%2F11_20%2020%2004.gif?alt=media" alt=""><figcaption><p>Change Parent using the dropdown</p></figcaption></figure>
