Trame

prefs_page: a settings page from the preferences

#import "trame:prefs_page". It builds a program's settings from its preference registry (config.md), with no code per preference, in the look of Tower's settings.

Formula
page: prefs_page.Page                         // kept between frames; prefs_page.destroy(&page) at the end

ui.next({width = ui.fill(), height = ui.fill()})
prefs_page.build(&page, &prefs, {
	user    = app,
	pages   = {{category = "appearance", title = "Appearance", icon = ICO_PALETTE}, {category = "history", title = "History", icon = ICO_HISTORY}},
	icon_font = app.icons, search_icon = ICO_SEARCH, reset_icon = ICO_RESET,
	file = app.prefs_path,                         // at the sidebar's foot: a click opens it
	changed = proc(user: rawptr, name: string) {   // a value was set or reset
		app := (^App)(user)
		// the loop saves: config.user_writer_save, once per round
		apply(app)
	},
	themes = app.themes_file.all[:], themes_light = app.theme_shown.light,   // appearance.theme as cards
	themes_file = &app.themes_file,                // and the user's own themes under them
	custom_names = {"look.font"},
	custom  = proc(user: rawptr, name: string, em: f32) {   // the program's own control, under the words
		/* a control of the program's own */
	},
})

The Appearance page: the themes as cards with two of the user's own, light or dark, the finish, the glow (examples/showcase)

A program's files and its preferences' start

prefs_page.program_files(folder, memory = false) gives the paths every program keeps (src/md/features/program-files.md):

FieldFileFolder
prefsprefs (PREFS_FILE)config
themesthemes.txt (THEMES_FILE): themes_file_initconfig
viewsviews.txt (VIEWS_FILE): ui.views_initstate
palette_choicespalette_choices.txt (PALETTE_CHOICES_FILE): the palette's memorystate
file_dialogsfile_dialogs.txt (FILE_DIALOGS_FILE): ui.file_dialog_memorystate

config_dir and state_dir are the folders. With memory = true, every path is "": nothing is read or written (a test, a headless run). A test that keeps one file sets that field afterwards, in files.allocator. program_files_destroy(&files) frees them.

