# c8ui: widgets and services for apps

Part of the toolkit's notes (`CLAUDE.md` beside this file). Try the
widgets in `toolkit/c8ui/build/c8ui-gallery`.

- `c8ui-files.h` (in libc8ui): `c8ui_file_open/save` through the
  FileChooser portal (request path subscribed before the call; parent
  via `c8ui_window_export_handle`, xdg-foreign-v2 on a private queue),
  and `c8ui_thumbnail_load` (`src/thumbnail.c`): the freedesktop cache
  (MD5 of the URI, `Thumb::MTime` in tEXt chunks, `fail/c8ui/`), made by
  `.thumbnailer` programs under /usr only, always inside bwrap (/usr
  read-only, the file read-only as `/tmp/in/file.EXT`, a scratch dir at
  `/tmp/out`, `--unshare-all`, `--clearenv`, 30 s limit); no bwrap, no
  new thumbnails. Never run thumbnailers outside the sandbox.
- `c8ui-charms.h` (`src/charms.c`, in libc8ui): an app's Search and
  Settings charms. `c8ui_charms_new(app)` owns the app id on the session
  bus and serves `org.cont8nuum.Charms1`; `c8ui_charms_on_search`
  (`c8ui_search_add`, `_hold`/`_done` to answer later),
  `c8ui_charms_add_page` (a build fn adding `c8ui_page_toggle/choice/
  buttons/slider/text/button/link/heading/paragraph`, each with a change
  fn and `c8ui_setting_get_*`), `c8ui_charms_add_action`,
  `c8ui_charms_changed(page)`. The last build of a page is kept so
  SetSetting finds its control. `c8-charms-demo` uses it.
- Clipboard beyond text (c8ui-wayland.h): `c8ui_window_set_clipboard`
  takes items of any MIME type ("text/plain" is offered under text's
  other names too; none empties it), `c8ui_window_paste` reads the first
  type offered synchronously (ours is answered in-process, not through
  the compositor), `c8ui_app_clipboard_offers/_owned`,
  `c8ui_app_on_clipboard`. Sending is non-blocking; SIGPIPE is ignored.
- Drag and drop (c8ui-wayland.h): `c8ui_window_start_drag` (items like
  the clipboard's, actions copy/move, an icon drawn by a callback, `done`
  with the action taken; uses the last press/touch serial, then
  `c8ui_root_cancel_press`), `c8ui_window_set_drop` (motion returns the
  action, leave, drop) with `c8ui_drop_offers`/`c8ui_drop_read` (our own
  drag is answered in-process). `c8ui_list_on_drag` starts one after
  `DRAG_START` px. `c8ui_window_launch(win, desktop_id, uris)` launches
  an app with our token. `c8ui_dialog_add` puts a widget above a dialog's
  buttons; `c8ui_dialog_choose` presses one. Grid columns that expand
  also shrink to fit (wrapping labels).
- `c8ui_menu_show` (white Metro context menu as an overlay);
  `c8ui_menu_show_items` adds ticks, radio dots, separators, shortcut
  text and submenus (one overlay holding a chain of levels; resting
  300 ms opens one). `c8ui_entry_set_password`.
- Popups: `c8ui_root_push_popup` (private) is an overlay that leaves the
  focus where it is (keys reach it first, it forwards the rest), and
  `c8ui_root_repress` from its outside PRESS gives the press again to
  what is under it. Entry suggestions (`c8ui_entry_set_suggestions`,
  set from the change fn) use both.
