Text and formatting#

The four text widgets#

Call

Style

Lines

Use it for

ui_heading(text)

ui_style_heading

Wrapped

Section titles. The default theme draws a line under it

ui_text(text)

ui_style_text

Wrapped

Paragraphs

ui_caption(text)

ui_style_caption

Wrapped

Notes and help in a muted color

ui_label(text)

ui_style_text

One

Values, list cells, anything that must stay on one line

None of them take focus. Their text is copied when the frame is recorded, so it can live on the stack or come from ui_fmt.

Wrapping#

ui_text, ui_heading and ui_caption wrap at spaces to the width of their column. A \n in the string starts a new line. A word is split only when it is wider than the whole line.

ui_text("Its screen is 320 by 240 pixels.\nCEUI draws into the second half of video memory.");

Lines outside a scroll area’s visible part are measured but not recorded, so long text in a scroll area costs little to draw.

Labels and the ellipsis#

ui_label draws one line. When the text does not fit, it is cut and ends with an ellipsis. Use it for cells in lists and tables, and for values that must not push the layout down.

In a column set to UI_AUTO, a label, a text or a button is as wide as its text.

A quote style with a border on the left, centered text, a label with an ellipsis and a caption

The end of the Reading screen: a quote, centered text, a label cut with an ellipsis, and a caption.#

Alignment, size and color#

Alignment, font and colors come from the style. To change them for one widget, give it another style with ui_next_style:

const ui_style_t style_center = {UI_DEFAULT_TEXT, .text = UI_ALIGN_CENTER};
const ui_style_t style_large = {UI_DEFAULT_TEXT, .text = UI_FONT(1)};
const ui_style_t style_quote = {UI_DEFAULT_TEXT, .border = UI_BORDER(2, UI_LEFT), .pad = UI_PAD(6, 0),
                                .c[UI_NORMAL] = {.fg = UI_MUTED, .hi = UI_ACCENT, .lo = UI_ACCENT}};

ui_next_style(&style_center);
ui_text("Centered text wraps too, and every line is centered on its own.");

Centered and right aligned text is aligned line by line. Font 1 in the default theme is the graphx font at twice its size. See styling for fonts and the style record.

The Reading screen with large text

The same page with style_large on every paragraph.#

Text in containers#

Text takes its color from the style first, and from the container when the style leaves the color at 0. That is how a label in a selected list row turns white on the accent color without any code: the row’s focus colors flow down to the text in it. A caption has its own color for that case too.

Formatting numbers with ui_fmt#

CEUI has no printf. ui_fmt formats into a small rotating buffer and returns it, so any widget can take formatted text:

ui_label(ui_fmt("%u KB free", kb));
ui_caption(ui_fmt("%lu of %lu bytes", done, total));
ui_titlebar("Files", ui_fmt("%d files", count));

Specifier

Argument

%s

const char *. NULL prints nothing

%c

char

%d

int

%u

unsigned

%x

unsigned, in lower case hex

%ld, %lu, %lx

long, unsigned long

%%

A percent sign

There are no widths, padding, precision or floating point. Any other character after % is printed as it is.

The result is at most UI_FMT_SIZE - 1 characters (63 by default) and is cut there. ui_fmt cycles through UI_FMT_SLOTS buffers (4 by default), so up to four results can be used at once, for example as arguments of the same call. A fifth call reuses the first buffer. Copy the result with strcpy if you need to keep it longer than that.

ui_confirm(&open, "Create account", ui_fmt("Create an account for %s, age %d?", name, age), "Create");

Characters#

The built-in fonts are 8 pixels high and cover ASCII. There are no accented letters.