> For the complete documentation index, see [llms.txt](https://docs.perfectcs2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.perfectcs2.com/documentacao/api/ui.md).

# ui

Criar opções no menu.

As funções `ui.*` criam opções que aparecem na aba **Scripts**, em **Opções**, quando o script está selecionado. Elas têm o mesmo visual dos cards nativos do Perfect.

Cada função devolve um **objeto da opção**. Com ele você lê o valor (`:get()`), muda (`:set()`), esconde, bloqueia e reage a mudanças. Veja [Métodos das opções](/documentacao/tipos/opcoes.md).

```lua
ui.group("Crosshair", "Lines at the center of the screen")
local enabled = ui.toggle("Enabled", "Draw the crosshair", true)
local size    = ui.slider("Size", "Length of each line", 2, 20, 6, "%.0f px")

if enabled:get() then print("size " .. size:get()) end
```

Em todas as funções, `label` é o nome da linha e `description` é o texto menor embaixo dele. `description` pode ser `""` ou `nil`.

***

## ui.group

```lua
ui.group(title, [description])
```

Começa um card novo. As opções criadas depois entram nele, até o próximo `ui.group`. Sem nenhum grupo, as opções vão para um card chamado **Options**.

| Parâmetro     | Tipo   |                                    |
| ------------- | ------ | ---------------------------------- |
| `title`       | string | Título do card, na cor de destaque |
| `description` | string | Linha embaixo do título            |

***

## ui.toggle

```lua
local option = ui.toggle(label, description, [default], [color])
```

Um switch liga/desliga. Com `color`, aparece também um seletor de cor na mesma linha, como no ESP do Perfect.

| Parâmetro | Tipo                                  | Padrão  |                        |
| --------- | ------------------------------------- | ------- | ---------------------- |
| `default` | boolean                               | `false` | Se começa ligado       |
| `color`   | [color](/documentacao/tipos/color.md) | sem cor | Cor inicial do seletor |

`option:get()` devolve `boolean`, e também a `color` quando a opção tem cor.

```lua
local box = ui.toggle("Box", "Box around the enemy", true, color(255, 140, 40))
local on, clr = box:get()
```

***

## ui.slider / ui.slider\_int

```lua
local option = ui.slider(label, description, min, max, [default], [format])
local option = ui.slider_int(label, description, min, max, [default], [format])
```

Um controle deslizante. `slider` aceita números com vírgula e `slider_int` só inteiros.

| Parâmetro    | Tipo   | Padrão            |                                                                                     |
| ------------ | ------ | ----------------- | ----------------------------------------------------------------------------------- |
| `min`, `max` | number |                   | Limites; `max` deve ser maior que `min`                                             |
| `default`    | number | `min`             | Valor inicial, limitado a `min`–`max`                                               |
| `format`     | string | `"%.1f"` / `"%d"` | Como o valor é mostrado, no formato do `string.format`. Ex.: `"%.0f px"`, `"%d%%"`. |

`option:get()` devolve `number` (`slider`) ou `integer` (`slider_int`).

***

## ui.combo

```lua
local option = ui.combo(label, description, items, [default])
```

Uma lista em que se escolhe um item.

| Parâmetro | Tipo              | Padrão |                                                                      |
| --------- | ----------------- | ------ | -------------------------------------------------------------------- |
| `items`   | tabela de strings |        | Os itens, na ordem                                                   |
| `default` | string ou número  | 1      | Nome do item (sem diferenciar maiúsculas) ou posição, começando em 1 |

`option:get()` devolve **o nome** do item escolhido e a posição dele.

```lua
local style = ui.combo("Style", "", { "Cross", "Dot", "T-Shape" }, "Dot")
local name, index = style:get()  -- "Dot", 2
style:set("T-Shape")             -- or style:set(3)
```

***

## ui.multiselect

```lua
local option = ui.multiselect(label, description, items, [selected])
```

Vários itens podem ficar marcados ao mesmo tempo. A linha mostra os escolhidos, como "Head, Chest", e a engrenagem abre um switch para cada item.

| Parâmetro  | Tipo              | Padrão |                            |
| ---------- | ----------------- | ------ | -------------------------- |
| `items`    | tabela de strings |        | Os itens                   |
| `selected` | tabela de strings | nenhum | Itens que começam marcados |

| Uso                               | Resultado                                        |
| --------------------------------- | ------------------------------------------------ |
| `option:get()`                    | Tabela com os nomes marcados, na ordem dos itens |
| `option:get("Head")`              | `boolean`: esse item está marcado?               |
| `option:set({ "Head", "Chest" })` | Marca só esses                                   |
| `option:set("Legs", true)`        | Marca ou desmarca um item                        |

***

## ui.color

```lua
local option = ui.color(label, description, [color])
```

Um seletor de cor com transparência; o padrão é branco. `option:get()` devolve uma [color](/documentacao/tipos/color.md).

***

## ui.keybind

```lua
local option = ui.keybind(label, description, [key])
```

A pessoa clica e aperta uma tecla ou botão do mouse. Enquanto ele espera a tecla, Esc cancela e Backspace limpa. Com uma tecla escolhida, passar o mouse mostra um `x` que limpa.

| Parâmetro | Tipo   | Padrão  |                                                                                                         |
| --------- | ------ | ------- | ------------------------------------------------------------------------------------------------------- |
| `key`     | string | nenhuma | Tecla inicial, como `"F7"`, `"Mouse4"` ou `"LeftShift"`. Veja [Nomes de teclas](/referencia/teclas.md). |

| Uso                   | Resultado                              |
| --------------------- | -------------------------------------- |
| `option:get()`        | Nome da tecla (`"MouseX1"`) ou `nil`   |
| `option:is_down()`    | `true` enquanto a tecla está apertada  |
| `option:is_pressed()` | `true` só no frame em que foi apertada |

```lua
local hotkey = ui.keybind("Hotkey", "Turns it on and off", "F7")
callbacks.add("draw", function()
    if hotkey:is_pressed() then print("pressed") end
end)
```

***

## ui.button

```lua
local option = ui.button(label, description, [on_click], [text])
```

Um botão na linha. `on_click` recebe o objeto do botão. `text` é o que aparece no botão (padrão **Run**). `option:get()` devolve quantas vezes ele foi clicado.

```lua
ui.button("Reset", "Clears the counter", function()
    storage.set("kills", 0)
end, "Reset")
```

***

## ui.textbox

```lua
local option = ui.textbox(label, description, [text], [max_length])
```

Um campo de texto na linha.

| Parâmetro    | Tipo    | Padrão |                                 |
| ------------ | ------- | ------ | ------------------------------- |
| `text`       | string  | `""`   | Texto inicial                   |
| `max_length` | integer | 128    | Máximo de caracteres (1 a 1024) |

`option:get()` devolve `string`.

***

## ui.text

```lua
local option = ui.text(label, [description])
```

Uma linha só com texto, sem controle. Serve para mostrar informações que mudam: `option:set("new title")` troca o título e `option:description("…")` troca a descrição.

```lua
local status = ui.text("Kills", "0 so far")
status:description("5 so far")
```

***

## ui.separator

```lua
ui.separator()
```

Uma separação mais forte entre as linhas do card atual.


---

# 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.perfectcs2.com/documentacao/api/ui.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.