- `c8ui_scroll_set_directions`: sideways, both or vertical (default);
  `c8ui_scroll_set_narrow_directions` the ways while the window is
  narrow (News' article: across wide, down narrow). A scroll inside one
  that goes down gives way: it measures as tall as its child (a
  sideways one at its child's natural width), so a hub section's list
  stands whole in a narrow column and the outer scroll moves it.
  Sideways the child gets the width it measures with 100000 of room
  (anything taking it all gets the scroll's width). Both ways, the drag
  helper's `both` pans freely. Scrolling widgets leave Ctrl+wheel alone
  for `c8ui_zoom` (semantic zoom in layout.c: detail and overview, Ctrl
  +wheel/minus/plus, pinch, a − button; while moving both views are
  hidden and drawn scaled by the zoom itself).
- Bigger widgets for apps: `textview.c` (multi-line text, one cached
  Pango layout drawn line by line; undo groups, find/replace, framed or
  plain, wrap or sideways scroll; `_on_move` for caret moves; an
  unfocused selection shows as a faint band, so a match found from a
  find box shows. Rich text is opt-in per view, `_set_rich`: runs of
  `c8ui_text_format` (family, size in points, colour, bold, italic,
  underline, strike) kept beside the text, merged when alike, made Pango
  attributes when laid out, spliced on every edit; what is typed takes
  the format before it, or one chosen with `_format` with nothing
  selected until the caret moves. Undo keeps a copy of the runs before
  each group's first edit (and after it, on its last, once undone), so
  a format change is one step with the text the same. A plain view keeps
  no runs and pays nothing. No paragraph formats (alignment, indents,
  lists): one layout has one alignment. File formats (RTF) are the
  app's: the text editor's are in c8-lua), `list.c` (rows or grid the app draws
  through a callback, only the visible items; multi-select, open,
  context, keyboard), `appbar.c` (bottom app bar, an overlay while shown,
  owned by the root via `c8ui_root_keep`), `panes.c` (pivot, hub
  (panorama), flyout), `miller.c` (Miller columns), `forms.c` (check box, radio, progress ring,
  image, round `c8ui_icon_button_new` and `c8ui_back_button_new`, which
  Alt+Left / XF86Back / mouse button 8 press through `root->back`),
  `layout.c` (grid with spans, stack, expander, split with a draggable
  divider: a position in px, or `c8ui_split_set_share` for a part of
  the room kept as the window changes and when stacked, a drag keeping
  the new proportion; separator, flip view, info bar), `pickers.c` (number box,
  star rating, date and time as combos in the locale's order and clock,
  month calendar with marks), `tree.c` (tree view with lazy children via
  `on_expand`; column headers over a rows list, resize and sort,
  `c8ui_columns_draw_cell`), `c8ui_progress_new`, `c8ui_entry_set_search`.
  Tooltips: `c8ui_widget_set_tooltip` (core.c, drawn by the root after
  overlays; 600 ms, gone after 5 s or on a press/key/scroll). Try them all
  in `toolkit/c8ui/build/c8ui-gallery` (built, not installed).
- From the Windows 8 samples (`~/Code/old-Windows8-samples`), in the
  gallery's Reader and Tiles & media pages: `richtext.c` (`c8ui_rich_new`:
  read-only Pango markup, as wide as its text when that is less than
  the room (it took all the room before 2026-12-05, which hid a grid's
  other columns); `<a href>` in its markup is a link (taken out before
  Pango sees it, its bytes kept and coloured in the accent at the
  rebuild; `c8ui_rich_on_link` for clicks and the hand, swapping in an
  impl with an event fn only then, so a rich text without one never
  takes the hover from its parent; not the columns kind); `c8ui_rich_overflow_new` + `_set_overflow` chain
  containers like RichTextBlock/Overflow, one layout wrapped at the first
  container's width, each showing the lines that fit its height;
  `c8ui_rich_columns_new` is the magazine version for a sideways scroll,
  its height from `fixed_height` or its parent; narrow it is one column
  of the width given, as tall as the text), `C8UI_LIST_SPANS` in
  `list.c` (unit cells, `c8ui_list_set_spans` says how many each item
  takes, first-fit packing; call `set_count` again when spans change),
  `navbar.c` (the app bar's twin along the top, pages sideways when it
  overflows; `c8ui_navbar_set_colors` makes the places filled squares in
  the app's colours, as News had), `transport.c` (media controls drawn by one widget: the app
  plays, fn gets `C8UI_TRANSPORT_*` actions; `c8ui_transport_set_marks`
  cuts a gap in the seek bar where each chapter starts), `settingsflyout.c`
  (SettingsFlyout panel from the right, header in the accent colour) and
  `extras.c` (`c8ui_togglebutton_new`, `c8ui_repeat_button_new`,
  `c8ui_item_container_new` that makes any widget tappable/selectable, and
  `c8ui_viewbox_new`, display only: the child is laid out far off to the
  side and drawn scaled, because input is hit-tested by rect and can't be
  mapped through a transform). Untested live: touch on the nav bar, the
  settings flyout beside real charms.
- Miller columns (`miller.c`, `c8ui_miller_*`): each column opens the
  next at its right (Cirrus: a feed, a post in it, a reply in that);
  `c8ui_miller_open(m, after, content, width)` takes away the columns
  after `after` first, so choosing again in an earlier column starts
  the path over from there. Wide they pan like a hub (sideways wheel or
  Shift+wheel, touchpad with a fling, finger, the reveal hook for Tab),
  a new one entering Metro's way and panned into sight; a plain wheel
  is the columns' own, as they are mostly lists. A hairline sits in
  each gap and the hub's indicator along the bottom. Narrow (by itself,
  from the window) it shows only the last column, the whole width. `c8ui_miller_back` (and Escape or BackSpace
  inside it) closes the last one down to `set_base`; `on_change` hears
  every open and close, `index_of` says which column a widget is in.
  A column opened before the miller is in a window doesn't enter (it
  would never tick, and stayed unseen). Keeping the chosen item marked
  in each column is the app's. Tested through Cirrus (2026-12-01,
  headless, wide and snapped); untested: touch, touchpad flings, Tab
  panning, Shift+wheel.
