# Hojas de referencia rápida

> Referencia de bolsillo — firmas de add() por layout, Relative, colores ARGB y threading.

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

# Hojas de referencia rápida

Las decisiones más frecuentes, condensadas. Todos los fragmentos compilan contra la API 2026.

## Layouts — firma de `add()`
```java
// VerticalLayout / HorizontalLayout — primero el tamaño, luego el componente
add(LAY_FILL, comp);   // -1f → llena el espacio restante (el "elástico")
add(LAY_AUTO, comp);   //  0f → tamaño natural del contenido
add(0.2f, comp);       // >0  → 20% de la dimensión total del contenedor

// GridLayout — TODOS los anchos, luego TODOS los componentes
add(0.35f, 0.65f, new Label("Nome"), new TextField(""));

// EvenlySpacedLayout — solo el componente (espacia por igual; no dimensiona)
add(icone1); add(icone2);

// RelativeLayout — anclas (ver matriz abajo)
add(comp, RelPos.AFTER, RelPos.CENTER_OF, RelSize.AUTOSIZE, RelSize.AUTOSIZE, refComp);
```
Detalle 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` (posición) | `RelSize` (tamaño) |
|---|---|
| `START` · `CENTER` · `END` · `AFTER` · `BEFORE` | `AUTOSIZE` (contenido) |
| `CENTER_OF` · `END_OF` · `SAMEPOS` | `FILL` (padre − margen) · `FIT` (borde→ref) |
| `AUTOPOS` · `AUTOPOSCENTERED` · `KEEPPOS` | `SAMESIZE` · `KEEPSIZE` |

## Relative — dimensiones responsivas
```java
Relative.ofFont(1.5f);                     // 1,5 × altura de la fuente (escala con la UI)
Relative.ofScreen(0.8f);                   // 80% de la pantalla
Relative.ofScreen(0.5f, ScreenSize.MIN);   // 50% del lado MENOR (adapta portrait/landscape)
Relative.ofPixels(24f);                    // píxel fijo (usar por excepción)
```

## Colores — ARGB `0xAARRGGBB`
```java
int opaco     = 0xFF2196F3;                       // alpha FF = totalmente visible
int invisivel = 0x002196F3;                       // ⚠️ alpha 00 → NO 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);
```
> **Trampa del alpha:** un `int` sin el byte de alpha (`0xRRGGBB`) tiene alpha 0 → el componente queda
> **invisible**. Incluye siempre `0xFF...` para opaco.

## Threading — volver/ejecutar
```java
Component.onUI(() -> { ... });               // vuelve al paint thread (desde cualquier thread)
Main.runOnPaintThread(() -> { ... });         // ídem, fuera de un Component
Main.runOnPaintThreadAndWait(() -> { ... });  // ídem, bloqueando hasta terminar
comp.onActionThread(c -> { ... });            // reacciona a un evento en un thread de fondo
Component.repaint();                          // pide un nuevo frame (render bajo demanda)
```
Por qué: [El paint thread](/docs/concepts/the-paint-thread).

## Ver también
- [Enums y `UIConstants`](/docs/reference/enums-uiconstants) · [Layouts](/docs/ui/layouts) · Colores (Cap. 11)
