bookUI Reference

Reference notes and patterns for CSL UI drawing.

This page collects UI rules, patterns, and examples that are helpful once you know the basics.

Read UI Fundamentals first.

Core principles

  1. Y grows upward. Screen coordinates use (0, 0) at the bottom-left.

  2. Start from screen rects. Use UI.get_safe_screen_rect() or UI.get_screen_rect(), then derive everything from those rects.

  3. Push/pop pattern. Use defer for every push to avoid leaking UI state.

  4. Mobile-first. Avoid hover-only interactions.

  5. ASCII only. No emoji or Unicode in UI text.

  6. UI must render in ao_late_update. This is required for correct interaction.

Quick start: a simple HUD button

Player :: class : Player_Base {
    ao_late_update :: method(dt: float) {
        if this->is_local_or_server() {
            draw_my_hud(this);
        }
    }
}

draw_my_hud :: proc(player: Player) {
    rect := UI.get_safe_screen_rect()
        ->bottom_right_rect()
        ->grow(40, 150, 40, 150)
        ->offset(-50, 50);

    bs := UI.default_button_settings();
    ts := UI.default_text_settings();

    if UI.button(rect, bs, ts, "Action").clicked {
        do_action(player);
    }
}

Basic drawing

Quads and images

Text

Layouting: start from rects

Use cut for layout

The cut functions must be used for layouting when placing multiple UI elements:

Auto-scaling and unscaled rects

Rect functions are scaled by UI.get_current_scale_factor() (based on 1080p).

If you need exact pixel values, use the _unscaled variants:

Buttons

Button sprite rules

You must use one of these sprites when drawing buttons:

  • "$AO/new/modal/buttons_2/button_1.png" (Orange)

  • "$AO/new/modal/buttons_2/button_2.png" (Green)

  • "$AO/new/modal/buttons_2/button_3.png" (Red)

  • "$AO/new/modal/buttons_2/button_5.png" (Blue)

  • "$AO/new/modal/buttons_2/button_7.png" (Pink)

  • "$AO/new/modal/buttons_2/button_8.png" (Grey)

  • "$AO/new/modal/buttons_2/button_9.png" (White)

UI state management

Use defer for every push/pop pair:

IDs for repeated elements

When drawing lists or repeated items, push unique IDs:

Common sizes

Some sizes that are known to look good across devices:

  • Text: Title 52, Body 36, World space text 0.30

  • Rects: Simple dialog 600x400, Standard button 210x74, Exit button 65x65

Best practices

  • Use defer for every push/pop pair.

  • Push IDs for repeated elements.

  • Use unscaled functions with computed dimensions.

  • Fit icon aspect ratios with rect->fit_aspect(texture->get_aspect()).

  • Always check is_local_or_server() before drawing interactive UI.

Last updated