# Layout

This type represents a layout control.

<figure><img src="/files/2DaEwiJDxH99FNWnybRY" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This type inherits [`ControlContainer`](/api/instances/gui/container/controlcontainer.md) type. All of its base methods and fields are also available in this type.
{% endhint %}

Layouts are used to override the menu's default stacking methods, such as stacking elements horizontally or in a grid. For example, putting two buttons together in the same line:

***

## \_\_call﻿ <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Constructor**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Constructs the layout.

**Arguments**

| Name        | Type                                                                                       | Description.                                         |
| ----------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------- |
| `id`        | [`ControlID`](/api/instances/gui/types/controlid.md)`\|string`                             | ID.                                                  |
| `position`  | [`Vec2`](/api/instances/draw/types/vec2.md)                                                | Position, offset from parent.                        |
| `size`      | [`Vec2`](/api/instances/draw/types/vec2.md)                                                | Size.                                                |
| `direction` | [`StackDirection`](/api/instances/gui/container/controlcontainer/layout/stackdirection.md) | The stacking method for elements inside this layout. |

**Returns**

| Type     | Description      |
| -------- | ---------------- |
| `Layout` | Layout instance. |

**Example**

```lua
local layout = gui.Layout('my_layout', draw.Vec2(), draw.Vec2(100, 24), 
    gui.StackDirection.INLINE);
    
layout.sizeToParentW = true -- Resizes layout width to parent groupbox.
    
local cb1, ctrl1 = gui.MakeControlEasy('my_cb1', 'Checkbox 1', 'checkbox')
local cb2, ctrl2 = gui.MakeControlEasy('my_cb2', 'Checkbox 2', 'checkbox')

layout:Add(ctrl1)
layout:Add(ctrl2)
```

***

## direction <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

The current direction for this layout.

***

## shouldClip <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Whether the layout should respect clipping or not.

***

## shouldCenterize <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Whether or not the layout should center elements or not. Only works for some stacking directions.

***

## stackInvisible <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Alternative stacking method

***

## showSpinner <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Puts a loading icon on top of the entire layout and blurs background. Useful for when menu items are still loading (e.g. grenade helper lists).

***

## stackOffset <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Field**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Type: [`Vec2`](/api/instances/draw/types/vec2.md)

Overrides the distance between elements inside the layout horizontally and vertically.

[^1]: This is a constructor definition for this type.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lua2.fatality.win/api/instances/gui/container/controlcontainer/layout.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
