The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
idunn_theme.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file idunn_theme.h
5 * @brief idunn: the design tokens (colours, sizes, text styles, shadows).
6 *
7 * the tokens are the only place colours and sizes are written: widgets
8 * and heimdalld use token names, never numbers. the values follow the
9 * agreed look (plans/idunn-ui-plan.md, section 2), shadcn's "zinc" theme
10 * with the user's accent colour.
11 *
12 * the theme file (/etc/ginnos/theme.conf and ~/.config/ginnos/theme.conf)
13 * has these keys in [theme]: mode (light or dark), accent (rose, blue,
14 * green, orange, violet, neutral, or #rrggbb), font_size (13 to 15; all
15 * text styles follow), scale (1 or 2), motion (true or false) and radius
16 * (4 to 12; the small and large radii follow). the sections [light] and
17 * [dark] can change any colour token for that mode, by its name:
18 * "border = #ffffff1a".
19 */
20
21#include <conf.h>
22#include <gfx.h>
23#include <stdbool.h>
24#include <stdint.h>
25
31
32typedef enum
33{
34 IDUNN_COLOR_BACKGROUND, // the content of a plain window
35 IDUNN_COLOR_FOREGROUND, // normal text
36 IDUNN_COLOR_SURFACE, // the window content, a little off the background
37 IDUNN_COLOR_SIDEBAR, // a side bar, one step more
38 IDUNN_COLOR_CARD, // cards, fields, menus, dialogs
40 IDUNN_COLOR_MUTED, // quiet backgrounds: tab lists, code, empty states
41 IDUNN_COLOR_MUTED_FOREGROUND, // help text, placeholders, inactive things
43 IDUNN_COLOR_INPUT, // the border of inputs
44 IDUNN_COLOR_FIELD, // the inside of text fields
45 IDUNN_COLOR_PRIMARY, // the main button: the accent
49 IDUNN_COLOR_HOVER, // ghost buttons, menu items and rows under the pointer
50 IDUNN_COLOR_ACCENT, // the user's colour
52 IDUNN_COLOR_SELECTION, // selected text and rows: the accent, faint
53 IDUNN_COLOR_DESTRUCTIVE, // delete buttons, errors
54 IDUNN_COLOR_RING, // the focus ring: the accent at half
55 IDUNN_COLOR_OVERLAY, // behind a dialog
56 IDUNN_COLOR_TITLE_TOP, // the title bar's gradient
58 IDUNN_COLOR_TOP_LIGHT, // the light line at the top edge of a title bar
61
62typedef enum
63{
64 IDUNN_TEXT_BODY, // almost all text, inputs, menu items
65 IDUNN_TEXT_LABEL, // buttons, labels of fields, tabs
66 IDUNN_TEXT_SMALL, // help text, captions, badges
67 IDUNN_TEXT_TITLE, // card and dialog titles
68 IDUNN_TEXT_HEADING, // page titles
69 IDUNN_TEXT_DISPLAY, // the first page of an app
70 IDUNN_TEXT_MONO, // code, paths
71 IDUNN_TEXT_CAPTION, // badges, tabs, section captions: small and medium
72 IDUNN_TEXT_HERO, // one very large line: the clock of a login screen
75
76typedef struct
77{
78 int32_t size; // pixels
80 int32_t weight; // 400, 500 or 600 (Inter Regular, Medium, SemiBold)
81 float tracking; // letter spacing in ems (bragi_face_set_tracking)
82 bool mono; // JetBrains Mono instead of Inter
84
85typedef enum
86{
87 IDUNN_SHADOW_XS, // inputs, buttons, the selected side bar item
88 IDUNN_SHADOW_MD, // menus, popovers, tooltips
89 IDUNN_SHADOW_WINDOW, // windows and dialogs
92
93#define IDUNN_SHADOW_LAYERS 4
94
95typedef struct
96{
98 gfx_color_t colors[2][IDUNN_COLOR_COUNT]; // by mode: changing mode needs nothing else
99 int32_t radius; // the base radius at scale 1
100 int32_t font_size; // the body text size at scale 1
101 int32_t scale; // 1 or 2
102 bool scale_auto; // the scale follows the screen (idunn_theme_fit)
103 bool motion;
105
106/**
107 * the default theme: dark, rose, 13 px text, 6 px radius.
108 */
110
111/**
112 * a theme from a theme file (or from text, for tests); missing or bad
113 * values keep their defaults.
114 */
115void idunn_theme_from_conf(idunn_theme_t *theme, const conf_t *conf);
116
117/**
118 * read the user's theme (conf_open("theme")).
119 */
121
122/** screens at least this wide get scale 2 when the scale is auto */
123#define IDUNN_HIDPI_WIDTH 2400
124
125/**
126 * set the scale for a screen when the theme's scale is auto.
127 * @return true if the scale changed.
128 */
129bool idunn_theme_fit(idunn_theme_t *theme, int32_t screen_width);
130
131static inline gfx_color_t idunn_color(const idunn_theme_t *theme, idunn_color_t which)
132{
133 return theme->colors[theme->mode][which];
134}
135
136/**
137 * the name of a colour token in the theme file ("muted-foreground"), or
138 * NULL.
139 */
140const char *idunn_color_name(idunn_color_t which);
141
142/**
143 * a size of the design at the theme's scale: idunn_px(theme, 32).
144 */
145static inline int32_t idunn_px(const idunn_theme_t *theme, int32_t px)
146{
147 return px * theme->scale;
148}
149
150/** buttons, inputs, list rows */
152/** check boxes, small items in menus: half the radius */
154/** cards, dialogs, popovers, windows: the radius + 4 */
156
157/**
158 * a text style at the theme's font size and scale.
159 */
161
162/**
163 * the layers of a shadow, in the order to draw them (the CSS list from
164 * its end), at the theme's scale.
165 * @return the number of layers (at most IDUNN_SHADOW_LAYERS).
166 */
167int idunn_shadow(const idunn_theme_t *theme, idunn_shadow_t which,
settings files: sections of "key = value" lines.
struct conf conf_t
Definition conf.h:37
libgfx: drawing into pixel buffers in memory.
uint32_t gfx_color_t
a premultiplied ARGB colour, 0xAARRGGBB.
Definition gfx.h:30
#define IDUNN_SHADOW_LAYERS
Definition idunn_theme.h:93
int idunn_shadow(const idunn_theme_t *theme, idunn_shadow_t which, gfx_shadow_t layers[IDUNN_SHADOW_LAYERS])
the layers of a shadow, in the order to draw them (the CSS list from its end), at the theme's scale.
Definition theme.c:324
idunn_shadow_t
Definition idunn_theme.h:86
@ IDUNN_SHADOW_XS
Definition idunn_theme.h:87
@ IDUNN_SHADOW_MD
Definition idunn_theme.h:88
@ IDUNN_SHADOW_COUNT
Definition idunn_theme.h:90
@ IDUNN_SHADOW_WINDOW
Definition idunn_theme.h:89
idunn_mode_t
Definition idunn_theme.h:27
@ IDUNN_LIGHT
Definition idunn_theme.h:28
@ IDUNN_DARK
Definition idunn_theme.h:29
idunn_text_style_t idunn_text_style(const idunn_theme_t *theme, idunn_text_t which)
a text style at the theme's font size and scale.
Definition theme.c:283
void idunn_theme_from_conf(idunn_theme_t *theme, const conf_t *conf)
a theme from a theme file (or from text, for tests); missing or bad values keep their defaults.
Definition theme.c:222
const char * idunn_color_name(idunn_color_t which)
the name of a colour token in the theme file ("muted-foreground"), or NULL.
Definition theme.c:263
int32_t idunn_radius_sm(const idunn_theme_t *theme)
check boxes, small items in menus: half the radius
Definition theme.c:273
void idunn_theme_load(idunn_theme_t *theme)
read the user's theme (conf_open("theme")).
Definition theme.c:256
int32_t idunn_radius_lg(const idunn_theme_t *theme)
cards, dialogs, popovers, windows: the radius + 4
Definition theme.c:278
void idunn_theme_default(idunn_theme_t *theme)
the default theme: dark, rose, 13 px text, 6 px radius.
Definition theme.c:200
idunn_color_t
Definition idunn_theme.h:33
@ IDUNN_COLOR_ACCENT
Definition idunn_theme.h:50
@ IDUNN_COLOR_COUNT
Definition idunn_theme.h:59
@ IDUNN_COLOR_DESTRUCTIVE
Definition idunn_theme.h:53
@ IDUNN_COLOR_SECONDARY
Definition idunn_theme.h:47
@ IDUNN_COLOR_CARD_FOREGROUND
Definition idunn_theme.h:39
@ IDUNN_COLOR_TITLE_BOTTOM
Definition idunn_theme.h:57
@ IDUNN_COLOR_PRIMARY
Definition idunn_theme.h:45
@ IDUNN_COLOR_ACCENT_FOREGROUND
Definition idunn_theme.h:51
@ IDUNN_COLOR_RING
Definition idunn_theme.h:54
@ IDUNN_COLOR_INPUT
Definition idunn_theme.h:43
@ IDUNN_COLOR_SECONDARY_FOREGROUND
Definition idunn_theme.h:48
@ IDUNN_COLOR_HOVER
Definition idunn_theme.h:49
@ IDUNN_COLOR_TOP_LIGHT
Definition idunn_theme.h:58
@ IDUNN_COLOR_FIELD
Definition idunn_theme.h:44
@ IDUNN_COLOR_SIDEBAR
Definition idunn_theme.h:37
@ IDUNN_COLOR_MUTED
Definition idunn_theme.h:40
@ IDUNN_COLOR_PRIMARY_FOREGROUND
Definition idunn_theme.h:46
@ IDUNN_COLOR_TITLE_TOP
Definition idunn_theme.h:56
@ IDUNN_COLOR_BACKGROUND
Definition idunn_theme.h:34
@ IDUNN_COLOR_OVERLAY
Definition idunn_theme.h:55
@ IDUNN_COLOR_FOREGROUND
Definition idunn_theme.h:35
@ IDUNN_COLOR_CARD
Definition idunn_theme.h:38
@ IDUNN_COLOR_SELECTION
Definition idunn_theme.h:52
@ IDUNN_COLOR_MUTED_FOREGROUND
Definition idunn_theme.h:41
@ IDUNN_COLOR_BORDER
Definition idunn_theme.h:42
@ IDUNN_COLOR_SURFACE
Definition idunn_theme.h:36
int32_t idunn_radius(const idunn_theme_t *theme)
buttons, inputs, list rows
Definition theme.c:268
bool idunn_theme_fit(idunn_theme_t *theme, int32_t screen_width)
set the scale for a screen when the theme's scale is auto.
Definition theme.c:211
idunn_text_t
Definition idunn_theme.h:63
@ IDUNN_TEXT_SMALL
Definition idunn_theme.h:66
@ IDUNN_TEXT_CAPTION
Definition idunn_theme.h:71
@ IDUNN_TEXT_HEADING
Definition idunn_theme.h:68
@ IDUNN_TEXT_MONO
Definition idunn_theme.h:70
@ IDUNN_TEXT_BODY
Definition idunn_theme.h:64
@ IDUNN_TEXT_HERO
Definition idunn_theme.h:72
@ IDUNN_TEXT_COUNT
Definition idunn_theme.h:73
@ IDUNN_TEXT_DISPLAY
Definition idunn_theme.h:69
@ IDUNN_TEXT_LABEL
Definition idunn_theme.h:65
@ IDUNN_TEXT_TITLE
Definition idunn_theme.h:67
integer types of fixed width.
int int32_t
Definition stdint.h:14
bool, true and false.
a CSS box-shadow: "x y blur spread color", and "inset".
Definition gfx.h:202
Definition idunn_theme.h:77
int32_t weight
Definition idunn_theme.h:80
float tracking
Definition idunn_theme.h:81
bool mono
Definition idunn_theme.h:82
int32_t line_height
Definition idunn_theme.h:79
int32_t size
Definition idunn_theme.h:78
Definition idunn_theme.h:96
bool motion
Definition idunn_theme.h:103
idunn_mode_t mode
Definition idunn_theme.h:97
int32_t font_size
Definition idunn_theme.h:100
gfx_color_t colors[2][IDUNN_COLOR_COUNT]
Definition idunn_theme.h:98
bool scale_auto
Definition idunn_theme.h:102
int32_t radius
Definition idunn_theme.h:99
int32_t scale
Definition idunn_theme.h:101