UI 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
Y grows upward. Screen coordinates use (0, 0) at the bottom-left.
Start from screen rects. Use
UI.get_safe_screen_rect()orUI.get_screen_rect(), then derive everything from those rects.Push/pop pattern. Use
deferfor every push to avoid leaking UI state.Mobile-first. Avoid hover-only interactions.
Text uses UTF-8, but character coverage is incomplete. A character still needs a glyph in the selected font or its fallback fonts. Some characters, including emoji, are not supported yet.
Use the player late-update stack. Draw all player UI from that player's
ao_late_updateunderis_local_or_server().
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 {
log_info("action from %", {player.get_username()});
}
}Basic drawing
Quads and images
Filled quads
Pass Quad_Params.fill from UI.quad_fill to reveal only part of a quad. The available Fill_Direction values are .NONE, .RIGHT, .LEFT, .UP, .DOWN, and .RADIAL.
Linear fills use amounts from 0 to 1. Radial fills start at 12 o'clock and use a signed amount: -1..0 fills counterclockwise and 0..1 fills clockwise. Values outside the applicable range are clamped. A zero radial amount draws nothing; -1 and 1 both draw the complete quad.
For a changing fill, keep a persistent Float_Interpolation_Helper and pass its result to UI.quad_fill. Clamp before calling update; preserving the sign is required for counterclockwise radial fills. Use UI.push_fill_amount and UI.pop_fill_amount instead when the same fill should apply to several draw calls. Always pair the push with a deferred pop.
Text
Layout: 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
Regular rect functions take points and scale them by UI.get_current_scale_factor() (based on a 1080-point-tall reference canvas).
Use the _unscaled variants only when a value is already expressed in actual screen pixels, such as a dimension measured from an existing rect:
Buttons
Button sprite rules
UI.default_button_settings() already provides a complete button style. For a custom button, set sprite and optionally sprite_hovered and sprite_pressed. When the optional sprites are null, the base sprite is reused.
Modals
Use UI.begin_modal / UI.end_modal for a dimmed backdrop that closes when the player taps outside the modal or presses Escape.
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:
Screen text points: Title 52, Body 36
Screen rect points: Simple dialog 600x400, Standard button 210x74, Exit button 65x65
World-space text size: 0.30 meters
Best practices
Use
deferfor 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