> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/about/layout-overview.md).

# Layout Overview

## Introduction

Gum provides a flexible layout engine for creating responsive UI. Gum objects can be docked, anchored, stacked, wrapped, positioned, and sized dynamically.

Layouts can be performed quickly using common containers such as StackPanel. Dock and Anchor methods can be used to position objects relative to their parent container. Individual *unit* values can be used to fine-tune the position of objects.

## Parent/Child Relationship

Gum objects can be added to other Gum objects to create parent/child relationships. For example, the following shows two rectangles inside a parent container. Notice that the rectangles are positioned relative to the parent's position.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-ef434798b0e9700d43b90c3e616ae27b65790b44%2F15_10%2025%2052.gif?alt=media" alt=""><figcaption><p>Children are positioned relative to their parent</p></figcaption></figure>

Hierarchies can be many levels deep, allowing for complex, reactive layouts. Multiple containers can be used to adjust how different areas of a component react to changes in size.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-be904b8a1ba038164a2eb56d3c2645244d55e02d%2F15_10%2038%2015.gif?alt=media" alt=""><figcaption></figcaption></figure>

## Dock and Anchor

Gum objects can be docked and anchored to create common layout behaviors.

Anchor adjusts the position of objects so that they reset against the sides, corners, or center of their 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-bcf523376c717612f102e15aff70062d7e167025%2F15_16%2056%2039.png?alt=media" alt=""><figcaption></figcaption></figure>

Dock adjusts the position and size of an object so it sits against one or more edges of its parent. Docking can be used to adjust the width an object and also anchor it to the top or bottom.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-15ffe43ce52d1e73400389d6374e27fc6f98677e%2F15_17%2000%2023.png?alt=media" alt=""><figcaption></figcaption></figure>

Similarly, Dock can be used to adjust an object vertically and optionally anchor it to the left or right.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-395029fc5fcaacd8fc9d2c6cd365c2cafbbae3f0%2F15_17%2003%2014.png?alt=media" alt=""><figcaption></figcaption></figure>

## Units and Origins

Objects have the following Units and Origin values which provide more fine-tuned control over positioning and sizing. For example, an object can be positioned under its parent with the following code:

```csharp
buttonInstance.Dock(Dock.Bottom);
// after docking, set the YOrigin to Top, resulting in the button's 
// top being docked to the bottom of its 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-19d2f29adf50d18f28c4be7c8b4e7bc4cefcd997%2F15_17%2011%2010.png?alt=media" alt=""><figcaption></figcaption></figure>

## Container Stack and Grid

Parent containers can stack, wrap, and arrange their children in a grid.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-04e32a4220a2df8258c1b703fb52a034453c3f98%2F15_17%2030%2053.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/about/layout-overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
