# Cheat sheets

> Pocket reference — add() signatures by layout, Relative, ARGB colors and threading.

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

# Cheat sheets

The most frequent decisions, condensed. All snippets compile against the 2026 API.

## Layouts — `add()` signature
```java
// VerticalLayout / HorizontalLayout — first the size, then the component
add(LAY_FILL, comp);   // -1f → fills the remaining space (the "elastic")
add(LAY_AUTO, comp);   //  0f → content's natural size
add(0.2f, comp);       // >0  → 20% of the container's total dimension

// GridLayout — ALL the widths, then ALL the components
add(0.35f, 0.65f, new Label("Nome"), new TextField(""));

// EvenlySpacedLayout — only the component (spaces evenly; does not size)
add(icone1); add(icone2);

// RelativeLayout — anchors (see matrix below)
add(comp, RelPos.AFTER, RelPos.CENTER_OF, RelSize.AUTOSIZE, RelSize.AUTOSIZE, refComp);
```
Detail per layout: [`ui/layouts/`](/docs/ui/layouts).

## RelativeLayout — matrix
```java
add(alvo, RelPos x, RelPos y, RelSize larg, RelSize alt [, Component ref] [, Gap outgap]);
```
| `RelPos` (position) | `RelSize` (size) |
|---|---|
| `START` · `CENTER` · `END` · `AFTER` · `BEFORE` | `AUTOSIZE` (content) |
| `CENTER_OF` · `END_OF` · `SAMEPOS` | `FILL` (parent − margin) · `FIT` (edge→ref) |
| `AUTOPOS` · `AUTOPOSCENTERED` · `KEEPPOS` | `SAMESIZE` · `KEEPSIZE` |

## Relative — responsive dimensions
```java
Relative.ofFont(1.5f);                     // 1.5 × font height (scales with the UI)
Relative.ofScreen(0.8f);                   // 80% of the screen
Relative.ofScreen(0.5f, ScreenSize.MIN);   // 50% of the SMALLER side (adapts portrait/landscape)
Relative.ofPixels(24f);                    // fixed pixel (use as an exception)
```

## Colors — ARGB `0xAARRGGBB`
```java
int opaco     = 0xFF2196F3;                       // alpha FF = fully visible
int invisivel = 0x002196F3;                       // ⚠️ alpha 00 → does NOT appear
int meio      = ColorUtils.withAlpha(0xFF2196F3, 128);  // 50% transparent
int escuro    = ColorUtils.darker(0xFF2196F3, 0.2f);
int claro     = ColorUtils.lighter(0xFF2196F3, 0.2f);
int mistura   = ColorUtils.lerpColor(corA, corB, 0.5f);
```
> **Alpha trap:** an `int` without the alpha byte (`0xRRGGBB`) has alpha 0 → the component becomes
> **invisible**. Always include `0xFF...` for opaque.

## Threading — return/run
```java
Component.onUI(() -> { ... });               // returns to the paint thread (from any thread)
Main.runOnPaintThread(() -> { ... });         // same, outside of a Component
Main.runOnPaintThreadAndWait(() -> { ... });  // same, blocking until it finishes
comp.onActionThread(c -> { ... });            // reacts to an event on a background thread
Component.repaint();                          // requests a new frame (render on demand)
```
Why: [The paint thread](/docs/concepts/the-paint-thread).

## See also
- [Enums and `UIConstants`](/docs/reference/enums-uiconstants) · [Layouts](/docs/ui/layouts) · Colors (Ch. 11)
