# Folhas de cola

> Referência de bolso — assinaturas de add() por layout, Relative, cores ARGB e threading.

Source: https://crossfly.dev/pt/docs/reference/cheat-sheets — CrossFly documentation. Full docs as one file: https://crossfly.dev/llms-full.txt

# Folhas de cola

As decisões mais frequentes, condensadas. Todos os trechos compilam contra a API 2026.

## Layouts — assinatura de `add()`
```java
// VerticalLayout / HorizontalLayout — primeiro o tamanho, depois o componente
add(LAY_FILL, comp);   // -1f → preenche o espaço restante (o "elástico")
add(LAY_AUTO, comp);   //  0f → tamanho natural do conteúdo
add(0.2f, comp);       // >0  → 20% da dimensão total do contêiner

// GridLayout — TODAS as larguras, depois TODOS os componentes
add(0.35f, 0.65f, new Label("Nome"), new TextField(""));

// EvenlySpacedLayout — só o componente (espaça igualmente; não dimensiona)
add(icone1); add(icone2);

// RelativeLayout — âncoras (ver matriz abaixo)
add(comp, RelPos.AFTER, RelPos.CENTER_OF, RelSize.AUTOSIZE, RelSize.AUTOSIZE, refComp);
```
Detalhe por layout: [`ui/layouts/`](/docs/ui/layouts).

## RelativeLayout — matriz
```java
add(alvo, RelPos x, RelPos y, RelSize larg, RelSize alt [, Component ref] [, Gap outgap]);
```
| `RelPos` (posição) | `RelSize` (tamanho) |
|---|---|
| `START` · `CENTER` · `END` · `AFTER` · `BEFORE` | `AUTOSIZE` (conteúdo) |
| `CENTER_OF` · `END_OF` · `SAMEPOS` | `FILL` (pai − margem) · `FIT` (borda→ref) |
| `AUTOPOS` · `AUTOPOSCENTERED` · `KEEPPOS` | `SAMESIZE` · `KEEPSIZE` |

## Relative — dimensões responsivas
```java
Relative.ofFont(1.5f);                     // 1,5 × altura da fonte (escala com a UI)
Relative.ofScreen(0.8f);                   // 80% da tela
Relative.ofScreen(0.5f, ScreenSize.MIN);   // 50% do MENOR lado (adapta portrait/landscape)
Relative.ofPixels(24f);                    // pixel fixo (use por exceção)
```

## Cores — ARGB `0xAARRGGBB`
```java
int opaco     = 0xFF2196F3;                       // alpha FF = totalmente visível
int invisivel = 0x002196F3;                       // ⚠️ alpha 00 → NÃO aparece
int meio      = ColorUtils.withAlpha(0xFF2196F3, 128);  // 50% transparente
int escuro    = ColorUtils.darker(0xFF2196F3, 0.2f);
int claro     = ColorUtils.lighter(0xFF2196F3, 0.2f);
int mistura   = ColorUtils.lerpColor(corA, corB, 0.5f);
```
> **Armadilha do alpha:** um `int` sem o byte de alpha (`0xRRGGBB`) tem alpha 0 → o componente fica
> **invisível**. Sempre inclua `0xFF...` para opaco.

## Threading — voltar/rodar
```java
Component.onUI(() -> { ... });               // volta à paint thread (de qualquer thread)
Main.runOnPaintThread(() -> { ... });         // idem, fora de um Component
Main.runOnPaintThreadAndWait(() -> { ... });  // idem, bloqueando até terminar
comp.onActionThread(c -> { ... });            // reage a um evento numa thread de fundo
Component.repaint();                          // pede um novo frame (render sob demanda)
```
Por quê: [A paint thread](/docs/concepts/the-paint-thread).

## Veja também
- [Enums e `UIConstants`](/docs/reference/enums-uiconstants) · [Layouts](/docs/ui/layouts) · Cores (Cap. 11)
