# C API: Player screens: the quick creator and the wardrobe picker

Two ready-made screens a game opens and gets an avatar back from: the quick creator (eight generated looks, pick one, change one thing, done) and the wardrobe picker (an outfit for this match from the player's own wardrobe, or the catalogue under the host's filter, with a live try-on). The host draws a screen from its node list; input arrives as actions from any device. The guide, with the flow, the controls, the drawing contract and the numbers, is [Quick creator and wardrobe](../../guides/quick-creator.md).

Structs: `sona_screen_event` (48 bytes), `sona_screen_theme` (96, 88 with 4-byte pointers), `sona_screen_node` (112, 92), `sona_quick_options` (96, 72), `sona_wardrobe_options` (128, 84), `sona_screen_stats` (108). `sona_screen` is opaque. A screen is used from the ctx's owner thread and destroyed before its ctx.

## sona_screen_theme_defaults

```c
void sona_screen_theme_defaults(sona_screen_theme *t, uint32_t preset);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `t` | `sona_screen_theme *` | The [`sona_screen_theme`](../fields.md#sona_screen_theme) to fill with the defaults | required |
| `preset` | `uint32_t` | Which preset, one of the header's constants for it | - |

**Returns** Nothing.

**Example**:

```c
sona_screen_theme x_screen_theme;
memset(&x_screen_theme, 0, sizeof x_screen_theme);
x_screen_theme.size = sizeof x_screen_theme;
sona_screen_theme_defaults(&x_screen_theme, 0);
```

`SONA_THEME_DARK`, `SONA_THEME_LIGHT` (the editor module's own palettes) or `SONA_THEME_CONTRAST` (black, white and yellow, with `SONA_THEME_HIGH_CONTRAST` set). `size` set, scale 1, corner 10.

## sona_quick_defaults

```c
void sona_quick_defaults(sona_quick_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_quick_options *` | The [`sona_quick_options`](../fields.md#sona_quick_options) to fill with the defaults | required |

**Returns** Nothing.

**Example**:

```c
sona_quick_options x_quick_options;
memset(&x_quick_options, 0, sizeof x_quick_options);
x_quick_options.size = sizeof x_quick_options;
sona_quick_defaults(&x_quick_options);
```

`size` set, seed 1, 8 looks, both bodies, no flags. Set `catalogue` before opening.

## sona_quick_open

```c
sona_result sona_quick_open(sona_ctx *ctx, const sona_quick_options *o, sona_screen **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_quick_options *` | The options, a [`sona_quick_options`](../fields.md#sona_quick_options) | required |
| `out` | `sona_screen **` | Receives the new screen | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY` ([what each means](../../troubleshooting.md#error-codes)).

The quick creator; its eight looks start building at once, hidden from `sona_draw`. `SONA_E_ARGUMENT` without a catalogue, for `looks` outside 2..8 or `body` over 2; `SONA_E_NOT_FOUND` when the catalogue after the filter has no hair, clothes or shoes for a body it needs.

## sona_quick_look

```c
sona_result sona_quick_look(const sona_quick_options *o, uint32_t shuffle, uint32_t index, uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `const sona_quick_options *` | The options, a [`sona_quick_options`](../fields.md#sona_quick_options) | required |
| `shuffle` | `uint32_t` | How many times the player asked for new looks | - |
| `index` | `uint32_t` | Which one, from 0 | - |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [The quick creator and the wardrobe picker](../../guides/quick-creator.md)):

```c
/* catalogue, filter, seed set */
typedef struct quick_hook {
  sona_quick_options o;
  uint64_t first;
} quick_hook;
static int quick_looks(void *user, uint64_t seed, uint32_t index, uint8_t manifest[SONA_MANIFEST_BYTES]) {
  quick_hook *h = (quick_hook *)user;
  return sona_quick_look(&h->o, (uint32_t)(seed - h->first), index, manifest) == SONA_OK;
}
/* sona_editor_options: .seed = h.first = h.o.seed, .look = quick_looks, .look_user = &h, the same .filter */
```

Look `index` of the set the seed and `shuffle` (X presses so far) make, without a screen or a ctx: the same bytes the screen shows. A screen re-rolls a look whose items are missing from the sources; that one then differs. The editor module's `look` hook takes it in one line (the guide shows it).

## sona_wardrobe_defaults

```c
void sona_wardrobe_defaults(sona_wardrobe_options *o);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `o` | `sona_wardrobe_options *` | The [`sona_wardrobe_options`](../fields.md#sona_wardrobe_options) to fill with the defaults | required |

**Returns** Nothing.

**Example** (also in [The quick creator and the wardrobe picker](../../guides/quick-creator.md)):

```c
sona_wardrobe_options wo;
sona_wardrobe_defaults(&wo);
wo.manifest = my_avatar;            /* the player's own, SONA_MANIFEST_BYTES; only clothes change */
wo.catalogue = cat;
wo.owned = owned; wo.owned_count = n;   /* the player's wardrobe; NULL: the catalogue's items for this body */
wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names;   /* saved outfits, first tab */
wo.filter = my_content_filter;
wo.title = "Dress for the match";
sona_wardrobe_open(ctx, &wo, &s);
```

`size` set, `flags` `SONA_WARDROBE_STOCK`. Set `manifest` and `catalogue` before opening.

## sona_wardrobe_open

```c
sona_result sona_wardrobe_open(sona_ctx *ctx, const sona_wardrobe_options *o, sona_screen **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `ctx` | `sona_ctx *` | The context | required |
| `o` | `const sona_wardrobe_options *` | The options, a [`sona_wardrobe_options`](../fields.md#sona_wardrobe_options) | required |
| `out` | `sona_screen **` | Receives the new screen | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_FOUND`, `SONA_E_MEMORY`, `SONA_E_MANIFEST` ([what each means](../../troubleshooting.md#error-codes)).

**Example** (also in [The quick creator and the wardrobe picker](../../guides/quick-creator.md)):

```c
sona_wardrobe_options wo;
sona_wardrobe_defaults(&wo);
wo.manifest = my_avatar;            /* the player's own, SONA_MANIFEST_BYTES; only clothes change */
wo.catalogue = cat;
wo.owned = owned; wo.owned_count = n;   /* the player's wardrobe; NULL: the catalogue's items for this body */
wo.outfits = saved_outfits; wo.outfit_count = 3; wo.outfit_names = names;   /* saved outfits, first tab */
wo.filter = my_content_filter;
wo.title = "Dress for the match";
sona_wardrobe_open(ctx, &wo, &s);
```

The wardrobe picker on the player's manifest. Its lists, outfits and names are copied. Only clothes change. `SONA_E_ARGUMENT` without a manifest or catalogue (or a count without its array), `SONA_E_MANIFEST` for a manifest that does not parse.

## sona_screen_destroy

```c
void sona_screen_destroy(sona_screen *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |

**Returns** Nothing.

Removes the screen's avatars from the ctx and frees it. NULL does nothing.

## sona_screen_kind

```c
uint32_t sona_screen_kind(const sona_screen *s);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |

**Returns** `uint32_t`.

`SONA_SCREEN_KIND_QUICK` or `SONA_SCREEN_KIND_WARDROBE`; 0 for NULL.

## sona_screen_layout

```c
sona_result sona_screen_layout(sona_screen *s, uint32_t width, uint32_t height);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

The host's size in pixels, 64 to 16384 a side: a wide layout when `width >= height`, a tall one otherwise. Default 1280 x 720. May change at any time.

## sona_screen_set_theme

```c
sona_result sona_screen_set_theme(sona_screen *s, const sona_screen_theme *t);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `t` | `const sona_screen_theme *` | A [`sona_screen_theme`](../fields.md#sona_screen_theme) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

Copies the theme; the next nodes use it.

## sona_screen_input

```c
sona_result sona_screen_input(sona_screen *s, const sona_screen_event *in);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `in` | `const sona_screen_event *` | A [`sona_screen_event`](../fields.md#sona_screen_event) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

One event: `SONA_INPUT_PRESS` and `_RELEASE` of a `sona_screen_action`, pointer moves, presses and releases, scrolls, and the turn axis. Held directions and tabs repeat by themselves (after a set 0.36 s, then every 0.085 s) until released. `SONA_E_ARGUMENT` for a bad event; a finished screen ignores input.

## sona_screen_update

```c
sona_screen_status sona_screen_update(sona_screen *s, double dt_seconds);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `dt_seconds` | `double` | Seconds since the last update | - |

**Returns** `sona_screen_status`.

Repeats, turning, the screen's avatars (a rebuilt one replaces the shown one when READY) and the screen's own timers. Call it after `sona_update`. Returns `SONA_SCREEN_RUNNING`, `_DONE`, `_CANCELLED` or `_FINE_TUNE`, and keeps returning a finished status. NULL: `_CANCELLED`.

## sona_screen_nodes

```c
uint32_t sona_screen_nodes(sona_screen *s, sona_screen_node *out, uint32_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `out` | `sona_screen_node *` | Receives the [`sona_screen_node`](../fields.md#sona_screen_node) | `NULL` allowed (below) |
| `cap` | `uint32_t` | How many entries `out` holds | `NULL` allowed (below) |

**Returns** `uint32_t`.

What to draw, in paint order, with roles, states, boxes in pixels, text and spoken labels; writes up to `cap` (`out` may be NULL) and returns how many there are. Strings live until the next call on the screen.

## sona_screen_announcement

```c
int sona_screen_announcement(sona_screen *s, char *out, size_t cap);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `out` | `char *` | Receives the text, NUL-terminated | required |
| `cap` | `size_t` | How many bytes `out` holds | - |

**Returns** `int`.

The oldest thing a screen reader should say (eight are kept): 1 when one was written (cut at `cap`), 0 when none.

## sona_screen_result

```c
sona_result sona_screen_result(const sona_screen *s, uint8_t manifest[SONA_MANIFEST_BYTES]);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `manifest` | `uint8_t [SONA_MANIFEST_BYTES]` | The manifest's 1,000 bytes, changed in place | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](../../troubleshooting.md#error-codes)).

The avatar the player has now. The quick creator answers `SONA_E_NOT_READY` before a pick; a cancelled wardrobe answers the manifest it opened with.

## sona_screen_stats_get

```c
void sona_screen_stats_get(const sona_screen *s, sona_screen_stats *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `out` | `sona_screen_stats *` | Receives the [`sona_screen_stats`](../fields.md#sona_screen_stats) | required |

**Returns** Nothing.

Presses (repeats not counted), taps, changes, shuffles, focus moves, the seconds from open to finish and the presses of each action.

## sona_screen_owns

```c
int sona_screen_owns(const sona_screen *s, const sona_avatar *a);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `a` | `const sona_avatar *` | The avatar | required |

**Returns** `int`.

1 when `a` is one of the screen's avatars, for hosts that read `sona_poll_event`.

## sona_screen_view_avatar

```c
sona_avatar *sona_screen_view_avatar(const sona_screen *s, int32_t view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `const sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |

**Returns** `sona_avatar *`.

The avatar a node's `view` shows now, or NULL. It may change between frames.

## sona_screen_view_camera

```c
sona_result sona_screen_view_camera(sona_screen *s, int32_t view, uint32_t width, uint32_t height, sona_view *out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `s` | `sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `out` | `sona_view *` | Receives the [`sona_view`](../fields.md#sona_view) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY` ([what each means](../../troubleshooting.md#error-codes)).

The view's camera for a `width` x `height` picture (the figure fills the height, turned by the player), for hosts that draw through the data API. `SONA_E_NOT_READY` before READY.

## sona_screen_view_draw

```c
sona_result sona_screen_view_draw(sona_renderer *r, sona_screen *s, int32_t view, const sona_target *target,
                                  const sona_draw_options *opts);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `s` | `sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |
| `target` | `const sona_target *` | Where the frame lands, a [`sona_target`](../fields.md#sona_target) | required |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](../fields.md#sona_draw_options) | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](../../troubleshooting.md#error-codes)).

`sona_draw` of that view alone into `target`. `SONA_E_NOT_READY` while it has nothing to draw.

## sona_screen_view_snapshot

```c
sona_result sona_screen_view_snapshot(sona_renderer *r, sona_screen *s, int32_t view, uint32_t width, uint32_t height,
                                      const sona_draw_options *opts, uint8_t *rgba_out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `r` | `sona_renderer *` | The renderer | required |
| `s` | `sona_screen *` | The screen | required |
| `view` | `int32_t` | Which of the screen's avatar views | - |
| `width` | `uint32_t` | The picture's width in pixels | - |
| `height` | `uint32_t` | The picture's height in pixels | - |
| `opts` | `const sona_draw_options *` | The options, a [`sona_draw_options`](../fields.md#sona_draw_options) | required |
| `rgba_out` | `uint8_t *` | Receives straight RGBA8, row 0 at the top: `width * height * 4` bytes | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT`, `SONA_E_NOT_READY`, `SONA_E_MEMORY`, `SONA_E_CONTEXT`, `SONA_E_READBACK` ([what each means](../../troubleshooting.md#error-codes)).

`sona_snapshot` of that view alone, straight RGBA8.
