# Interfaces: apps built from views Pinnacle's interface library is Mithril (`code.garage44.eu/jeroen/mithril`), the same library the web and Cartopolis use, taken without `std` and with no code from outside our own repositories. An app describes its screen as a view — elements, the component library's classes, signals for what changes — and `pinnacle-view` (`view/`) styles it, lays it out for the window, draws it and turns input into the view's events. **A new app, or an app being rebuilt, is built this way**; hand-placed rectangles (`pinnacle_layout`) and immediate drawing (`pinnacle_ui::theme`) are what the older apps still use, and each moves over when a session works on it. On views so far: the home screen, About, Settings, Clock, Notes, Calculator, the Store, Contacts, Files, Fien, Paint, Messages, Calls, Bluetooth, the terminal, and the display server's password, question and notification list. Still drawn by hand: the status bar, the home bar and the banner. ## An app ```rust let mut app = App::new("Clock"); let mut screen = Screen::new(app.width, app.height); let seconds = signal(now()); screen.mount(page(seconds.clone())); // el("main")…, the library's classes screen.draw(&mut app.canvas(), true); app.present_all(); loop { match app.next_event(deadline) { Event::Input(e) => { screen.input(&e); // clicks reach the view's handlers if let Some(area) = screen.draw(&mut app.canvas(), false) { app.present(area); // only what changed } } Event::Shown(true) | Event::Resized => { screen.resize(app.width, app.height); /* draw all */ } Event::Clipboard(text) => { screen.paste(&text); } … } } ``` - **Layout is the stylesheet's**: flex, wrapping, `max-width` columns, `100vh`; a page taller than the window scrolls by a finger dragged more than 8 px. Logical pixels are drawn at 4/3 (`SCALE`): the sheet's 15 px body is the system's 20 px. `tokens()` is the sheet in the system's colours. - **Handlers write signals; the loop reads them** (`tapped.get_untracked()` after `screen.input`), so the app's state stays plain Rust beside the view. - **Text fields** (`input`, `textarea`) take the focus on a tap (or `@focus`), and `Screen` brings the on-screen keyboard up beneath them; ctrl+V and ctrl+C come out of `Screen::clipboard` for the app to ask the display (`App::paste`). - **Name every control a test taps** (`data-name="…"`) and call `screen.announce(": button ")` after drawing a page: `cargo xtask` taps `Session::tap_named(": button ", "")`, dragging it into view first if it is off the screen. Never compute a control's place from `pinnacle_layout` for an app on views: the stylesheet places it. - **The app's own pixels** go in a ``: `Screen::draw_with` calls the app back with its name and place for each one it draws (Paint's drawing, Calls' video), and moving its `data-revision` on draws it again, and only it. A pointer on it is the app's when its `pointerdown` handler prevents the default: the moves and the release then come to it, and the page does not scroll. - **Rules of the app's own** (`Screen::with_rules(&css! { … })`) come after the library's, for a state it has no class for: the home screen's icon sinks on `:active`. - **App icons** are drawn by `pinnacle_ui::icons` into a `` named by `icons::canvas_name`; `Icons::draw_canvas` in the app's `draw_with` fills each (the home screen, the Store). How they look: `docs/brand/README.md`. - A one-line field with `enterkeyhint="send"` or `"go"` keeps the focus and the keyboard after Enter (Messages, the password); any other is done with Enter and gives it up. - **An element that edits text itself** (`role="textbox"`, `tabindex="0"`: the terminal's session, Fien) gets the keys as the DOM names them, Ctrl held or not, and `Screen` brings the keyboard up for it; `Screen::keyboard_shown` says whether it is up, for keys of the app's own above it. A press on a control beside the field leaves the keyboard as it is (make such a control a `div role="button"`, which takes no focus), so what is pressed does not move. - Print a line once the first frame is drawn (`clock: drawn`) when a demo photographs the app right after it opens: a view's first frame comes later than a hand-drawn one. ## Facts that bit - Mithril's crates build **without debug info** in release (`Cargo.toml`'s `profile.release.package.mithril_*`): with it, an app was 16.5 MB instead of 2.4 MB and the PC's self-check disk filled. The PC's programs are stripped too. - A grid given a height shares it among its rows (`fr` rows by fraction, else the auto rows evenly), and `aspect-ratio` makes an auto side follow the other: a round button is `width: 120px; aspect-ratio: 1; border-radius: 50%`. - Checkboxes, radio buttons, switches (`m-switch`) and sliders are drawn whole (the tick, the knob, the track); a slider follows the finger and says `input`, then `change` at the release. - **Bold is the one face drawn twice**, a pixel or so apart: Pinnacle has one weight of its sans and one of its mono (`font-family: monospace`), so `font-weight` 600 and up is emboldened, and the measure counts the extra. - The home screen's tiles are named by title: `Session::tap_named("launcher: tile ", "Notes")`. The on-screen keyboard of an app on views spans the window's bottom, so `Session::type_text` taps it there. - Mithril is **pinned by revision** in `view/Cargo.toml`; a change in Mithril lands there first, then the pin moves here. Keep `Cargo.lock` in step when rebasing (a stale one dropped `pinnacle-modem` from main once and broke `--locked`).