Theme header#

ui_theme.h holds the style types, the palette roles and the declarations every theme defines. ui.h includes it. themes/default.h holds the default values a theme starts from. See styling and themes.

Sizes#

UI_SLOTS#

#define UI_SLOTS 16

The number of palette entries CEUI owns, at the top of the palette. Override it with -DUI_SLOTS=n in CFLAGS to get slots of your own past UI_ROLES.

UI_FONTS#

#define UI_FONTS 4

The number of entries in ui_fonts. Override it with -DUI_FONTS=n.

UI_PALETTE_BASE#

#define UI_PALETTE_BASE (256 - UI_SLOTS)

The palette index of slot 0. Slot n is palette entry UI_PALETTE_BASE + n. Sprites should use only entries below it.

UI_NONE#

#define UI_NONE 0xFF

A color that means transparent: nothing is drawn for that field.

UI_GLYPH_SIZE#

#define UI_GLYPH_SIZE 8

Glyphs are UI_GLYPH_SIZE by UI_GLYPH_SIZE pixels, one byte per row, highest bit on the left.

Style field macros#

UI_BORDER#

#define UI_BORDER(width, sides) ((uint8_t)((width) << 4 | (sides)))

The border field: a width of 0 to 3 pixels on the given sides.

UI_PAD#

#define UI_PAD(x, y) ((uint8_t)((x) << 4 | (y)))

The pad field: space inside the border, 0 to 15 pixels horizontally and vertically.

UI_SHADOW#

#define UI_SHADOW(dx, dy) ((uint8_t)((dx) << 4 | (dy)))

The shadow field: a drop shadow offset of 0 to 3 pixels right and down, drawn in the slot shade.

UI_FONT#

#define UI_FONT(n) ((n) << 2)

Selects font n of ui_fonts in the text field. Join it with an alignment and UI_RING using |.

UI_RGB#

#define UI_RGB(r, g, b) gfx_RGBTo1555(r, g, b)

Turns 8 bit red, green and blue into the 1555 color graphx uses. It is evaluated at compile time for constants.

Enums#

States#

enum { UI_NORMAL, UI_FOCUS, UI_ACTIVE, UI_DISABLED, UI_ON, UI_STATES };

The index into a style’s c array. UI_STATES is the number of states. See states for when each applies and how colors fall back.

Roles#

enum {
  UI_BG = 1,
  UI_SURFACE,
  UI_RAISED,
  UI_LINE,
  UI_MUTED,
  UI_TEXT,
  UI_ACCENT,
  UI_ON_ACCENT,
  UI_DANGER,
  UI_OK,
  UI_SHADE,
  UI_DIM_BG,
  UI_DIM_SURFACE,
  UI_DIM_TEXT,
  UI_ROLES
};

The palette slots every theme fills. Slot 0 means inherit. UI_ROLES (15) is the first slot free for the program. See palette slots for what each role is for.

Sides#

enum { UI_TOP = 1, UI_BOTTOM = 2, UI_LEFT = 4, UI_RIGHT = 8, UI_ALL = 15 };

The sides of UI_BORDER, joined with |.

Text flags#

enum { UI_ALIGN_LEFT = 0, UI_ALIGN_CENTER = 1, UI_ALIGN_RIGHT = 2, UI_ALIGN_MASK = 3, UI_FONT_MASK = 12, UI_RING = 16 };

The text field of a style: an alignment, a font from UI_FONT(n), and UI_RING for a focus ring outside the border in the hi color of UI_FOCUS. UI_ALIGN_MASK and UI_FONT_MASK pick the alignment and the font out of the field.

Types#

ui_colors_t#

typedef struct {
  uint8_t bg, fg, hi, lo;
} ui_colors_t;

The colors of one state, as palette slots: fill, text and glyph, top and left border, bottom and right border.

ui_style_t#