- Hub: `c8ui_hub_set_spacing` sets the room round and between its
  sections (60, 80, 30, 24 unless set). Keep them for a panorama: a hub
  of columns filling the window edge to edge stops looking like one
  (Cirrus was that until 2026-12-01).
  `c8ui_hub_add_full` is a section without a header, the whole
  height, from the left edge when first (width 0: the hub's less a peek
  of the next); headers take room only when some section has one.
  The hub is Metro's panorama (WP7's name; Windows 8 called it hub).
  `c8ui_hub_set_background` puts a picture behind all of it, as tall as
  the hub, its extra width panned over the sections' whole run (left
  edge at the first section, right edge at the last), so it never runs
  out; but at most half the sections' speed (`HUB_BG_PARALLAX`), or a
  wide picture in a short hub raced ahead of them (1800x600 in the
  gallery at 1280x800: 1276 px to pan over a 760 px run), so a very wide
  one's right part isn't seen. A plain colour is
  `c8ui_widget_set_background`; text keeps the scheme, so a dark picture
  wants `c8ui_widget_set_scheme(hub, C8UI_SCHEME_DARK)`. The rules from
  Metro's guidance (the
  "Introduction to Metro UI" deck), for apps using one: a hub puts
  several sources into one place, like a magazine cover (the title is
  the branding, a full first section the hero); a pivot shows one set
  of things several ways. Keep to about 5 sections; one background
  (a colour, or one picture that spans it all, never a picture per
  section); no pivot or hub inside a section, and nothing in a section
  that pans sideways (a vertical list is fine: a scroll leaves mostly
  sideways fingers to the hub, see DRAWING.md). WP7's panorama wrapped
  round from the last section to the first; ours, like Windows 8's,
  stops at the ends. Narrow, the hub becomes a pivot by itself (it
  doesn't pan 400 px sections across a 474 px window): its sections
  with a header, or a name from `c8ui_hub_set_name` (a hero is left
  nameless, so hidden), are moved into a wrapping pivot titled as the
  hub, `C8UI_HUB_NARROW_EDGE` (20) in, and moved back in order going
  wide, the hub scrolled to the section the pivot was on (the start if
  that was the first). `c8ui_hub_show` turns the pivot narrow;
  `c8ui_hub_set_width` changes a section's width without building
  again. `c8ui_hub_set_narrow_column(hub, true)` folds it into one
  column going down instead (News, Weather: a page to read top to
  bottom rather than tabs): each section in a holder (padded
  `HUB_NARROW_PAD`, its name as a SUBHEADER over it, content set to
  fill with its own `fill` kept in `was_fill`), the hub's title on
  top, all in a vertical scroll; `c8ui_hub_show` scrolls to the
  section, sections appended later get a holder too, and going wide
  puts them back and pans to the section that was showing.
  Which section "shows", either way (`hub_shows`): the first with half
  of it in view or filling half the view, else the one at the edge; a
  sliver of the one before doesn't count (it did until 2026-12-01: a
  hub panned to Hourly snapped to the top). Panning back wide waits
  for the wide layout (`wide_at`): a section without a width is as wide
  as the hub, so its place isn't known while the hub is narrow (the
  offset was once worked out from the narrow width and the hub came
  back a section short). Tested headless (News, Weather, the gallery's
  pivot, 2026-12-01). Untested: touch in the column.
  The gallery's Music hub has a drawn background. Tested headless
  (nested c8, the gallery at 1280x800 and 480x900, wheeled to the
  middle and the end; `c8.hub { background }` from Lua). Untested:
  touch and fling over it, fractional scales, how it costs per frame.
  `C8UI_WEIGHT_BOLD` (Selawik Bold); `c8ui_widget_shows_focus` says when
  a custom widget should draw its focus ring.