prefs_open(p, files, sets, defaults, defs, args, descriptions) makes the registry: the standard preferences (standard_register), the program's own (defs, a list of tables), the version for What's new (changelog_register), the file files.prefs ("": none), then --pref in args. It gives the arguments that are not preferences and the problems (the file's first). It reads a file: call it at the start, before the loop.

Formula
app.files = prefs_page.program_files(APP_FOLDER, memory = headless)
rest, problems := prefs_page.prefs_open(&app.prefs, app.files, prefs_page.STANDARD_ALL, standard_defaults(), {PREF_DEFS[:]}, os.args[1:])
for p in problems { log.warn(p) }
ui.views_init(&app.views, {path = app.files.views})
prefs_page.themes_file_init(&app.themes_file, app.files.themes, ui.THEMES[:])

The standard settings

Every program has the same look, the same text, the same hand and the same place on the desktop: the toolkit declares each of its settings that changes how a program looks or answers as a standard preference, with today's default, and every program inherits them. standard_register registers the sets asked, with their titles, descriptions, choices, bounds, search tags and the titles of their groups; the page then draws them with no code of the program's. settings.md lists every one with its default.

Formula
d := prefs_page.STANDARD_DEFAULTS   // system, machined, 14 px, glow 1, in the menu, updates on
d.theme, d.app_name = "cliche", "cliche"
prefs_page.standard_register(&prefs, prefs_page.STANDARD_ALL, d)
config.register(&prefs, PREF_DEFS[:])   // the program's own, after them

// applied now, then each one again when it changes (config.watch): nothing per frame
prefs_page.standard_watch(&app.standard, &prefs, &app.state, {renderer = &app.r, fonts = &app.fonts, partial_redraw = &app.host.partial_redraw})
defer prefs_page.standard_unwatch(&app.standard)

a := prefs_page.appearance_read(&prefs)   // the theme: the program shows it; again after each change
defer prefs_page.appearance_destroy(&a)
ui.theme_show(&theme, themes, prefs_page.appearance_choice(a), &shown, space)
SetGroup (page)What
Appearanceappearance, windowtheme, light or dark, finish, glow, text size, zoom, density, rounding, smooth corners, animations; the system's title bar, where messages show
Textappearance.text (in Appearance)the interface, monospace and reading fonts, the emoji font, the system's fonts as a last resort, colour emoji, subpixel text, gamma, contrast, weight; advanced: the blending curve and space, subpixel positions, grid fitting, the renderer (Windows), Slug's tolerance, the atlas's and Slug's pages, the words kept
Scrollingscrolling, scrolling.autoscrollsmooth scrolling, the glide's length, lines per notch, hidden bars, arrows; scrolling with the middle button; advanced: the curve, the impulse, the fling, the middle button's distances and speeds
Inputinputkey and button repeats, undo steps and merge, type to find, the zoom step; advanced: the steps of Shift, Ctrl, Alt and Page
Timingtimingthe tooltip delay, the submenu delay, a menu item's height, the colour fade
Renderingrenderingall advanced: presentation (vsync, tearing), frames queued, partial redraw, the blur limit, the filters' precision
Updateupdateupdate.auto, update.channel (only with Standard_Defaults.update_channels: a choice of them), update.base_url (advanced); update_source reads the last two for the Updater
Sessiongeneralgeneral.menu (in the application menu), general.autostart (with the session), general.messages (System, Window, Off; read by announce_mode for ui.announce), general.language (system; at once, language_start)
Keyskeysall advanced: keys.custom and keys.aliases (KEYS_CUSTOM_PREF, KEYS_ALIASES_PREF), the person's keys and aliases of commands, set from the palette; read into Standard_Targets.keymap and written back from it

STANDARD_ALL is every set. Start from STANDARD_DEFAULTS: a zero Standard_Defaults has menu and update_auto off. Standard_Defaults.values gives any other standard setting the program's own default, as the file writes it ({{"appearance.rounding", "0.25"}, {"rendering.partial_redraw", "true"}}): registered as the default, a reset comes back to the program's look. app_name goes in the descriptions ("Start cliche with the session"); those texts are made in the allocator argument and must live as long as the registry. The names are fixed: the programs' files hold them. The groups come in this order among a program's own (theirs have the order 0): General, Appearance and Window before them, the others after.

Applying them

standard_apply(prefs, state, targets) gives every standard preference that is registered, at its default too (a program's own default is its Standard_Defaults.values), to the toolkit's setters: ui.set_feel (repeats, undo, typeahead, steps, zoom step, tooltips, menus, the fade, the wheel's lines, the fling), set_zoom, set_density, set_rounding, set_animations, set_smooth_scroll, set_scroll_settings, set_autoscroll_enabled, set_autoscroll_settings, set_scrollbar_size, set_scrollbar_autohide, set_scrollbar_overlay, set_toast_position, set_partial_redraw. Standard_Targets gives what lies outside the interface (each nil: left alone): renderer (set_corner_smoothing, set_text_rendering, set_blend_space, set_present_mode, set_max_frame_latency, set_blur_sigma_limit, set_filter_precision), fonts (font.set_settings) and partial_redraw (a host's flag, host.Host.partial_redraw, which the host gives the interface at each frame; nil: ui.set_partial_redraw). A preference at its default is left alone, so what a program set itself stays until the user changes it.

The family settings (appearance.text.ui_font, mono_font, prose_font) and appearance.text.mono_features (MONO_FEATURES_PREF) apply live, in every window of the program (its views' windows too), with no restart: ui.use_text_family loads the family's face on a chore and swaps it in when it comes, and ui.use_text_features applies the monospace face's OpenType features (font-picker.md, "The text faces"). MONO_FEATURES_PREF shares MONO_FONT_PREF's row as its Features (N) button (line_of), rather than taking a row of its own. Standard_Targets.faces gives the program's own faces, which "Default" draws in (each 0: Build_Params.base.font, State.mono_font else the embedded Paper Mono, the interface's for prose); keep giving the program's own face as Build_Params.base.font: the toolkit puts the chosen one in its place. Standard_Targets.font_source gives the families another way (a test's; zero: the system's).

standard_watch(w, prefs, state, targets) applies them, then watches the registry (config.watch): a change of one applies that one alone, at once, on the thread that changed it. A zoom by Ctrl+wheel is not undone by a change of the density. standard_unwatch(w) ends it; keep w where it is until then. With Standard_Targets.keymap (the program's ui.Keymap) and the Keys set: keys.custom and keys.aliases are read into it, and its changed writes the one that changed when the person sets a key or an alias in the palette (a value it wrote itself is not read back).

What the program applies itself:

  • the theme (appearance.theme, mode, finish, glow, font_size): appearance_read, appearance_choice, ui.theme_show. After a change of appearance.text.blend_space, show the theme again with render.blend_space(r);
  • the emoji font (appearance.text.emoji_font), appearance.text.page_size and update.base_url: read at the start (Def.restart: "Takes effect at the next start");
  • window.system_title with no Standard_Targets.window. With it, standard_apply and standard_watch give that window the system's title bar or the program's own (platform.set_integrated_title) at once, the program's where the system cannot draw one (platform.system_title_available). The program's bar is its ui.title_bar with ui.window_buttons at its end: they show only while the title bar is the program's;
  • update.channel: at once, by update.set_channel on the program's Updater (update.md, "Channels");
  • general.language: language_start(prefs, catalogues) at the start, which then switches the language at once at each change of it (i18n.md, "Changing the language");
  • general.menu and general.autostart, on a worker with desktop.apply (desktop.md); update.auto by its Updater.

appearance_read reads a preference that is not registered as its standard default.

What it shows

A page, its group and its Advanced partA search
The Scrolling page: the middle button's group, then Advanced unfoldedThe settings searched for "scroll": what matches in every page
  • On the left, the sidebar: the search in a well, then the pages, each a button with its icon and its title; the page shown is pressed in. A page is a top group of the registry (the first segment of the name). Page_Options.pages gives their order, titles and icons (a page with no preference in the registry is not shown); without it, each top group shows, by config.groups_of, with its config.group_title. At its foot: Page_Options.version ("Papier 0.15.0"), the settings file (Page_Options.file, shortened with ~: a click opens it with the system's program, ui.open), then Export… and Import… (below) and what the last of them did.
  • A page of the program's own: a Page_Info with build has no preference; the page shows its title and calls build(user, em) under it (a server's state, a list the program keeps). A search does not look in it. heading puts a small title above a page, which starts a group ("CLIENT", "SERVER"): one sidebar for the settings and the program's pages, not two.
  • The sidebar's handle (ui.side_panel_handle) resizes it with the mouse; a double click puts 14 ems back. Its width is kept in the hidden preference prefs_page.sidebar_width (SIDEBAR_PREF, in ems; the page registers it at its first build), written when the handle is let go. It stays between 9 ems and half of the page. It is never narrower than its longest page title or heading on one line, nor than the search's placeholder whole, in the language in use (ui.button_width): the handle does not go under that; at half of the page, a longer title wraps onto two lines.
  • The sidebar folds to a rail (ui.Side_Panel, panes.md): when, open, it leaves the page less than BODY_MIN_EM (26 ems), in a window or in a dialog, and again by its fold button (at the start of the search's row, and at the top of the rail at the same pixel). It opens again when the page has BODY_MIN_EM plus 1 em. A fold or an opening by hand holds until the width next crosses that threshold. The rail (RAIL_EM, 3.5 ems) holds a magnifier (it opens the sidebar with the search field focused), the pages' icons (the title as the tooltip, the page shown lit, Up and Down for the page before and after; a page without an icon shows the first letter of its title), and a … button whose menu holds the version, the settings file, Export… and Import…. A pull of the rail's edge opens the sidebar. The fold is kept in the hidden preference prefs_page.sidebar_fold (SIDEBAR_FOLD_PREF, ui.side_fold_format).
  • On the right, in what the sidebar leaves (never wider: a page's wide row wraps or scrolls in it, as in a dialog narrower than the page's natural width): the page's title, then a line per preference, in the order the program registered them: its title (config.title_of) on the left, its control on the right, a reset button while the user's value differs from the default; a carved line between two lines of a group, none under the last. Resting the pointer on the setting title (Feel.tooltip_delay_ms) opens a wrapped tooltip with its description (plus "Locked by a policy.", "Set on the command line for this run.", or "Takes effect at the next start." when applicable), and the same text is exposed as the title's accessibility description. Only a locked setting (policy or command line) shows its brief lock reason inline under the title so the disabled control explains itself.
  • The preferences of an inner group (appearance.text in Appearance) follow those of the page's own group, under the group's title (config.group_title). The advanced ones (Def.advanced) of the page come last, under Advanced, folded until a click (ui.accordion; the page keeps it open while it lives). The fold is only on a page that has ordinary preferences too. A page of advanced ones alone (Rendering) shows them, under the sentence "These are technical settings: their defaults are right for most people.": a fold would leave the page empty.
  • A standard group whose title does not say what it is for (Input, Delays and menus, Rendering) has a sentence under its title, in the weak text, that says it.
  • While a search is typed (title, name, description, tags or a group's title: config.matches): what matches in every page, the advanced ones too, under each page's title.
  • Nothing goes past the window or is cut: description tooltips wrap; a control that would leave its words less than 12 ems goes under them, as wide as the line; the page scrolls.

The controls come from the value, never from a name: one table, control_of(def, choices, themes, custom) -> Control, from the storage, the value kind (Def.value_kind, config.md) and the count of choices. The page asks it for each line; a program asks it too, to say which control a preference gets.

PreferenceControlDrawn as
a name in Page_Options.custom_namesCustomthe program's own (Page_Options.custom), under the words
BoolSwitcha switch
Font_FamilyFont_Familya font picker (font-picker.md): the family in use, its default named ("Roboto (default)"), the system's families drawn in themselves, searched as one types; the monospace ones first for mono_font
Theme, with Page_Options.themesThemethe themes' cards, under the words, in the version appearance.mode asks
ColorColora swatch and the value; a click opens the colour picker (ui.color_picker) in a popover under the button; each change is set in hex; the button, Escape or a press outside closes it
KeysKeysa field that records the keys pressed (ui.hotkey_field): a click, then the keys; with Page_Options.shortcut_prefs, what the system made of them under it (see below)
String with up to 6 choices (SEGMENTS_MAX: its own choices, or the program's Page_Options.choices)Segmentsa segmented choice; under the words when it takes more than 45 % of the line
String with more choicesLista list
Int, Float bounded, and every Fraction, but a SizeNumberui.number with its slider: − and +, a field for its exact value, its unit after it; a float's step is round (0.1, 1, 10...); a Fraction in percent; the field reads its unit's suffixes ("1.5 s" for a time in ms)
the restFielda field: a number's unit after it, a Size in its largest exact unit ("4 MiB") and read with its suffixes, a Path or an Address in the monospace face

A family names its default by the program's face it replaces (standard_face_of(name): the monospace face for mono_font, the reading one for prose_font, the interface's for the others, a program's own family setting too) and ui.program_text_face: the one it gives in Standard_Targets.faces, else Build_Params.base.font, State.mono_font, the interface's for prose. A family chosen before does not change that name. The page reads the families from the program's source (ui.text_font_source: Standard_Targets.font_source, a test's; zero: the system's), at a picker's first opening, on a chore, and keeps the list for its life.

A value a field refuses says why under the line, with what is taken: the bounds as the value is shown ("out of range: 1 KiB to 100 MiB"), the choices, or the value kind's hint (config.value_hint: "an address with its scheme: https://…").

setting_line(page, prefs, options, name) draws one preference's line, as the page does, anywhere: a program's own view of a few settings, the showcase's Values scene. control_open(page, name) opens a preference's control at its next build, as a click would (a family's list, a colour's picker).

The showcase's Values scene: a Font_Family value gets the font picker, each family in its face

A locked preference (a policy, the command line) shows its control disabled. Page_Options.problem(user, name) gives what the program has to say under a line (a shortcut another program holds): it shows in red. Page_Options.status(user, name) says a preference's state plainly, under its line, in the weak text (the keys a shortcut got). Page_Options.page_foot(user, category, em) draws the program's own content under a page's preferences (not in a search): buttons, a list.

Each line whose value is the user's and differs from its default shows the reset button, whatever its control: differs_from_default(prefs, name) says when (a Keys value is compared as key combinations, so "ctrl+print" is "Ctrl+Print"). A value the user set equal to the default shows none. While one line of the page shown has it, a Restore defaults button beside the page's title puts all of them back (each through Page_Options.changed, as its own reset button does).

Global shortcuts

A program with global shortcuts (shortcuts.md) gives its service in Page_Options.shortcuts and, in Page_Options.shortcut_prefs, each preference that holds a shortcut's keys (a Keys Def) with the shortcut's id in the service:

Formula
SHORTCUTS := [?]prefs_page.Shortcut_Pref{{pref = "shortcut.region", id = "region"}, {pref = "shortcut.screen", id = "screen"}}
opts.shortcuts, opts.shortcut_prefs = app.shortcuts, SHORTCUTS[:]

Each line records keys. Under it, in the weak text, shortcuts.status_text ("Works in every program: Ctrl+Print.", "The system gave other keys…", "Waiting for the system's answer…"); in red, shortcuts.problem_text ("Another program holds Ctrl+Print: choose other keys.", "The system refused this shortcut.", keys that do not parse). While a field records keys, the page holds the service (shortcuts.hold): Windows would take the very keys being recorded. The program's status and problem run for its other preferences.

Themes from the program

With Page_Options.themes (the program's list: its own theme, then ui.THEMES), a Theme preference (appearance.theme, or a program's own) shows as the themes' cards and a click sets it. The cards show the version appearance.mode asks; for system, the one the program shows now (Page_Options.themes_light: its ui.Theme_Shown.light; the page does not ask the system each frame).

A program that updates itself (update.Updater, docs/update.md) gives it in Page_Options.updater, and in update_pref the preference whose line shows it ("": the standard update.auto). Under that line: the state in words (update.status_words: up to date, a version available, downloading, installed, the last check's failure, or that a package manager updates this copy), a Check now button, Install <version> when one is on offer, and Restart now when one is installed and the program gives Page_Options.restart. That procedure calls host.restart_after_exit(&program) and quits (getting-started.md, "A restart after the end").

Changes

A value goes through config.set_from_string at the User layer: every observer of the registry runs. A field applies its text on Enter, when it loses the keyboard, or when its line is hidden by a page switch, search filter or fold; a refused value stays as it was, and the reason shows under the line ("out of range: 1 to 64 KB"). flush(&page) commits any pending field edits before the caller saves, hides, closes or destroys the page (back_bar, escape_leaves and export_to call it too; destroy only frees memory). A number applies a key, a click, a notch of the wheel, a button or what is typed at once; a drag of its slider when it is let go. While the slider is held, Page_Options.preview(user, name, value) gets each value it moves to, for the program to show at once (a rounding, a size) without writing it. Page_Options.changed runs after each value set or reset: apply the change from there (or let standard_watch do it); the loop's config.user_writer_save writes the file off the loop.

Export and import

Export… asks for a file (ui.file_dialog), then writes the user's settings (what differs from the defaults) in the format of its extension: JSON (as the settings.json of Zed or VS Code), TOML, INI, or the program's own (.txt: config.export with .Own). The text is made on the interface's thread, a task writes it. Import… reads a file of the program's own format (a task reads it, config.load_text sets its values as the user's): settings carried from another machine. Page_Options.changed hears of each value that changed; the loop's writer saves them. JSON, TOML and INI are written only.

Formula
prefs_page.export_to(&page, path, prefs_page.export_format_of(path))   // what the dialog's answer does
prefs_page.import_from(&page, path)
text := config.export(&prefs, .Toml)

export_format_of(path, chosen = .Json) is the format of a file's extension (config.Export_Format: Json, Toml, Ini, Own), else chosen. The page must have been built once: its tasks answer to the state it is built in. What came of it shows at the sidebar's foot.

Themes of the user's own

Every program can let the user make themes: a file beside the preferences, [Name] sections of colours (themes.md, "A user's themes"). Themes_File keeps it, and Page_Options.themes_file shows it under the themes' cards: a line that says themes can be made, then the file's path as a link. A click makes the file from THEMES_TEMPLATE when it is not there (comment lines: the keys, the colour format, from = ..., the light versions, a commented example; nothing changes until a line is written) and opens it in the system's editor, on a task. It is read again when it changes.

Formula
prefs_page.themes_file_init(&app.themes_file, themes_path, app_themes[:])   // the program's themes: first, and what `from` names
defer prefs_page.themes_file_destroy(&app.themes_file)

// each build: a task looks at the file at most every THEMES_FILE_POLL_MS (2 s), and reads it when it changed
if prefs_page.themes_file_poll(&app.themes_file, &app.state) { show_theme_again(app) }
opts.themes, opts.themes_file = app.themes_file.all[:], &app.themes_file
  • all holds the program's themes, then the user's; a theme of the user's with the name of one of the program's takes its place. serial counts the reloads.
  • themes_file_poll(tf, state) -> bool is true on the build the new themes came in. It looks only while builds happen: a window at rest is not woken for it, its next build looks.
  • themes_file_open(tf, state) makes and opens the file (the link's click); a file that could not be written says so under the link (tf.error).
  • themes_file_write_template(path) -> bool writes the template, and its folder, when there is no file; a file there is never touched. It touches the disk: a task's.

Keep the Themes_File as long as the ui.State its tasks answer to.

Themes as cards

theme_cards(list, current, light, em, columns = 3) draws the themes of list columns to a row, each in its own colours (its version light): its surface, its name in its text, its hues as dots, a ring of its accent around the one named current. Every card has the column's width, the cards of a last row that is not full too, at their columns. A card too narrow for all its dots shows fewer. It returns the index of the one clicked, or -1.

The settings in place of the main view

A program with one window shows its settings in place of its main view (papier: in place of the history):

Formula
// the state: settings_open: bool, page: prefs_page.Page
open_settings :: proc(app: ^App) {   // the gear button, Ctrl+,
	app.settings_open = true
	prefs_page.focus_search(&app.page)
}

// in the build
if app.settings_open {
	o := settings_options(app)
	if !dialog_open && prefs_page.escape_leaves(&app.page) { app.settings_open = false }
	if prefs_page.back_bar(&app.page, o, "Settings", "Back to the history (Escape)", em) { app.settings_open = false }
	ui.next({width = ui.fill(), height = ui.fill()})
	prefs_page.build(&app.page, &app.prefs, o)
} else {
	build_main_view(app)
}

back_bar(page, o, title, back_tip, em) is a bar as wide as its parent: a back arrow (Lucide's arrow-left in Page_Options.icon_font, else the word "Back") whose tooltip is back_tip, then the title. It returns true when the arrow was pressed. escape_leaves(page) is true when Escape was pressed and no editor of a preference has the keyboard: that Escape gives up the editor first.

What's new

Page_Options.changelog (a Changelog, the program's) adds a What's new page, first of the toolkit's own: the program's CHANGELOG.md as a timeline: a rail with a dot at each version (the newest lit), a card per version (its number, its day and time, "Latest"), its changes by type under a pill of the type's hue and icon, their text laid out by trame:markdown. Every version is there (only those near the view are built: a lazy column). Over them, a search keeps the versions whose number, day or changes hold its words (ASCII case folded), a toggle per kind the changelog has hides or shows that kind's changes, and "N of M versions" says how many are kept; the list is worked out again only when the search, the kinds or the text change. On a narrow page (the settings in a dialog) the search, the toggles and the count flow onto more lines, each whole, and so do a card's number, day and "Latest". A page narrower than 34 em (510 px at the default font) is stacked: no rail, each kind's pill on a line of its own over its changes, which take the card's whole width; from 35 em it is wide again (the page's width at the last layout decides, whats-new.md). The changelog is written in English (Changelog.english, often #load("../CHANGELOG.md", string)); translations may give it in other languages (Changelog_Text{language, text}), and the page shows the one of the language in use, else the English one (changelog_text).

changelog_after_update(&c, &prefs, version, &announcer, open, user), once at start, compares version with the hidden general.seen_version (changelog_register registers it). Another version is an update: a message "Updated to 1.2.0" stays until it is clicked (ui.announce's stays), and the click calls open, where the program shows its settings at CHANGELOG_PAGE (show). The first start says nothing. changelog_destroy frees the page's text.

The licence

A program that sells a licence (licence.md) shows it on the toolkit's Licence page, worded the same in every program, after the program's pages. The program gives its product and where it keeps the key (licence.Store_Options), its name as people read it, its site's pricing page, and for the licence card its logo (the bytes of its PNG) and its vendor's name:

Formula
prefs_page.licence_init(&app.licence, &app.main.state, {
	store = {product = PRODUCT, program = APP_NAME, accept_dev = #config(DEBUG, false)},
	name = "Inspecteur", pricing_url = "https://inspecteur.froment.software/pricing/", owner = app.main.win,
	logo = identity.ICONS[6].png, vendor = "Froment Software",
})                                                         // at the start: the store, its first read (a task)
opts.licence = &app.licence                                // the settings: the Licence page
prefs_page.licence_install_file(&app.licence, path)        // a licence file dropped, or given on the command line
prefs_page.licence_end(&app.licence)                       // at the end, the window's State closed
  • The page says the state: Unregistered with "<name> is free; a licence supports its development.", or a key stored that is not valid (licence.error_text). Then what can be done: Buy a licence (opens pricing_url; none when it is ""), a field to paste a key and Register, Choose a licence file… (the system's dialog), Remove the licence (a second click removes; Escape gives the question up). Under them, a line says the key is checked on this computer with no network.
  • A registered licence is shown as its card (licence-card.md, ui.licence_card): the program's name and logo, the edition's title (licence.edition_title), the holder, the e-mail, the date and the order are on it, so no line under it says them again; a thank-you, Remove the licence and the line on the network follow. Its back says "<NAME> · <VENDOR>" in capitals (the name alone when vendor is "").
  • Every read and write of the key's file is a task of the ui.State given to licence_init (ui.task): the answer comes at its next build. One task at a time; a file given meanwhile waits for its turn (Licence.pending).
  • licence_registered(l) says whether the last read found a valid licence (false until it came); Licence.status is that read (licence.Status).
  • licence_end frees what the page holds; a task still on the chores keeps the store, left to the process's end.
  • The page's category is LICENCE_PAGE; the palette finds it by "licence", "license", "key", "register", "buy".

The installation

Every program installs itself the same way: one Install object holds the setup's Dialog (setup.md), offers the install at a start, keeps the user's answer in the settings, and shows the Installation page at the end of the sidebar. The program declares what it is, as data: a setup.Setup_Options (its desktop.Identity, its version, its install folder, its icons, its own options and prepare for its parts: the PATH, the start with the session).

Formula
prefs_page.install_init(&app.install, &app.prefs, setup_options())   // its settings loaded (registers install.choice)
prefs_page.install_vendor_mark(&app.install, &app.shared.r, VENDOR_MARK_PNG)   // the "By" line's mark
prefs_page.install_offer(&app.install, &app.main.state, offer = !app.demo)   // its window open: read on a task
// each frame
if prefs_page.install_frame(&app.install) == .Launched { quit() }   // the work that ended, the view's answer
opts.install = &app.install                                          // the settings: the Installation page
// --setup
prefs_page.install_open(&app.install)
// at the end, before the window's State goes; then last, the single instance released
prefs_page.install_end(&app.install)
prefs_page.install_launch(&app.install)
  • install_offer(in, state, offer) reads the install on a task; the installed copy deletes what an update left (.old files). When offer and setup.wanted say so (no install, one to repair, an older one to upgrade) and the user did not answer for this version, the setup's modal opens. Install.known and running_it say what the reading found (an updater wants to know which copy runs).
  • install_frame(in) -> setup.Event collects the work and the answer of the setup's view (a view of the window's Views, built at the end of the build; Install.logo is its mark): the answer goes to install.choice (INSTALL_CHOICE_PREF, hidden: installed, standalone, dismissed:<version>; a page left answers nothing; an Uninstall is standalone: the next start offers nothing). choice_after(ev, upgrade, saved, version) says what each event leaves; the offer obeys install_choice(in), the value for the run (a --pref install.choice=… over the user's file). It returns what happened: Launched, the program ends and install_launch starts the installed copy; Installed and Uninstalled: install_follow runs again.
  • install_follow(in) applies general.menu and general.autostart to the installed copy, on a task: when the install's reading says this copy is the installed one, its launcher in the applications menu and its start with the session follow the two settings, its other parts stay as the install left them. A copy that is not installed (a build, a Nix package) writes nothing, and the settings page hides the two. It runs by itself after the start's reading, after an install or an uninstall, and when either setting changes; one at a time, the last change winning. install_init's announcer says when the desktop refuses (nil: the log only). A program writes no code of its own for these two settings.
  • install_end(in) before the window's State goes: what an uninstall left is deleted once the process ends, the dialog's thread is waited for. install_launch(in) last, once the program's single instance is released: the installed copy asked for starts (started earlier, it would find this copy running and hand itself over to it).
  • install_vendor_mark(in, &renderer, png) -> bool, once the renderer exists: the vendor's mark of the "By" line of the modal and the page, a texture made from the PNG's bytes (a #load). Once: a later call does nothing (a window that opens again may call it again). A view already open takes it at once; install_end frees it. False: the bytes are no PNG, and the line names the vendor alone. Install.vendor_mark is the texture, for a program's own "By" line.
  • install_open(in) shows the modal (--setup, Settings > Apps' Uninstall). install_open_now(in): the modal is open, a program leaves the keyboard to it.
  • The page (Page_Options.install, category INSTALL_PAGE) is setup.page: while the modal is open it waits.

The command line is setup.command_of and setup.command_run (--install, --uninstall, --setup).

The panels of the window

Page_Options.views (the program's ui.Views) adds to the page window how far the frame's bottom panel goes across: Content, Left, Right or Full (views.md, Panels, "The corners"), and the top panel's while the frame has a top zone. A choice is the person's span (ui.views_space_set_span), kept with the layout in the views' memory, not in the settings file; its reset gives the program's back. A program whose pages have no window page adds {category = "window", title = "Window"} to them.

Diagnostics

Page_Options.diagnostics (a Diagnostics_Source of the window the settings are in) adds a Diagnostics page after the installation: what a person on a slow machine copies and sends. A program on the toolkit's host gives prefs_page.diagnostics_of(&app.main); a program with a loop of its own fills the source itself: its renderer, its window, a host.Frame_Ring it feeds with host.frame_add, and whether partial redraw is on. No renderer: no page. diagnostics_rows(source, version, system) gives the lines the page shows. One line each: the program (Page_Options.version), the toolkit (ui.VERSION), the system (read once on a task), the graphics adapter and API (render.adapter_info, with a warning above the lines when it is a software rasterizer), the window's size in pixels and its scale, the last frames' total, build and draw times (median and 95th percentile: host.frame_stats, kept in every build), and partial redraw with the share of the pixels it drew. The lines are made again once a second while the page is shown (DIAGNOSTICS_REFRESH_MS); Copy puts them on the clipboard as key: value lines (diagnostics_text).

The toolkit's pages in the palette

A page of its own (Page_Info.build) with Page_Info.tags is an item of the palette's settings source: its title, the group "Settings", its icon and its tags; its name is the page's category, and show(page, prefs, o, category) puts that page up, the search cleared. The Licence, Installation and Diagnostics pages have theirs ("licence", "key", "buy"; "install", "uninstall", "path"; "gpu", "performance", "slow"). Page_Info.user is what build is given (nil: Page_Options.user).

Keyboard

Tab goes through the search, the pages and the controls. focus_search(&page) gives the search the keyboard at the next build (a program opens the page with it). editing(&page) says whether a field (a number's too) has the keyboard: a program that closes the page on Escape leaves that Escape to the field.

The settings in the command palette

palette_settings_add(&palette, &settings, &prefs, &page, options, open, user) adds the toolkit's settings source to a program's command palette (palette.md): the prefix :, and the plain search. It gives one item per preference the pages show (a hidden one is not): its title is the one the page gives it, its group Settings · <page>, its icon the page's (else Lucide's sliders), its tags the preference's (config.Def.tags: other words the settings' search and the palette find it by, "colours" and "dark" for a theme), its name its last text (a search by appearance.theme finds it), its value in use at its right. A preference that a policy or the command line fixes is greyed, its reason its detail.

Choosing a switch flips it (Page_Options.changed then saves it) and the palette stays open, the switch's mark following. Choosing another preference opens its run mode in the palette: its control from the same table as the page (control_of), a change written at once (and Page_Options.changed called), Enter keeps it, Escape puts back the value of before (palette.md, "The run mode"). Shift+Enter goes to its line: the page shows its page (its search cleared, its Advanced part unfolded for an advanced one), open(user) shows the settings, and the line, whose act name is setting:<name>, is brought to the top of the page, focused and lit. palette_settings_add also installs the commands' forms (palette_forms_use(&palette): a program without the settings source calls it itself).

show(page, prefs, options, name) puts one preference alone on its page for a program's own jump (a link, the What's new page): the page's search holds its name in quotes, and the page under the search is its own.

The source reads the preferences again when one is registered, and when the language changes: a frame walks none. options(user) -> Page_Options is asked each time the source reads or acts, so its slices (the themes, the pages) are the program's of that moment: one add at the start is enough, and a second add does nothing. When the pages a program shows change, it bumps palette_settings.source.version. Palette_Settings stays where it is while the palette has it.

Formula
prefs_page.palette_settings_add(&app.palette, &app.palette_settings, &app.prefs, &app.page,
    proc(user: rawptr) -> prefs_page.Page_Options { return settings_options((^App)(user)) },
    proc(user: rawptr) { (^App)(user).settings_open = true }, app)

The updates

Updates is a program's Updater (update.md) with what every program wrote around it:

Formula
prefs_page.updates_start(&app.updates, {
    product = PRODUCT, repository = "owner/app", version = APP_VERSION,
    prefs = &app.prefs, install = &app.install, state = &app.main.state, window = app.main.win,
})
// each frame
if changed, st := prefs_page.updates_follow(&app.updates); changed {
    host.host_settle(&app.main)                                    // the badge and the settings show the new state
    if words, bad := update.notice(st); words != "" { say(app, bad, words) }
    if st.phase == .Installed && !app.visible { restart(app) }    // host.restart_after_exit(&p), then quit
}
prefs_page.updates_stop(&app.updates)   // at the end, before the windows go
  • updates_start(u, o) reads the folder from update.base_url (update_source), else the repository's latest release (update.latest_release_folder); the user agent is <product>/<version>; at each news it wakes o.window (or calls o.news(o.user), on the updater's thread, for a program with several windows to wake).
  • updates_follow(u) -> (changed, status) applies update.auto first: Install when the preference is on and Install.known and running_it say this is the installed copy (install_offer's reading), else Off (Check now still works); a change of either is followed with no call of the program. Then changed is true once per change of the updater. When a version is in place, the installed copy's manifest gets it (setup.updated with Install.options, on a chore of o.state; a failure goes to the log).
  • u.updater is what Page_Options.updater and update_badge take; u.folder is the folder read (a program that reads more files of its release there).

The update in the status bar

update_badge(updater, restart, user) is a button for a program's status bar: "Install 0.16.0" when a version is on offer, "Downloading 0.16.0…" while it comes, "Restart to update to 0.16.0" once it is in place (restart(user): the program starts again). It builds nothing when there is nothing to do and returns nil; else it returns its box, whose rect (the last layout's) is the room it takes, for a bar that fits its other parts beside it. Its words are never cut.

The badge is the one place of a program's window that shows the update's phase. The program's status line or toasts say only update.notice(status) (update.md): never the phase again beside the badge.

Edit this page on GitHub