typedef struct {
  ui_colors_t c[UI_STATES];
  uint8_t border;
  uint8_t radius;
  uint8_t pad;
  uint8_t shadow;
  uint8_t shade;
  uint8_t text;
  const uint8_t *glyph;
} ui_style_t;

A style, 29 bytes. radius is 0 to 3; glyph is drawn by check boxes, radio buttons and selects. See the style record.

ui_font_t#

typedef struct {
  const uint8_t *data;
  const uint8_t *spacing;
  uint8_t scale;
  uint8_t monospace;
} ui_font_t;

A font: graphx font data and its width table (NULL for the graphx font), the integer scale, and a fixed advance in pixels or 0. See fonts.

ui_metrics_t#

typedef struct {
  int margin, gap, row, label, titlebar, softkeys, scrollbar, modal;
} ui_metrics_t;

Sizes in pixels used across the toolkit. See metrics.

What a theme defines#

Every theme defines these objects. Programs can read them, for example to start a style from a theme’s part.

Style parts#

extern const ui_style_t ui_style_screen, ui_style_titlebar, ui_style_softkey, ui_style_panel, ui_style_modal;
extern const ui_style_t ui_style_menu, ui_style_menu_item, ui_style_toast, ui_style_heading, ui_style_text;
extern const ui_style_t ui_style_caption, ui_style_separator, ui_style_button, ui_style_check, ui_style_radio;
extern const ui_style_t ui_style_toggle, ui_style_knob, ui_style_choice, ui_style_select, ui_style_track;
extern const ui_style_t ui_style_fill, ui_style_thumb, ui_style_input, ui_style_list, ui_style_row;
extern const ui_style_t ui_style_header, ui_style_scrollbar, ui_style_tab;

The 28 parts. See parts for which widget uses which.

ui_fonts#

extern const ui_font_t ui_fonts[UI_FONTS];

The fonts styles pick with UI_FONT(n).

ui_metrics#

extern const ui_metrics_t ui_metrics;

The theme’s sizes.

ui_palette_default#

extern const uint16_t ui_palette_default[UI_ROLES];

The colors of the role slots that ui_init loads. Pass it to ui_palette to go back to the theme’s colors.

ui_dimmed#

extern const uint8_t ui_dimmed[UI_ROLES];

For each role slot, the slot it is drawn in under a modal or menu. 0 keeps the slot. Slots past the roles are drawn in UI_DIM_TEXT.

Glyphs#

extern const uint8_t ui_glyph_check[UI_GLYPH_SIZE], ui_glyph_dot[UI_GLYPH_SIZE], ui_glyph_left[UI_GLYPH_SIZE];
extern const uint8_t ui_glyph_right[UI_GLYPH_SIZE], ui_glyph_down[UI_GLYPH_SIZE];

The built-in glyphs: the check mark, the radio dot, the left and right arrows of choices and numbers, and the down arrow of selects. They are defined by CEUI, not by the theme, and can be used as the glyph of a style or with ui_icon_button.

themes/default.h#

The default values a theme starts from. Include it with #include <themes/default.h> to build styles of your own.

Macro

What it holds

UI_DEFAULT_<PART>

The initializer of each part, such as UI_DEFAULT_BUTTON, for use as {UI_DEFAULT_BUTTON, .radius = 2}

UI_DEFAULT_PALETTE

The default colors, as [UI_BG] = UI_RGB(244, 245, 247), ...

UI_DEFAULT_DIMMED

The default dimmed table

UI_DEFAULT_FONTS

The default font list

UI_DEFAULT_METRICS

The default metrics: margin 4, gap 3, row 14, label 92, titlebar 18, softkeys 18, scrollbar 4, modal 260

themes/default.c#

The theme template. Before including it, a theme file can define any of these; each one left undefined falls back to its default.

Macro

Defines

UI_STYLE_<PART>

ui_style_<part>

UI_PALETTE

ui_palette_default

UI_DIMMED

ui_dimmed

UI_FONTS_LIST

ui_fonts

UI_METRICS

ui_metrics

See writing your own theme.