Configuration#

CEUI’s buffers and limits are fixed sizes, so it never allocates memory. You can change them with -D in your program’s CFLAGS, set before include vendor/ceui/ui.mk:

CFLAGS = -Wall -Wextra -Oz -DUI_COMMANDS=4096 -DUI_SLOTS=20
include vendor/ceui/ui.mk
include $(shell cedev-config --makefile)

The same values are used by CEUI’s sources and by your theme, so always set them in CFLAGS, never with a #define in one file.

Macro

Default

Meaning

UI_SLOTS

16

Palette entries CEUI owns, at the top of the palette. Raise it to get your own slots

UI_COMMANDS

3072

Bytes per page of the base command stream. There are two pages

UI_OVERLAY_COMMANDS

1024

Bytes per page of the overlay stream (modals, menus, toasts). There are two pages

UI_FOCUSABLES

48

Focusable widgets per frame. Widgets past this number cannot be reached with the arrows

UI_DEPTH

8

Container nesting, the screen included

UI_COLUMNS

8

Columns per row

UI_LAYERS

4

Modals and menus open at once

UI_SCROLLS

8

Scroll areas per frame

UI_FONTS

4

Entries in ui_fonts

UI_FMT_SLOTS

4

Buffers ui_fmt cycles through

UI_FMT_SIZE

64

Bytes per ui_fmt buffer, terminator included

UI_TOAST_MS

2000

How long a toast stays, in milliseconds

UI_TOAST_SIZE

48

Bytes of toast text, terminator included

UI_REPEAT_DELAY_MS

400

Time a key is held before it starts to repeat

UI_REPEAT_MS

60

Time between repeats

UI_DEBUG

off

Prints each frame’s buffer use and dirty rectangles through dbg_printf

Sizing the command buffers#

Every widget records a few commands into the command stream: a frame, its text, a glyph. Text is copied into the command, so long paragraphs use more. Commands outside the current clip, like lines of a scroll area that are not visible, are not recorded.

When a buffer fills up, the rest of that stream is dropped for the frame and the next frame is redrawn in full. A screen that loses its last widgets, or redraws in full on every key, has run out of command buffer. Build with -DUI_DEBUG and run it in CEmu or CEbox to see how full the buffers get. Each frame prints lines like these to the emulator’s debug console:

frame base=2148 over=0 rects=2
 0,18 320x32
 0,50 320x16

base and over are the bytes used in the base and overlay streams, and each following line is a rectangle that was redrawn. Raise UI_COMMANDS or UI_OVERLAY_COMMANDS until the largest screen fits with room to spare. Remove UI_DEBUG for release builds.

RAM#

Buffer

Default size

Command pages, base and overlay

2 × (3072 + 1024) = 8 KB

Focus table

About 1 KB

Everything else

About 2 KB

That is 11.1 KB of .bss in total with the defaults, and no heap. The back buffer CEUI draws into is the second half of video memory, which 8 bits per pixel mode leaves free, so it costs no RAM.