forked from Blendman974/faceclaw
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
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user