mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Onboarding: Add layout and depth pages
This commit is contained in:
1 parent
1d257e8bb6
commit
6b1e64c5ac
17 files changed
+766
-74
No files matched your search
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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). */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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[] {
|
||||
|
||||
@@ -271,7 +271,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
||||
'../../graphics/image': images, '../../native/frame-timings': timings,
|
||||
'../../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false },
|
||||
'../layers': layers, '../window-menu': { WindowMenuLayer: Menu },
|
||||
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }) },
|
||||
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }), setAppFullscreen: () => false },
|
||||
'./shell': { shell },
|
||||
});
|
||||
const input = [], menus = [];
|
||||
|
||||
@@ -204,6 +204,33 @@ test('a bottom app switcher centres 576-wide windows and hangs one tall tab unde
|
||||
assert.equal(g.windowFramed(), false);
|
||||
});
|
||||
|
||||
test('a fullscreen app fills the panel without chrome rows, frame or depth, in any layout', () => {
|
||||
const panel = { x: 0, y: 0, width: 640, height: 480 };
|
||||
for (const position of ['left', 'right', 'bottom', 'popup']) {
|
||||
const g = geometry();
|
||||
g.settings.appSwitcherPositionSetting.value = position;
|
||||
g.settings.statusBarPositionSetting.value = 'bottom';
|
||||
g.settings.uiDepthSetting.value = '48';
|
||||
assert.equal(g.setAppFullscreen('onboarding', true), true);
|
||||
assert.equal(g.setAppFullscreen('onboarding', true), false);
|
||||
for (const mode of ['min', 'medium', 'max']) assert.deepEqual(g.rect(mode, 'onboarding'), panel, position);
|
||||
assert.equal(g.windowFramed('onboarding'), false);
|
||||
assert.equal(g.statusInSwitcherRow('onboarding'), false);
|
||||
// The switcher overlays it while focused, as in the full-panel mode.
|
||||
assert.equal(g.sidebarStripVisible('window', 'onboarding'), false);
|
||||
assert.equal(g.sidebarStripVisible('sidebar', 'onboarding'), true);
|
||||
assert.equal(g.uiDepth('onboarding'), 0);
|
||||
// Other apps keep the layout and its depth.
|
||||
const depth = position === 'bottom' || position === 'popup' ? 48 : 0;
|
||||
assert.equal(g.uiDepth('launcher'), depth);
|
||||
assert.equal(g.uiDepth(), depth);
|
||||
assert.notDeepEqual(g.rect('min', 'launcher'), panel);
|
||||
assert.equal(g.setAppFullscreen('onboarding', false), true);
|
||||
assert.deepEqual(g.rect('min', 'onboarding'), g.rect('min', 'launcher'));
|
||||
assert.equal(g.uiDepth('onboarding'), depth);
|
||||
}
|
||||
});
|
||||
|
||||
// The real chrome layer over the given geometry, with platform pieces stubbed:
|
||||
// a 4px-per-character font that paints each character as a 2x6 block, up to
|
||||
// `notifications` 24px notification icons (keyed n0, n1, ...), and a phone
|
||||
@@ -296,6 +323,25 @@ test('a bottom app switcher frames the foreground window\'s content in a rounded
|
||||
assert.equal(chrome.paintParts().flatMap((p) => frames(p.image)).length, 0);
|
||||
});
|
||||
|
||||
test('over a fullscreen window the chrome draws only the switcher, and only while it has focus', () => {
|
||||
for (const position of ['bottom', 'popup', 'left']) {
|
||||
const g = geometry();
|
||||
g.settings.appSwitcherPositionSetting.value = position;
|
||||
g.settings.statusBarPositionSetting.value = position === 'left' ? 'top' : 'bottom';
|
||||
g.setAppFullscreen('onboarding', true);
|
||||
const { chrome, state } = chromeLayer(g, { windows: 2, notifications: 1 });
|
||||
state.foregroundAppId = 'onboarding';
|
||||
assert.equal(chrome.paintParts().length, 0, position);
|
||||
assert.equal(chrome.paint().pixels.some((value) => value !== 0), false, position);
|
||||
state.focus = 'sidebar';
|
||||
const parts = chrome.paintParts();
|
||||
// No status bar (key 2), not even in a bottom row.
|
||||
assert.equal(parts.length, 1, position);
|
||||
assert.notEqual(parts[0].shellKey, 2, position);
|
||||
if (position === 'bottom') assert.deepEqual([parts[0].x, parts[0].y, parts[0].image.width], [0, 444, 640]);
|
||||
}
|
||||
});
|
||||
|
||||
test('the launcher\'s tab lines up with the window frame, whose corner squares to meet it', () => {
|
||||
const g = geometry();
|
||||
g.settings.appSwitcherPositionSetting.value = 'bottom';
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
// Roboto's line heights at the onboarding sizes, and a fixed advance.
|
||||
const FONTS = { title: 31, body: 24, detail: 19, hero: 52 };
|
||||
const font = (role) => ({ lineHeight: FONTS[role], measureText: (text) => text.length * 8, getGlyph: () => ({ dwidthX: 8 }) });
|
||||
|
||||
function setting(value, values) {
|
||||
return { value, values, get() { return this.value; }, set(next) { this.value = next; this.writes.push(next); },
|
||||
writes: [], displayValue: (v) => v[0].toUpperCase() + v.slice(1) };
|
||||
}
|
||||
|
||||
function harness() {
|
||||
const settings = {
|
||||
appSwitcherPositionSetting: setting('bottom', ['left', 'right', 'bottom', 'popup']),
|
||||
statusBarPositionSetting: setting('bottom', ['top', 'bottom']),
|
||||
uiDepthSetting: setting('48', ['-62', '-48', '-32', '-16', '0', '16', '32', '48', '62']),
|
||||
};
|
||||
const load = loader({}, {
|
||||
'./onboarding-fonts': { onboardingFont: font },
|
||||
'../../graphics/image': { G2_LENS_WIDTH: 640 },
|
||||
'../../ui/dashboard-settings': settings,
|
||||
'../../ui/shell/geometry': { MIN_WINDOW_HEIGHT: 288, SIDEBAR_WIDTH: 64, SWITCHER_ROW_HEIGHT: 36, TOP_BAR_HEIGHT: 28 },
|
||||
});
|
||||
return { settings, load };
|
||||
}
|
||||
|
||||
/** An image that records what is drawn, checking it all lands on the image. */
|
||||
function recorder(width, height) {
|
||||
const calls = [];
|
||||
const inside = (kind, x, y, w, h) => {
|
||||
assert.ok(x >= 0 && y >= 0 && x + w <= width && y + h <= height, `${kind} out of bounds: ${[x, y, w, h]}`);
|
||||
};
|
||||
return {
|
||||
width, height, calls,
|
||||
fillRect(x, y, w, h, value) { inside('fillRect', x, y, w, h); calls.push({ kind: 'fill', x, y, w, h, value }); },
|
||||
fillRoundedRect(x, y, w, h, value) { inside('fillRoundedRect', x, y, w, h); calls.push({ kind: 'fill', x, y, w, h, value }); },
|
||||
drawRoundedRect(x, y, w, h, value) { inside('drawRoundedRect', x, y, w, h); calls.push({ kind: 'outline', x, y, w, h, value }); },
|
||||
drawText(f, x, y, text, value) {
|
||||
inside(`text "${text}"`, x, y, f.measureText(text), f.lineHeight);
|
||||
calls.push({ kind: 'text', x, y, text, value });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('the layout page fits four 40%-wide diagrams with captions on the fullscreen panel', () => {
|
||||
const { load } = harness();
|
||||
const { LayoutPage } = load('app/apps/onboarding/layout-page.ts');
|
||||
const page = new LayoutPage();
|
||||
assert.equal(page.fullscreen, true);
|
||||
const image = recorder(640, 480);
|
||||
page.paint(image, true);
|
||||
// Each diagram's outline spans the display's width at 40%.
|
||||
const areas = image.calls.filter((call) => call.kind === 'outline' && call.w === 256);
|
||||
assert.equal(areas.length, 4);
|
||||
assert.deepEqual(areas.map((area) => area.h), [130, 130, 130, 130]);
|
||||
// A 2x2 grid, the layouts with depth on top, captioned under each diagram.
|
||||
const text = (label) => image.calls.filter((call) => call.kind === 'text' && call.text === label);
|
||||
const [bottom, popup, left, right] = ['Bottom (Recommended)', 'Popup', 'Left', 'Right'].map((label) => text(label)[0]);
|
||||
assert.equal(bottom.y, popup.y);
|
||||
assert.equal(left.y, right.y);
|
||||
assert.ok(left.y > bottom.y);
|
||||
assert.ok(popup.x > bottom.x && right.x > left.x);
|
||||
for (const [caption, area] of [[bottom, areas[0]], [popup, areas[1]], [left, areas[2]], [right, areas[3]]]) {
|
||||
assert.ok(caption.y >= area.y + area.h, `${caption.text} sits under its diagram`);
|
||||
assert.ok(caption.x > area.x && caption.x + caption.text.length * 8 < area.x + area.w, `${caption.text} sits under its diagram`);
|
||||
}
|
||||
// Customizable Depth under Bottom and Popup only.
|
||||
const depth = text('Customizable Depth');
|
||||
assert.equal(depth.length, 2);
|
||||
for (const [subtitle, title] of [[depth[0], bottom], [depth[1], popup]]) {
|
||||
assert.equal(subtitle.y, title.y + FONTS.body);
|
||||
assert.ok(Math.abs(subtitle.x + 'Customizable Depth'.length * 4 - (title.x + title.text.length * 4)) <= 1, 'centred together');
|
||||
}
|
||||
// Bottom, recommended, is the selected cell at first, filled while focused.
|
||||
const box = image.calls.find((call) => call.kind === 'fill' && call.value === 15);
|
||||
assert.ok(box.x <= areas[0].x && box.y <= areas[0].y && box.y + box.h >= bottom.y);
|
||||
});
|
||||
|
||||
test('the layout page starts on Bottom whatever is set, swipes in reading order, and a tap saves the choice', () => {
|
||||
const { load, settings } = harness();
|
||||
const { LayoutPage } = load('app/apps/onboarding/layout-page.ts');
|
||||
const page = new LayoutPage();
|
||||
settings.appSwitcherPositionSetting.value = 'right';
|
||||
page.enter?.();
|
||||
let next = 0;
|
||||
const nav = { next: () => next++ };
|
||||
page.handleInput({ type: 'click' }, nav);
|
||||
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['bottom']);
|
||||
page.handleInput({ type: 'scroll-up' }, nav);
|
||||
for (let i = 0; i < 2; i++) page.handleInput({ type: 'scroll-down' }, nav);
|
||||
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['bottom'], 'scrolling saves nothing');
|
||||
page.handleInput({ type: 'click' }, nav);
|
||||
for (let i = 0; i < 5; i++) page.handleInput({ type: 'scroll-down' }, nav);
|
||||
// Coming back keeps the last choice.
|
||||
page.enter?.();
|
||||
page.handleInput({ type: 'click' }, nav);
|
||||
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['bottom', 'left', 'right']);
|
||||
assert.equal(next, 3);
|
||||
});
|
||||
|
||||
test('the text size page offers 12 to 18px, starts on the recommended 16px, and previews plain text', () => {
|
||||
const menu = { selected: null, items: [], setItems(items, index) { this.items = items; this.selected = index; },
|
||||
get selectedItem() { return this.items[this.selected] ?? null; }, paint(image, box) { this.box = box; },
|
||||
async handleInput(event) { this.selected = Math.max(0, Math.min(this.items.length - 1, this.selected + (event.type === 'scroll-down' ? 1 : -1))); } };
|
||||
let menuOptions;
|
||||
let selection = { kind: 'ttf', file: 'Roboto-Light.ttf', size: 14 };
|
||||
const saved = [];
|
||||
const load = loader({}, {
|
||||
'./onboarding-fonts': { onboardingFont: font },
|
||||
'../../graphics/installed-fonts': { installedFontPath: (file) => `/fonts/${file}` },
|
||||
'../../graphics/ttf-font': { TtfFont: { load: (path, size) => font(size === 12 ? 'title' : 'detail') } },
|
||||
'../../graphics/ui-fonts': { fontSelectionLabel: () => 'Terminus', getDefaultSmallFont: () => font('detail'),
|
||||
getUiFontSelection: () => selection, setUiFontSelection: (value) => { selection = value; saved.push(value.size); },
|
||||
uiFontSizeAllowed: (path, size) => size !== 13 },
|
||||
'../../ui/font-picker': { FONT_SIZE_CHOICES: [8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 24] },
|
||||
'../../ui/menu-core': { Menu: class { constructor(options) { menuOptions = options; return menu; } } },
|
||||
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
|
||||
});
|
||||
const { TextSizePage } = load('app/apps/onboarding/text-size-page.ts');
|
||||
const page = new TextSizePage();
|
||||
page.enter();
|
||||
assert.deepEqual(Array.from(menu.items), [12, 14, 15, 16, 17, 18]);
|
||||
assert.equal(menu.selectedItem, 16, 'recommended, not the current 14');
|
||||
// Only 16 carries the note, beside its size.
|
||||
const rows = [];
|
||||
for (const size of menu.items) {
|
||||
const row = recorder(menu.box?.width ?? 200, 32);
|
||||
menuOptions.draw({ image: row, item: size, x: 0, y: 0, width: row.width, height: 32, selected: size === 16 });
|
||||
rows.push(row.calls.map((call) => call.text));
|
||||
}
|
||||
assert.deepEqual(rows[3], ['16 px', 'Recommended']);
|
||||
assert.deepEqual(rows.filter((texts) => texts.length > 1).length, 1);
|
||||
// The size column holds the note; the preview is paragraphs of text, no menu.
|
||||
const image = recorder(640, 480);
|
||||
page.paint(image, true);
|
||||
assert.ok(menu.box.width >= 10 + '16 px'.length * 8 + 8 + 'Recommended'.length * 8);
|
||||
const preview = image.calls.filter((call) => call.kind === 'text' && call.x > menu.box.x + menu.box.width);
|
||||
assert.equal(preview[0].text.startsWith('This is how text will look'), true);
|
||||
assert.ok(preview.length > 3);
|
||||
assert.equal(image.calls.some((call) => call.kind === 'text' && call.text === 'Timers'), false);
|
||||
// A tap saves; coming back keeps the size chosen.
|
||||
page.handleInput({ type: 'scroll-up' }, { next: () => {} });
|
||||
page.handleInput({ type: 'click' }, { next: () => {} });
|
||||
assert.deepEqual(saved, [15]);
|
||||
page.enter();
|
||||
assert.equal(menu.selectedItem, 15);
|
||||
});
|
||||
|
||||
test('the depth page follows layouts that have depth, sits in the layout, and applies depth as it scrolls', () => {
|
||||
const { load, settings } = harness();
|
||||
const menu = { selected: 0, items: [], select(index) { this.selected = index; },
|
||||
get selectedItem() { return this.items[this.selected] ?? null; }, paint() {},
|
||||
async handleInput(event) { this.selected = Math.max(0, Math.min(this.items.length - 1, this.selected + (event.type === 'scroll-down' ? 1 : -1))); } };
|
||||
const mocks = loader({}, {
|
||||
'./onboarding-fonts': { onboardingFont: font },
|
||||
'../../ui/dashboard-settings': settings,
|
||||
'../../ui/menu-core': { Menu: class { constructor(options) { menu.items = options.items; return menu; } } },
|
||||
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
|
||||
'./layout-page': { layoutHasDepth: (position) => position === 'bottom' || position === 'popup' },
|
||||
});
|
||||
const { DepthPage } = mocks('app/apps/onboarding/depth-page.ts');
|
||||
const page = new DepthPage();
|
||||
assert.equal(page.fullscreen, undefined);
|
||||
for (const [position, applies] of [['left', false], ['right', false], ['bottom', true], ['popup', true]]) {
|
||||
settings.appSwitcherPositionSetting.value = position;
|
||||
assert.equal(page.applies(), applies, position);
|
||||
}
|
||||
page.enter();
|
||||
assert.equal(menu.selectedItem, '48');
|
||||
let next = 0;
|
||||
page.handleInput({ type: 'scroll-down' }, { next: () => next++ });
|
||||
page.handleInput({ type: 'scroll-up' }, { next: () => next++ });
|
||||
page.handleInput({ type: 'scroll-up' }, { next: () => next++ });
|
||||
assert.deepEqual(settings.uiDepthSetting.writes, ['62', '48', '32']);
|
||||
page.handleInput({ type: 'click' }, { next: () => next++ });
|
||||
assert.equal(next, 1);
|
||||
});
|
||||
|
||||
test('the flow switches fullscreen per page and skips pages that do not apply, both ways', async () => {
|
||||
const shell = { yields: 0, yieldFocusToSidebar() { this.yields++; } };
|
||||
const load = loader({}, {
|
||||
'../../graphics/image': { GrayImage: class {} },
|
||||
'../../ui/shell/in-process-window': {}, '../../ui/shell/shell': { shell }, '../../ui/sound-effects': {},
|
||||
'./data-collection-page': {}, './depth-page': {}, './ios-privacy-page': {}, './layout-page': {},
|
||||
'./onboarding-progress': {}, './text-size-page': {}, './welcome-page': {},
|
||||
});
|
||||
const { OnboardingLayer } = load('app/apps/onboarding/onboarding-app.ts');
|
||||
let depthApplies = false;
|
||||
const entered = [];
|
||||
const page = (name, extra) => ({ ...extra, enter: () => entered.push(name),
|
||||
handleInput: (event, nav) => { if (event.type === 'click') nav.next(); } });
|
||||
const fullscreen = [];
|
||||
let finished = 0;
|
||||
const layer = new OnboardingLayer([
|
||||
page('welcome', { fullscreen: true }), page('layout', { fullscreen: true }),
|
||||
page('depth', { applies: () => depthApplies }), page('voice', {}),
|
||||
], (value) => fullscreen.push(value), () => finished++);
|
||||
const input = (type) => layer.handleInput({ type });
|
||||
await input('click');
|
||||
await input('click');
|
||||
assert.deepEqual(entered, ['welcome', 'layout', 'voice'], 'depth skipped going forward');
|
||||
assert.deepEqual(fullscreen, [true, false]);
|
||||
await input('double-click');
|
||||
assert.deepEqual(entered.at(-1), 'layout', 'and going back');
|
||||
depthApplies = true;
|
||||
await input('click');
|
||||
await input('click');
|
||||
assert.deepEqual(entered.slice(-2), ['depth', 'voice']);
|
||||
assert.deepEqual(fullscreen, [true, false, true, false, false]);
|
||||
await input('click');
|
||||
assert.equal(finished, 1);
|
||||
for (let i = 0; i < 4; i++) await input('double-click');
|
||||
assert.equal(entered.at(-1), 'welcome');
|
||||
assert.equal(shell.yields, 1, 'double-click on the first page leaves the app');
|
||||
});
|
||||
Reference in new issue
Block a user