Onboarding: Add layout and depth pages

This commit is contained in:
James Babcock committed 2026-10-10 21:52:19 -07:00
1 parent 1d257e8bb6
commit 6b1e64c5ac
17 files changed
+766 -74

No files matched your search

+3 -2
View File
@@ -13,6 +13,7 @@ const LABEL_GAP = 24;
/** None / Minimal / Full, each with a one-line summary; a tap saves the selected level. */
export class DataCollectionPage implements OnboardingPage {
readonly fullscreen = true;
/** Width of the level-name column, measured each paint. */
private labelColumnWidth = 0;
private readonly menu = new Menu<DataCollectionLevel>({
@@ -31,9 +32,9 @@ export class DataCollectionPage implements OnboardingPage {
paint(image: GrayImage, focused: boolean): void {
const top = drawPageHeading(
image,
"Faceclaw statistics",
"Data Sharing",
(global.isIOS ? "If using TestFlight, crash/usage reports cannot be disabled here. " : "") +
"Choose optional Faceclaw statistics. Change later in Settings > Privacy.",
"Choose how much data you want to share. Change later in Settings > Privacy.",
3,
) + CONTENT_GAP;
const body = onboardingFont("body");
+71
View File
@@ -0,0 +1,71 @@
import type { GrayImage } from "../../graphics/image";
import { appSwitcherPositionSetting, uiDepthSetting, type UiDepth } from "../../ui/dashboard-settings";
import type { InputEvent } from "../../ui/gestures";
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
import { layoutHasDepth } from "./layout-page";
import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
const COLUMN_WIDTH = 220;
/**
* The whole display's stereo depth, after a layout that has one (Bottom or
* Popup). Not fullscreen, so the page sits in the chosen layout, and the
* depth is saved as the selection moves: the shell shifts everything with
* it, which is the only way to see the difference.
*/
export class DepthPage implements OnboardingPage {
private readonly menu = new Menu<UiDepth>({
items: uiDepthSetting.values,
wrap: false,
rowGap: 2,
highlight: { radius: 8 },
getHeight: () => listRowHeight(onboardingFont("body")),
draw: (args) => this.drawRow(args),
});
applies(): boolean {
return layoutHasDepth(appSwitcherPositionSetting.get());
}
enter(): void {
this.menu.select(uiDepthSetting.values.indexOf(uiDepthSetting.get()));
}
paint(image: GrayImage, focused: boolean): void {
const top = drawPageHeading(
image,
"Depth",
"Swipe to move the display nearer or farther away, then tap to continue. Change later in Settings > Customization.",
) + CONTENT_GAP;
this.menu.paint(
image,
{ x: PAGE_X - 10, y: top, width: COLUMN_WIDTH, height: image.height - top - BOTTOM_MARGIN },
focused,
);
}
handleInput(event: InputEvent, nav: OnboardingNav): void {
switch (event.type) {
case "scroll-up":
case "scroll-down": {
void this.menu.handleInput(event);
const depth = this.menu.selectedItem;
if (depth !== null) uiDepthSetting.set(depth);
return;
}
case "click":
nav.next();
return;
default:
return;
}
}
private drawRow({ image, item: depth, x, y, selected }: MenuDrawArgs<UiDepth>): void {
image.drawText(onboardingFont("body"), x + 10, y + LIST_ROW_TEXT_INSET, uiDepthSetting.displayValue(depth), selected ? 255 : 190);
}
}
+2 -1
View File
@@ -4,7 +4,8 @@ import { ONBOARDING_APP_ID } from "./onboarding-progress";
/**
* First-run setup on the glasses: welcome, text size, data-collection
* preference. The connection controllers open it on their own when it is
* preference, layout (app switcher position) and, for layouts that have
* one, depth. The connection controllers open it on their own when it is
* due (claimGlassesOnboardingAutoLaunch); the launcher entry reruns it.
*/
const onboardingApp: AppDefinition = {
+1
View File
@@ -7,6 +7,7 @@ import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from
/** Paginate the notice so no disclosure is silently clipped on a short glasses viewport. */
export class IosPrivacyPage implements OnboardingPage {
readonly fullscreen = true;
private page = 0;
private pageCount = 1;
+259
View File
@@ -0,0 +1,259 @@
import { G2_LENS_WIDTH, type GrayImage, type UiFont } from "../../graphics/image";
import { appSwitcherPositionSetting, statusBarPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
import type { InputEvent } from "../../ui/gestures";
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
import { MIN_WINDOW_HEIGHT, SIDEBAR_WIDTH, SWITCHER_ROW_HEIGHT, TOP_BAR_HEIGHT } from "../../ui/shell/geometry";
import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
/** Diagram width as a fraction of the display's: the most a diagram is drawn at. */
const DIAGRAM_SCALE = 0.4;
/** The real-display area a diagram covers: a 288px window band and a bottom switcher row under it. */
const DIAGRAM_AREA_HEIGHT = MIN_WINDOW_HEIGHT + SWITCHER_ROW_HEIGHT;
/** Padding inside a cell's selection box, round the diagram and its caption. */
const CELL_PADDING = 8;
const CAPTION_GAP = 4;
const COLUMN_GAP = 16;
const ROW_GAP = 6;
const DEPTH_SUBTITLE = "Customizable Depth";
/** Grid order, in rows of two: the layouts with depth on top. */
const LAYOUT_ORDER: readonly AppSwitcherPosition[] = ["bottom", "popup", "left", "right"];
/** Selected on the first visit, and marked. */
const RECOMMENDED_LAYOUT: AppSwitcherPosition = "bottom";
/** Whether a layout leaves the side margins the display's stereo depth shifts into (geometry.ts uiDepth). */
export function layoutHasDepth(position: AppSwitcherPosition): boolean {
return position === "bottom" || position === "popup";
}
/**
* The app switcher position, as a 2×2 grid of captioned diagrams of each
* layout, Bottom (recommended, and selected at first) and Popup on top;
* swipes move through them in reading order, a tap saves the selected one.
* The page is fullscreen, so the diagrams get 40% of the display's width
* each. Choosing a layout reflows open windows (the dashboard controller
* watches the setting).
*/
export class LayoutPage implements OnboardingPage {
readonly fullscreen = true;
/** Kept across visits, so going back returns to the last choice. */
private selected = LAYOUT_ORDER.indexOf(RECOMMENDED_LAYOUT);
paint(image: GrayImage, focused: boolean): void {
const top = drawPageHeading(
image,
"Layout",
"Swipe to choose where the app switcher goes, then tap to continue.",
) + CONTENT_GAP;
const title = onboardingFont("body");
const subtitle = onboardingFont("detail");
const captionHeight = CAPTION_GAP + title.lineHeight + subtitle.lineHeight;
const available = image.height - top - BOTTOM_MARGIN;
// Short of DIAGRAM_SCALE only where two rows of cells wouldn't fit.
const scale = Math.min(
DIAGRAM_SCALE,
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / DIAGRAM_AREA_HEIGHT,
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / G2_LENS_WIDTH,
);
const diagramWidth = Math.round(G2_LENS_WIDTH * scale);
const diagramHeight = Math.round(DIAGRAM_AREA_HEIGHT * scale);
const cellWidth = diagramWidth + 2 * CELL_PADDING;
const cellHeight = diagramHeight + 2 * CELL_PADDING + captionHeight;
const left = Math.round((image.width - 2 * cellWidth - COLUMN_GAP) / 2);
const gridTop = top + Math.max(0, Math.round((available - 2 * cellHeight - ROW_GAP) / 2));
LAYOUT_ORDER.forEach((position, index) => {
const x = left + (index % 2) * (cellWidth + COLUMN_GAP);
const y = gridTop + Math.floor(index / 2) * (cellHeight + ROW_GAP);
const selected = index === this.selected;
if (selected) {
if (focused) image.fillRoundedRect(x, y, cellWidth, cellHeight, MENU_HIGHLIGHT_FILL, 8);
image.drawRoundedRect(x, y, cellWidth, cellHeight, MENU_HIGHLIGHT_STROKE, 8);
}
drawLayoutDiagram(new Diagram(image, x + CELL_PADDING, y + CELL_PADDING, scale), position);
const centre = (text: string, font: UiFont, textY: number, value: number) =>
image.drawText(font, x + Math.round((cellWidth - font.measureText(text)) / 2), textY, text, value);
const captionTop = y + CELL_PADDING + diagramHeight + CAPTION_GAP;
const name = appSwitcherPositionSetting.displayValue(position);
const caption = position === RECOMMENDED_LAYOUT ? `${name} (Recommended)` : name;
centre(caption, title, captionTop, selected ? 255 : 190);
if (layoutHasDepth(position)) {
centre(DEPTH_SUBTITLE, subtitle, captionTop + title.lineHeight, selected ? 210 : 150);
}
});
}
handleInput(event: InputEvent, nav: OnboardingNav): void {
const last = LAYOUT_ORDER.length - 1;
switch (event.type) {
case "scroll-up":
this.selected = Math.max(0, this.selected - 1);
return;
case "scroll-down":
this.selected = Math.min(last, this.selected + 1);
return;
case "click":
appSwitcherPositionSetting.set(LAYOUT_ORDER[this.selected]!);
nav.next();
return;
default:
return;
}
}
}
// Diagram brightnesses: brighter than the real chrome's, which the diagrams
// shrink to a few pixels.
const AREA_OUTLINE = 30;
const CHROME_LINE = 100;
const WINDOW_FRAME = 140;
const ICON = 160;
const SELECTED_ICON = 230;
const STATUS = 140;
const CONTENT = 110;
const CONTENT_TITLE = 170;
/** Window content under a popup switcher, which dims it. */
const DIM = 0.5;
/**
* Draws in real-display pixels, scaled into a cell: the DIAGRAM_AREA_HEIGHT
* rows from the diagram's top, or from `top` rows down (see from).
*/
class Diagram {
constructor(
private readonly image: GrayImage,
private readonly x: number,
private readonly y: number,
private readonly scale: number,
private readonly top = 0,
) {}
/** The same diagram with its row 0 `top` rows down. */
from(top: number): Diagram {
return new Diagram(this.image, this.x, this.y, this.scale, top);
}
private box(x: number, y: number, width: number, height: number) {
y += this.top;
const left = this.x + Math.round(x * this.scale), top = this.y + Math.round(y * this.scale);
return {
x: left,
y: top,
width: Math.max(1, this.x + Math.round((x + width) * this.scale) - left),
height: Math.max(1, this.y + Math.round((y + height) * this.scale) - top),
};
}
fill(x: number, y: number, width: number, height: number, value: number, radius = 0): void {
const box = this.box(x, y, width, height);
if (radius) this.image.fillRoundedRect(box.x, box.y, box.width, box.height, value, Math.max(1, Math.round(radius * this.scale)));
else this.image.fillRect(box.x, box.y, box.width, box.height, value);
}
outline(x: number, y: number, width: number, height: number, value: number, radius = 0): void {
const box = this.box(x, y, width, height);
this.image.drawRoundedRect(box.x, box.y, box.width, box.height, value, Math.max(0, Math.round(radius * this.scale)));
}
/** A one-pixel line along a real-pixel row (horizontal) or column. */
hline(x: number, y: number, width: number, value: number): void {
const box = this.box(x, y, width, 1);
this.image.fillRect(box.x, box.y, box.width, 1, value);
}
vline(x: number, y: number, height: number, value: number): void {
const box = this.box(x, y, 1, height);
this.image.fillRect(box.x, box.y, 1, box.height, value);
}
}
/**
* A layout as the real chrome lays it out (geometry.ts, chrome-layer.ts),
* to scale and simplified: the window band with its status bar and frame,
* and the switcher with a few icons, the first selected. Status bar
* placement follows the current setting. Only a bottom switcher row takes
* rows under the band; without one, the band sits centred in their place,
* as the band and row share the screen's slack.
*/
function drawLayoutDiagram(area: Diagram, position: AppSwitcherPosition): void {
area.outline(0, 0, G2_LENS_WIDTH, DIAGRAM_AREA_HEIGHT, AREA_OUTLINE, 12);
const d = position === "bottom" ? area : area.from((DIAGRAM_AREA_HEIGHT - MIN_WINDOW_HEIGHT) / 2);
const statusAtBottom = statusBarPositionSetting.get() === "bottom";
const windowLeft = SIDEBAR_WIDTH / 2, windowWidth = G2_LENS_WIDTH - SIDEBAR_WIDTH;
switch (position) {
case "left":
case "right": {
const stripLeft = position === "left" ? 0 : G2_LENS_WIDTH - SIDEBAR_WIDTH;
const contentLeft = position === "left" ? SIDEBAR_WIDTH : 0;
drawStatusBar(d, contentLeft, 0, windowWidth, true);
drawContent(d, contentLeft, TOP_BAR_HEIGHT, windowWidth, MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT, 1);
const separator = position === "left" ? SIDEBAR_WIDTH - 1 : stripLeft;
d.vline(separator, TOP_BAR_HEIGHT, MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT, CHROME_LINE);
// One column of icons against the separator.
const column = position === "left" ? SIDEBAR_WIDTH - 36 : stripLeft;
for (let slot = 0; slot < 4; slot++) drawIcon(d, column + 2, TOP_BAR_HEIGHT + 10 + slot * 40, slot === 0);
return;
}
case "bottom": {
// With the status bar in the row, the window's header is just the frame's top.
const contentTop = statusAtBottom ? 1 : TOP_BAR_HEIGHT;
if (!statusAtBottom) drawStatusBar(d, windowLeft, 0, windowWidth, false);
drawContent(d, windowLeft, contentTop, windowWidth, MIN_WINDOW_HEIGHT - contentTop, 1);
d.outline(windowLeft - 1, contentTop - 1, windowWidth + 2, MIN_WINDOW_HEIGHT - contentTop + 2, WINDOW_FRAME, 8);
for (let slot = 0; slot < 4; slot++) drawIcon(d, windowLeft + 1 + slot * 40, MIN_WINDOW_HEIGHT + 2, slot === 0);
if (statusAtBottom) drawStatusItems(d, windowLeft + windowWidth, MIN_WINDOW_HEIGHT + 4);
return;
}
case "popup": {
const statusTop = statusAtBottom ? MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT : 0;
const contentTop = statusAtBottom ? 1 : TOP_BAR_HEIGHT;
const contentHeight = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 1;
drawStatusBar(d, windowLeft, statusTop, windowWidth, false);
drawContent(d, windowLeft, contentTop, windowWidth, contentHeight, DIM);
d.outline(windowLeft - 1, contentTop - 1, windowWidth + 2, contentHeight + 2, WINDOW_FRAME, 8);
// The popup: a row of icons over the selected window's title, centred on the content.
const box = { width: 272, height: 98 };
const boxLeft = (G2_LENS_WIDTH - box.width) / 2;
const boxTop = contentTop + (contentHeight - box.height) / 2;
d.fill(boxLeft, boxTop, box.width, box.height, 0);
d.outline(boxLeft, boxTop, box.width, box.height, WINDOW_FRAME);
const iconsLeft = boxLeft + (box.width - (3 * 48 - 4)) / 2;
for (let slot = 0; slot < 3; slot++) drawIcon(d, iconsLeft + slot * 48 + 6, boxTop + 18, slot === 0);
d.fill(G2_LENS_WIDTH / 2 - 50, boxTop + 70, 100, 12, STATUS, 6);
return;
}
}
}
/** A status bar along a window's top or bottom edge; `divider` draws its line toward the window. */
function drawStatusBar(d: Diagram, x: number, y: number, width: number, divider: boolean): void {
if (divider) d.hline(x, y + TOP_BAR_HEIGHT - 1, width, CHROME_LINE);
drawStatusItems(d, x + width, y);
}
/** Notification icons, a battery and the clock, ending at `right`, in a status bar's 28 rows from `top`. */
function drawStatusItems(d: Diagram, right: number, top: number): void {
d.fill(right - 64, top + 7, 56, 14, STATUS, 4);
d.outline(right - 108, top + 8, 32, 12, STATUS, 2);
d.outline(right - 148, top + 4, 20, 20, CHROME_LINE, 4);
d.outline(right - 176, top + 4, 20, 20, CHROME_LINE, 4);
}
/** A switcher icon (32px); the selected one filled, as the switcher's selection tab is. */
function drawIcon(d: Diagram, x: number, y: number, selected: boolean): void {
if (selected) d.fill(x, y, 32, 32, SELECTED_ICON, 6);
else d.outline(x, y, 32, 32, ICON, 6);
}
/** Stand-in window content: a title and list rows, the first selected. */
function drawContent(d: Diagram, x: number, y: number, width: number, height: number, brightness: number): void {
const rowWidths = [width - 60, 300, 360, 240];
d.fill(x + 18, y + 14, 150, 18, CONTENT_TITLE * brightness, 6);
d.outline(x + 8, y + 44, width - 16, 34, CONTENT * brightness, 8);
for (let row = 0; row < rowWidths.length; row++) {
const rowTop = y + 52 + row * 44;
if (rowTop + 18 > y + height) break;
d.fill(x + 18, rowTop, Math.min(rowWidths[row]!, width - 36), 18, CONTENT * brightness, 6);
}
}
+36 -14
View File
@@ -5,7 +5,9 @@ import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow }
import { shell } from "../../ui/shell/shell";
import { findSoundEffect, playSoundEffect } from "../../ui/sound-effects";
import { DataCollectionPage } from "./data-collection-page";
import { DepthPage } from "./depth-page";
import { IosPrivacyPage } from "./ios-privacy-page";
import { LayoutPage } from "./layout-page";
import { markGlassesOnboardingFinished, ONBOARDING_APP_ID } from "./onboarding-progress";
import type { OnboardingPage } from "./onboarding-page";
import { TextSizePage } from "./text-size-page";
@@ -25,7 +27,7 @@ export function createOnboardingAppWindow(options: InProcessAppOptions): InProce
const pages: OnboardingPage[] = [
new WelcomePage(), new TextSizePage(),
...(global.isIOS ? [new IosPrivacyPage()] : []),
new DataCollectionPage(),
new DataCollectionPage(), new LayoutPage(), new DepthPage(),
];
const app = createInProcessWindow({
appId: ONBOARDING_APP_ID,
@@ -34,11 +36,17 @@ export function createOnboardingAppWindow(options: InProcessAppOptions): InProce
iconLetter: "On",
icon: "sparkles",
closeable: true,
fullscreen: pages[0]!.fullscreen,
actions: options.actions,
baseLayer: new OnboardingLayer(pages, () => {
markGlassesOnboardingFinished();
shell.closeWindow(ONBOARDING_WINDOW_ID);
}),
baseLayer: new OnboardingLayer(
pages,
// Only called on page changes, by when `app` is set.
(fullscreen) => app.setFullscreen(fullscreen),
() => {
markGlassesOnboardingFinished();
shell.closeWindow(ONBOARDING_WINDOW_ID);
},
),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
@@ -61,15 +69,17 @@ function playWelcomeSound(actions: LayerActions): void {
}
/**
* Hosts the current page. Double-click steps back a page, or leaves the app
* from the first one (the standard yield to the app switcher); every other
* gesture goes to the page.
* Hosts the current page, fullscreen or not as it asks. Double-click steps
* back a page, or leaves the app from the first one (the standard yield to
* the app switcher); every other gesture goes to the page. Pages that don't
* apply (Depth beside a side-strip app switcher) are skipped either way.
*/
class OnboardingLayer implements Layer {
export class OnboardingLayer implements Layer {
private index = 0;
constructor(
private readonly pages: readonly OnboardingPage[],
private readonly setFullscreen: (fullscreen: boolean) => void,
private readonly finish: () => void,
) {
pages[0]!.enter?.();
@@ -84,20 +94,32 @@ class OnboardingLayer implements Layer {
async handleInput(event: InputEvent): Promise<void> {
if (event.type === "double-click") {
if (this.index === 0) shell.yieldFocusToSidebar();
else this.show(this.index - 1);
const previous = this.applicableIndex(this.index - 1, -1);
if (previous === null) shell.yieldFocusToSidebar();
else this.show(previous);
return;
}
await this.pages[this.index]!.handleInput(event, { next: () => this.next() });
}
private next(): void {
if (this.index + 1 < this.pages.length) this.show(this.index + 1);
else this.finish();
const next = this.applicableIndex(this.index + 1, 1);
if (next === null) this.finish();
else this.show(next);
}
/** The first page from `index` on in direction `step` that applies, if any. */
private applicableIndex(index: number, step: 1 | -1): number | null {
for (; index >= 0 && index < this.pages.length; index += step) {
if (this.pages[index]!.applies?.() ?? true) return index;
}
return null;
}
private show(index: number): void {
this.index = index;
this.pages[index]!.enter?.();
const page = this.pages[index]!;
page.enter?.();
this.setFullscreen(page.fullscreen ?? false);
}
}
+8
View File
@@ -15,6 +15,14 @@ export type OnboardingNav = {
* viewport and handles every other gesture.
*/
export interface OnboardingPage {
/**
* Show the page fullscreen: the whole 640×480 panel, with the app switcher
* and status bar hidden. Otherwise it is an ordinary window in the
* chosen layout.
*/
readonly fullscreen?: boolean;
/** Whether the page belongs in the flow right now; skipped both ways when false. */
applies?(): boolean;
/** The page became current, going forward or back. */
enter?(): void;
paint(image: GrayImage, focused: boolean): void;
+47 -33
View File
@@ -1,4 +1,4 @@
import { GrayImage, type UiFont } from "../../graphics/image";
import type { GrayImage, UiFont } from "../../graphics/image";
import { installedFontPath } from "../../graphics/installed-fonts";
import { wrapText } from "../../graphics/textwrap";
import { TtfFont } from "../../graphics/ttf-font";
@@ -11,20 +11,29 @@ import {
} from "../../graphics/ui-fonts";
import { FONT_SIZE_CHOICES } from "../../ui/font-picker";
import type { InputEvent } from "../../ui/gestures";
import { Menu, MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE, type MenuBox, type MenuDrawArgs } from "../../ui/menu-core";
import { Menu, type MenuBox, type MenuDrawArgs } from "../../ui/menu-core";
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
const CONTENT_GAP = 10;
const BOTTOM_MARGIN = 8;
const SIZE_COLUMN_WIDTH = 84;
const COLUMN_GAP = 12;
const PREVIEW_PADDING = 10;
const ROW_GAP = 2;
const PREVIEW_TEXT = "This is how text will look on your glasses.";
/** Drawn while they fit, so smaller sizes visibly show more rows. */
const PREVIEW_ROWS = ["Timers", "Weather", "Music", "Settings", "Files"];
/** Between a size and its "Recommended" note. */
const NOTE_GAP = 8;
/** The sizes offered here; Settings has the full range. */
const SIZE_CHOICES = FONT_SIZE_CHOICES.filter((size) => size >= 12 && size <= 18);
/** Selected on the first visit, and marked. */
const RECOMMENDED_SIZE = 16;
const RECOMMENDED_NOTE = "Recommended";
/** Drawn while they fit, so smaller sizes visibly show more words. */
const PREVIEW_PARAGRAPHS = [
"This is how text will look on your glasses.",
"Smaller sizes fit more words on the display at once, while larger sizes are easier to read at a " +
"glance or on the move. Most people find the recommended size a good balance between the two.",
];
/** The UI font's face, as far as this page is concerned: resizable (TTF) or not (bitmap). */
type Face =
@@ -32,12 +41,14 @@ type Face =
| { kind: "fixed"; label: string };
/**
* The UI font's size, over a preview of list rows and body text in the
* chosen size. The face and weight stay as they are (they live in the
* Settings font picker); a bitmap face has only one size, so the page just
* says so. The size is saved on tap, not while scrolling.
* The UI font's size, 12 to 18px (16 recommended, and selected at first),
* beside a preview of text in the selected size. The face and weight stay
* as they are (they live in the Settings font picker); a bitmap face has
* only one size, so the page just says so. The size is saved on tap, not
* while scrolling.
*/
export class TextSizePage implements OnboardingPage {
readonly fullscreen = true;
private face: Face = { kind: "fixed", label: "Terminus" };
private readonly sizeMenu = new Menu<number>({
wrap: false,
@@ -52,10 +63,11 @@ export class TextSizePage implements OnboardingPage {
const selection = getUiFontSelection();
if (selection.kind === "ttf") {
const path = installedFontPath(selection.file);
const sizes = FONT_SIZE_CHOICES.filter((size) => uiFontSizeAllowed(path, size));
const sizes = SIZE_CHOICES.filter((size) => uiFontSizeAllowed(path, size));
if (sizes.length) {
this.face = { kind: "sized", file: selection.file, path, sizes };
this.sizeMenu.setItems(sizes, nearestIndex(sizes, selection.size));
// The recommended size the first time; on a return, what was left selected.
this.sizeMenu.setItems(sizes, nearestIndex(sizes, this.sizeMenu.selectedItem ?? RECOMMENDED_SIZE));
return;
}
}
@@ -86,7 +98,10 @@ export class TextSizePage implements OnboardingPage {
"Swipe to choose a size, then tap to continue. The typeface and weight can be changed in Settings.",
) + CONTENT_GAP;
const height = image.height - top - BOTTOM_MARGIN;
const menuBox = { x: PAGE_X - 10, y: top, width: SIZE_COLUMN_WIDTH, height };
const body = onboardingFont("body");
const columnWidth = 20 + Math.max(...this.face.sizes.map((size) => body.measureText(sizeLabel(size)))) +
NOTE_GAP + onboardingFont("detail").measureText(RECOMMENDED_NOTE);
const menuBox = { x: PAGE_X - 10, y: top, width: columnWidth, height };
this.sizeMenu.paint(image, menuBox, focused);
const previewX = menuBox.x + menuBox.width + COLUMN_GAP;
const size = this.sizeMenu.selectedItem;
@@ -117,36 +132,35 @@ export class TextSizePage implements OnboardingPage {
setUiFontSelection({ kind: "ttf", file: this.face.file, size });
}
private drawSizeRow({ image, item: size, x, y, selected }: MenuDrawArgs<number>): void {
image.drawText(onboardingFont("body"), x + 10, y + LIST_ROW_TEXT_INSET, `${size} px`, selected ? 255 : 190);
private drawSizeRow({ image, item: size, x, y, height, selected }: MenuDrawArgs<number>): void {
const body = onboardingFont("body");
const label = sizeLabel(size);
image.drawText(body, x + 10, y + LIST_ROW_TEXT_INSET, label, selected ? 255 : 190);
if (size !== RECOMMENDED_SIZE) return;
const detail = onboardingFont("detail");
const noteY = y + Math.round((height - detail.lineHeight) / 2);
image.drawText(detail, x + 10 + body.measureText(label) + NOTE_GAP, noteY, RECOMMENDED_NOTE, selected ? 210 : 150);
}
}
/** A framed sample in `font`: a sentence, then menu rows with the first one selected, as many as fit. */
function sizeLabel(size: number): string {
return `${size} px`;
}
/** A framed sample in `font`: paragraphs of text, as many whole lines as fit. */
function drawPreview(image: GrayImage, font: UiFont, box: MenuBox): void {
image.drawRoundedRect(box.x, box.y, box.width, box.height, 60, 8);
const left = box.x + PREVIEW_PADDING;
const width = box.width - 2 * PREVIEW_PADDING;
const bottom = box.y + box.height - PREVIEW_PADDING;
let y = box.y + PREVIEW_PADDING;
for (const line of wrapText(font, PREVIEW_TEXT, width)) {
if (y + font.lineHeight > bottom) return;
image.drawText(font, left, y, line, 220);
y += font.lineHeight;
}
y += PREVIEW_PADDING;
const rowHeight = listRowHeight(font);
for (let index = 0; index < PREVIEW_ROWS.length; index++) {
if (y + rowHeight - ROW_GAP > bottom) return;
const label = PREVIEW_ROWS[index]!;
if (index === 0) {
const row = new GrayImage(width, rowHeight - ROW_GAP, 0);
row.drawText(font, 10, LIST_ROW_TEXT_INSET, label, 255);
image.drawMenuSelection(row, left, y, MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE, 8, 0);
} else {
image.drawText(font, left + 10, y + LIST_ROW_TEXT_INSET, label, 200);
for (const [index, paragraph] of PREVIEW_PARAGRAPHS.entries()) {
if (index > 0) y += font.lineHeight >> 1;
for (const line of wrapText(font, paragraph, width)) {
if (y + font.lineHeight > bottom) return;
image.drawText(font, left, y, line, 220);
y += font.lineHeight;
}
y += rowHeight;
}
}
+2
View File
@@ -16,6 +16,8 @@ type TextLine = { font: UiFont; text: string; value: number; spaceBefore: number
/** The splash: logo beside the name, version and how to go on, centred as one group. */
export class WelcomePage implements OnboardingPage {
readonly fullscreen = true;
paint(image: GrayImage): void {
const { width, height } = image;
const logo = getFullLogo(Math.min(LOGO_MAX_HEIGHT, height - 2 * LOGO_MARGIN));
+3 -3
View File
@@ -698,9 +698,9 @@ const DATA_COLLECTION_LABELS: Record<DataCollectionLevel, string> = {
// What each level collects is set out in app/analytics/analytics-store.ts and
// the privacy policy (PRIVACY); keep these in step with both.
const DATA_COLLECTION_SUMMARIES: Record<DataCollectionLevel, string> = {
none: "No Faceclaw statistics",
minimal: "Version, devices, connection reliability",
full: "Also settings and API-key presence",
none: "Disable all data sharing",
minimal: "Version, devices, and connection reliability statistics",
full: "More detailed usage data",
};
/** One-line summary of what a data-collection level sends (onboarding, settings). */
+7 -5
View File
@@ -27,6 +27,7 @@ import { scrollToKeepSelectionVisible } from "../menu";
import { lineStep } from "../metrics";
import {
appViewportRect,
isFullscreen,
MIN_WINDOW_HEIGHT,
minWindowTop,
SHELL_OPAQUE_BLACK,
@@ -275,14 +276,15 @@ type StatusBarPlacement = { left: number; right: number; top: number; contentTop
/**
* The status bar's placement for the foreground window, or null when it
* isn't drawn as a bar: when it shares a bottom switcher row, or when it
* overlays the window (geometry.ts statusBarOverlays) and the popup
* switcher isn't up. An overlaying bar sits inside a window frame, whose
* side runs along its outer row, so it keeps its divider.
* isn't drawn as a bar: when the window is fullscreen, when it shares a
* bottom switcher row, or when it overlays the window (geometry.ts
* statusBarOverlays) and the popup switcher isn't up. An overlaying bar
* sits inside a window frame, whose side runs along its outer row, so it
* keeps its divider.
*/
function statusBarPlacement(state: ShellChromeState): StatusBarPlacement | null {
const appId = state.foregroundAppId;
if (statusInSwitcherRow(appId)) return null;
if (isFullscreen(appId) || statusInSwitcherRow(appId)) return null;
const overlays = statusBarOverlays();
if (overlays && !sidebarStripVisible(state.focus, appId)) return null;
const { left, right } = topBarSpan(state);
+34 -6
View File
@@ -60,9 +60,33 @@ export function displayMode(appId?: string): DisplayModeSetting {
return mode === "global" || mode === "default" ? displayModeSetting.get() : mode;
}
/** The full-panel mode: windows fill the panel; the switcher overlays them only while it has focus. */
/**
* Apps whose windows are fullscreen right now: the whole panel, with no
* status bar, window frame or room kept for the switcher (which overlays
* them only while it has focus, as in the full-panel mode), at depth 0. An
* app switches it at runtime (InProcessWindow.setFullscreen; the onboarding's
* first pages), so it is per app, like the per-app display modes.
*/
const fullscreenApps = new Set<string>();
/** Mark an app's windows fullscreen or not; true if that changed anything. */
export function setAppFullscreen(appId: string, fullscreen: boolean): boolean {
if (fullscreenApps.has(appId) === fullscreen) return false;
if (fullscreen) fullscreenApps.add(appId);
else fullscreenApps.delete(appId);
return true;
}
export function isFullscreen(appId?: string): boolean {
return appId !== undefined && fullscreenApps.has(appId);
}
/**
* The full-panel mode (or a fullscreen app): windows fill the panel; the
* switcher overlays them only while it has focus.
*/
function fullPanel(appId?: string): boolean {
return displayMode(appId) === "640x480";
return isFullscreen(appId) || displayMode(appId) === "640x480";
}
/**
@@ -176,9 +200,10 @@ export function statusBarOverlays(): boolean {
* Rows the shell draws along one edge of each window's content: the status
* bar's (the top bar, as a header), the frame's side, or none. A bottom
* switcher row's band has no footer: the frame's bottom side is the row's
* top edge.
* top edge. A fullscreen window has neither.
*/
function windowEdgeHeight(edge: "top" | "bottom", appId?: string): number {
if (isFullscreen(appId)) return 0;
if (switcherPosition() !== "popup") {
return edge === "bottom" ? 0 : statusInSwitcherRow(appId) ? 1 : TOP_BAR_HEIGHT;
}
@@ -261,17 +286,20 @@ export function appViewportLeft(appId?: string): number {
* the firmware's depth units; the shell scene carries it to the compositor,
* which shifts the screen and everything drawn over it per lens. Only with
* the switcher at the bottom or a popup, where the windows' side margins,
* less the window frame's pixel, leave room for the shift.
* less the window frame's pixel, leave room for the shift; not while the
* given (foreground) app is fullscreen, which has no margins.
*/
export function uiDepth(): number {
return sideStrip() ? 0 : Number(uiDepthSetting.get());
export function uiDepth(appId?: string): number {
return sideStrip() || isFullscreen(appId) ? 0 : Number(uiDepthSetting.get());
}
/**
* Explicit app sizes (including Use global) replace the requested height.
* The default keeps legacy per-window heights, such as tall terminal sessions.
* A fullscreen app is always the whole height.
*/
export function effectiveHeightMode(mode: WindowHeightMode, appId?: string): WindowHeightMode {
if (isFullscreen(appId)) return "max";
return displayMode(appId) === "576x288" ? (appDisplayMode(appId) === "default" ? mode : "min") : "max";
}
+24 -7
View File
@@ -8,7 +8,7 @@ import { type MenuItem } from "../menu";
import { WindowMenuLayer } from "../window-menu";
import { windowIcon } from "./chrome-layer";
import { type IconName } from "../../graphics/icons";
import { appViewportSize, type WindowHeightMode } from "./geometry";
import { appViewportSize, setAppFullscreen, type WindowHeightMode } from "./geometry";
import { shell, type ShellWindow } from "./shell";
/**
@@ -30,6 +30,8 @@ export type InProcessWindowOptions = {
closeable: boolean;
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode;
/** Open fullscreen: the whole panel, without the status bar (see geometry.ts isFullscreen). */
fullscreen?: boolean;
/**
* The window's tap-then-hold context menu: app-specific entries only (the
* shared Focus app switcher / Voice input / Close window entries live in
@@ -73,6 +75,12 @@ export type InProcessWindow = {
requestRender: () => void;
/** Change the window's height band at runtime (resizes the viewport + surface). */
setHeightMode: (mode: WindowHeightMode) => void;
/**
* Enter or leave fullscreen at runtime (resizes the viewport + surface).
* It is per app (geometry.ts isFullscreen), so an app with several
* windows switches them all.
*/
setFullscreen: (fullscreen: boolean) => void;
};
/** The controller-provided plumbing common to every in-process app window. */
@@ -102,10 +110,12 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
// Handed to app code as a bare callback, so it takes no arguments.
const requestRender = () => renderInNewFrame(0);
let heightMode = options.heightMode ?? "min";
setAppFullscreen(options.appId, options.fullscreen ?? false);
const viewportSize = () => appViewportSize(heightMode, options.appId);
const stack = new LayerStack(
options.baseLayer,
{ ...options.actions, requestRender },
appViewportSize(heightMode),
viewportSize(),
() => shell.isWindowFocused(options.windowId),
);
@@ -172,6 +182,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
hasAppMenu: () => appMenuItems().length > 0,
close: () => {
closed = true;
setAppFullscreen(options.appId, false);
// Fire onRemoved for any pushed layers so they release resources (e.g. a
// demo that enabled a hardware stream) even when closed from within.
stack.clearToBase();
@@ -210,7 +221,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
},
requestRender,
relayout: () => {
stack.setBaseSize(appViewportSize(heightMode));
stack.setBaseSize(viewportSize());
options.reconfigureSurface?.(heightMode);
requestRender();
},
@@ -226,15 +237,21 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
options.onForegroundChanged?.(foreground);
},
};
const resize = () => {
stack.setBaseSize(viewportSize());
options.reconfigureSurface?.(heightMode);
requestRender();
};
const setHeightMode = (mode: WindowHeightMode) => {
if (heightMode === mode) return;
heightMode = mode;
window.heightMode = mode;
stack.setBaseSize(appViewportSize(mode));
options.reconfigureSurface?.(mode);
requestRender();
resize();
};
return { window, stack, requestRender, setHeightMode };
const setFullscreen = (fullscreen: boolean) => {
if (!closed && setAppFullscreen(options.appId, fullscreen)) resize();
};
return { window, stack, requestRender, setHeightMode, setFullscreen };
}
/**
+5 -2
View File
@@ -831,10 +831,13 @@ class Shell {
/**
* Paint the shell surface: transparent chrome, or all-transparent when
* asleep. The scene also carries the whole display's stereo depth.
* asleep. The scene also carries the whole display's stereo depth (none
* under a fullscreen window).
*/
paintScene(): Uint8Array {
return this.screenOn ? encodeShellScene(this.stack.paintUndimmed(), uiDepth()) : encodeShellScene([]);
return this.screenOn
? encodeShellScene(this.stack.paintUndimmed(), uiDepth(this.foregroundWindow()?.appId))
: encodeShellScene([]);
}
paintSurface(): Plane[] {