CUI

Components / AI interfaces

Sources and citations

Citations inside an answer and the list of sources they point to.

Functions: cui_citation, cui_source_list

Sources and citations

Usage

static const cui_source sources[] = { { "Notes on subpixel text positioning", "https://glyphlab.io/notes/subpixel", "Shaping, hinting and..." } /* ... */ };
for (int k = 0; k < n; k++) cui_citation(ui, k + 1, &sources[k]);   /* a chip; hover for a card */
int open = cui_source_list(ui, "sources", sources, n);              /* cards that scroll sideways */

Citations show the source's domain and open a card with the title and snippet when hovered. Source cards get a colored initial (always the same for a domain), the title and the source's number.

cui_source_list returns the index of the card that was clicked, or -1, and cui_citation returns true when its chip is clicked. Neither opens anything: opening the URL is up to you. sources is your array of cui_source, only read: a title, a URL and a snippet. The domain shown is cut from the URL, and a source without a title shows its domain there too. A citation takes the number to show and a pointer to its source; with NULL the chip shows the number and has no card. Its identity comes from the number, so the same number twice in one scope needs a cui_id_scope around each answer.

Keyboard

  • Tab moves through the sources and the citation marks, and Enter or Space opens the focused one.

cui_source

FieldTypeDescription
titleconst char *the card's heading; NULL shows the URL's domain
urlconst char *the address: its domain is shown, and the whole URL as the card's tooltip
snippetconst char *an excerpt, shown in the hover card of a citation

Related