- Pivot: `c8ui_pivot_set_title` puts the small line in capitals over
  the headers that Metro's pivots have (the app's name, "INBOX"),
  in BODY_STRONG, uppercased with `g_utf8_strup`. `c8ui_pivot_set_wrap`
  is WP7's pivot: the selected header always at the left edge, the
  rest after it in order and round again; on a change the row slides
  from where the new header was (`header_shift`, eased in
  `pivot_tick` like the page), and going back one it comes in from the
  left. A header clicked while wrapping always counts as forward (all
  the others are to the right). The one sliding off the left is drawn
  again a ring's length back (`pivot_draw`), and hit-tested there too.
  The hover is found again from the pointer's last place whenever the
  headers move (`pivot_rehover`), or clicking on with the mouse still
  lit the header that had been there.
  Off (the default) the headers stay put, scrolled only to keep the
  selected one in sight, as Windows 8's. Keys (Ctrl+Tab) and swipes
  went round from the last page to the first already, either way. With
  few short headers the row isn't repeated to fill the width. The
  deck's pivot rules: one set of similar things shown several ways
  (filters, views), not a task's steps; no pivot inside a pivot or a
  hub; nothing inside that pans sideways. The gallery's pivot has a
  title and wraps; `c8.pivot { title, wrap }` from Lua. Tested headless
  (nested c8, 1280x800 and 480x900): the title, Ctrl+Tab and
  Ctrl+Shift+Tab round, the row mid-slide, a header click; from Lua
  (`c8.pivot { title, wrap }`, `:title`, `:wrap`). Untested: touch.
- Press tilt (Metro's "tilt" feedback): something pressed as a whole
  turns in space, the side pressed going back into the screen and the
  far one coming forward, drawn in perspective (a trapezoid), and
  springs back on release; pressed in the middle it only sinks. One
  rule, `struct c8ui_tilt` with `c8ui_tilt_set/_depth/_moving/_begin/
  _end` (core.c; down in 100 ms, back in 200): `_begin` draws the item
  into a group clipped to its rect at the normal scale (kept pictures
  stay kept, DRAWING.md); `_end` copies it out at device size and
  warps it with pixman (`tilt_warp`: a projective map, which cairo
  can't do; a first try that only scaled towards the far side looked
  like shrinking, not tilting). The card sinks `TILT_SINK` px and
  turns `TILT_TURN` px either way of that, seen from `TILT_EYE` px, then
  is made smaller all over until the corner coming forward stays
  inside the rect. Then all of it less until no corner moves more
  than `TILT_REACH` (6) px in or out: the same depth moves a point by
  its distance from the middle, so a 960 px list row swung its ends a
  long way, and the corner its short side's turn brought forward,
  fitted back in, shrank the whole row by 30 px and more (the user:
  "really really extreme" on lists while tiles looked right). The
  first numbers (sink 20, turn 50, no cap) were far too much even on
  tiles. A long thin item reaches less still, by how much longer than
  twice its width it is, down to `TILT_REACH_THIN` (2) px: a 960 px row
  at 6 px was still too much for the user. Tiles (up to 2:1) and cells
  pressed at an edge are under the reach; big ones pressed at a corner
  are brought down to it. The warped picture is painted only inside
  the turned corners (a clip): pixman's fixed point let a line of
  stray pixels through beside a corner-pressed card.
  pixman's matrix is 16.16 fixed point: it is
  normalised and scaled by 16000 / the size, since a bigger multiple
  overflows on each pixel (everything smeared) and none loses the
  bottom row's tiny numbers. Widgets with `w->tilts` get it from
  `c8ui_widget_draw` and the press grab (the item container sets it);
  the list does it per item itself, Start per tile (c8-shell's
  `press_tile`). Buttons, nav items and text don't tilt, as in Windows 8.
  A press released at once barely shows (it springs from the depth
  reached), so a touch tap on a list in a scroll, delivered as an
  instant click, hardly tilts.
  Tested offscreen (libc8ui-core with a fake host, a press held 150 ms:
  a 160 px grid cell pressed at an edge, a corner and the middle) and
  by the user in the real session's gallery (the scale-only first
  try). Untested: Start's tiles pressed (a nested c8 can't hold a
  button), touch, fractional scales.
- `c8ui_entry_set_enter_only`: the entry's fn runs for Enter (the search
  button, a picked suggestion) but not when focus leaves with text
  typed; for boxes whose Enter adds or submits. `c8ui_stack_push`/`_pop`:
  pages over a stack's first child (News, Weather).
  `c8ui_dialog_message(root, title, message)`: a dialog with only Close
  (to stderr without a root); the apps' `show_message`/`show_error` are
  that. `c8ui_weather_glyph` (`glyphs.c`): the weather glyphs drawn,
  one copy for Start's forecast template and the Weather app.
