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
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-widthcolumns,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()afterscreen.input), so the app's state stays plain Rust beside the view. - Text fields (
input,textarea) take the focus on a tap (or@focus), andScreenbrings the on-screen keyboard up beneath them; ctrl+V and ctrl+C come out ofScreen::clipboardfor the app to ask the display (App::paste). - Name every control a test taps (
data-name="…") and callscreen.announce("<app>: button ")after drawing a page:cargo xtasktapsSession::tap_named("<app>: button ", "<name>"), dragging it into view first if it is off the screen. Never compute a control's place frompinnacle_layoutfor an app on views: the stylesheet places it. - The app's own pixels go in a
<canvas data-name="…">:Screen::draw_withcalls the app back with its name and place for each one it draws (Paint's drawing, Calls' video), and moving itsdata-revisionon draws it again, and only it. A pointer on it is the app's when itspointerdownhandler 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::iconsinto a<canvas>named byicons::canvas_name;Icons::draw_canvasin the app'sdraw_withfills 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, andScreenbrings the keyboard up for it;Screen::keyboard_shownsays 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 adiv 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'sprofile.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 (
frrows by fraction, else the auto rows evenly), andaspect-ratiomakes an auto side follow the other: a round button iswidth: 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 saysinput, thenchangeat 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), sofont-weight600 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, soSession::type_texttaps it there. - Mithril is pinned by revision in
view/Cargo.toml; a change in Mithril lands there first, then the pin moves here. KeepCargo.lockin step when rebasing (a stale one droppedpinnacle-modemfrom main once and broke--locked).