forked from Blendman974/faceclaw
Borderless modes have different padding inside the builtin apps
Most of the builtin apps had some padding between the window edge and their content, because they expect to be displayed with a line border on their edge. We added a customization option to remove the border, so, that padding is not always necessary. Make the layouts dynamically adjust, to omit the padding when it isn't needed.
This commit is contained in:
1 parent
e158452ba4
commit
a02b849200
115 files changed
+3600
-1583
No files matched your search
@@ -4,11 +4,11 @@ import { dataCollectionSetting, dataCollectionSummary, type DataCollectionLevel
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
|
||||
const CONTENT_GAP = 10;
|
||||
const BOTTOM_MARGIN = 8;
|
||||
const LABEL_GAP = 24;
|
||||
|
||||
/** None / Minimal / Full, each with a one-line summary; a tap saves the selected level. */
|
||||
@@ -29,9 +29,10 @@ export class DataCollectionPage implements OnboardingPage {
|
||||
this.menu.select(dataCollectionSetting.values.indexOf(dataCollectionSetting.get()));
|
||||
}
|
||||
|
||||
paint(image: GrayImage, focused: boolean): void {
|
||||
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
|
||||
const top = drawPageHeading(
|
||||
image,
|
||||
padding,
|
||||
"Faceclaw Statistics",
|
||||
(global.isIOS ? "TestFlight reports are separate. " : "Google ML Kit diagnostics are separate. ") +
|
||||
"Choose Faceclaw statistics below. Details and controls: Settings > Privacy.",
|
||||
@@ -41,9 +42,14 @@ export class DataCollectionPage implements OnboardingPage {
|
||||
this.labelColumnWidth =
|
||||
Math.max(...dataCollectionSetting.values.map((level) => body.measureText(dataCollectionSetting.displayValue(level)))) +
|
||||
LABEL_GAP;
|
||||
// The list scrolls, so it runs to the window's bottom edge, with that
|
||||
// edge's padding after its last row.
|
||||
this.menu.paint(
|
||||
image,
|
||||
{ x: PAGE_X - 10, y: top, width: image.width - 2 * (PAGE_X - 10), height: image.height - top - BOTTOM_MARGIN },
|
||||
{
|
||||
x: padding.left, y: top, width: Math.max(0, image.width - padding.left - padding.right), height: Math.max(0, image.height - top),
|
||||
padBottom: padding.bottom,
|
||||
},
|
||||
focused,
|
||||
);
|
||||
}
|
||||
@@ -68,9 +74,9 @@ export class DataCollectionPage implements OnboardingPage {
|
||||
private drawRow({ image, item: level, x, y, width, height, selected }: MenuDrawArgs<DataCollectionLevel>): void {
|
||||
const body = onboardingFont("body");
|
||||
const detail = onboardingFont("detail");
|
||||
image.drawText(body, x + 10, y + LIST_ROW_TEXT_INSET, dataCollectionSetting.displayValue(level), selected ? 255 : 200);
|
||||
const summaryX = x + 10 + this.labelColumnWidth;
|
||||
const summary = truncateText(detail, dataCollectionSummary(level), x + width - 10 - summaryX);
|
||||
image.drawText(body, x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, dataCollectionSetting.displayValue(level), selected ? 255 : 200);
|
||||
const summaryX = x + PAGE_TEXT_INSET + this.labelColumnWidth;
|
||||
const summary = truncateText(detail, dataCollectionSummary(level), x + width - PAGE_TEXT_INSET - summaryX);
|
||||
image.drawText(detail, summaryX, y + Math.round((height - detail.lineHeight) / 2), summary, selected ? 210 : 150);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@ import { appSwitcherPositionSetting, uiDepthSetting, type UiDepth } from "../../
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { layoutHasDepth } from "./layout-page";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
|
||||
const CONTENT_GAP = 10;
|
||||
const BOTTOM_MARGIN = 8;
|
||||
const COLUMN_WIDTH = 220;
|
||||
|
||||
/**
|
||||
@@ -35,15 +35,21 @@ export class DepthPage implements OnboardingPage {
|
||||
this.menu.select(uiDepthSetting.values.indexOf(uiDepthSetting.get()));
|
||||
}
|
||||
|
||||
paint(image: GrayImage, focused: boolean): void {
|
||||
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
|
||||
const top = drawPageHeading(
|
||||
image,
|
||||
padding,
|
||||
"Depth",
|
||||
"Swipe to move the display nearer or farther away, then tap to continue. Change later in Settings > Customization.",
|
||||
) + CONTENT_GAP;
|
||||
// The list scrolls, so it runs to the window's bottom edge, with that
|
||||
// edge's padding after its last row.
|
||||
this.menu.paint(
|
||||
image,
|
||||
{ x: PAGE_X - 10, y: top, width: COLUMN_WIDTH, height: image.height - top - BOTTOM_MARGIN },
|
||||
{
|
||||
x: padding.left, y: top, width: Math.min(COLUMN_WIDTH, Math.max(0, image.width - padding.left - padding.right)),
|
||||
height: Math.max(0, image.height - top), padBottom: padding.bottom,
|
||||
},
|
||||
focused,
|
||||
);
|
||||
}
|
||||
@@ -66,6 +72,6 @@ export class DepthPage implements OnboardingPage {
|
||||
}
|
||||
|
||||
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);
|
||||
image.drawText(onboardingFont("body"), x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, uiDepthSetting.displayValue(depth), selected ? 255 : 190);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import { displayLayoutSetting, type DisplayLayout } from "../../ui/dashboard-set
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
|
||||
const CONTENT_GAP = 10;
|
||||
const BOTTOM_MARGIN = 8;
|
||||
const COLUMN_GAP = 16;
|
||||
|
||||
const DESCRIPTIONS = {
|
||||
@@ -41,24 +41,29 @@ export class DisplayModePage implements OnboardingPage {
|
||||
this.menu.setItems(values, index >= 0 ? index : values.indexOf("tall"));
|
||||
}
|
||||
|
||||
paint(image: GrayImage, focused: boolean): void {
|
||||
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
|
||||
const top = drawPageHeading(
|
||||
image,
|
||||
padding,
|
||||
"Display mode",
|
||||
"Swipe to choose how much of the display windows use; it changes as you go. Tap to continue.",
|
||||
) + CONTENT_GAP;
|
||||
const body = onboardingFont("body");
|
||||
// TTF widths are fractional; the menu's row images need whole pixels.
|
||||
const columnWidth = Math.ceil(20 + Math.max(...this.menu.items.map((value) => body.measureText(displayLayoutSetting.displayValue(value)))));
|
||||
const menuBox = { x: PAGE_X - 10, y: top, width: columnWidth, height: image.height - top - BOTTOM_MARGIN };
|
||||
const columnWidth = Math.ceil(2 * PAGE_TEXT_INSET +
|
||||
Math.max(...this.menu.items.map((value) => body.measureText(displayLayoutSetting.displayValue(value)))));
|
||||
// The list scrolls, so it runs to the window's bottom edge, with that
|
||||
// edge's padding after its last row.
|
||||
const menuBox = { x: padding.left, y: top, width: columnWidth, height: Math.max(0, image.height - top), padBottom: padding.bottom };
|
||||
this.menu.paint(image, menuBox, focused);
|
||||
const layout = this.menu.selectedItem;
|
||||
if (layout === null) return;
|
||||
// The description stays put beside the list, inside the right and bottom padding.
|
||||
const detail = onboardingFont("detail");
|
||||
const left = menuBox.x + columnWidth + COLUMN_GAP;
|
||||
let y = top + LIST_ROW_TEXT_INSET;
|
||||
for (const line of wrapText(detail, description(layout), image.width - PAGE_X - left)) {
|
||||
if (y + detail.lineHeight > image.height - BOTTOM_MARGIN) break;
|
||||
for (const line of wrapText(detail, description(layout), image.width - padding.right - PAGE_TEXT_INSET - left)) {
|
||||
if (y + detail.lineHeight > image.height - padding.bottom) break;
|
||||
image.drawText(detail, left, y, line, 170);
|
||||
y += detail.lineHeight;
|
||||
}
|
||||
@@ -86,7 +91,7 @@ export class DisplayModePage implements OnboardingPage {
|
||||
}
|
||||
|
||||
private drawRow({ image, item: layout, x, y, selected }: MenuDrawArgs<DisplayLayout>): void {
|
||||
image.drawText(onboardingFont("body"), x + 10, y + LIST_ROW_TEXT_INSET, displayLayoutSetting.displayValue(layout), selected ? 255 : 190);
|
||||
image.drawText(onboardingFont("body"), x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, displayLayoutSetting.displayValue(layout), selected ? 255 : 190);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ import { appSwitcherPositionSetting, glassesTypeSetting, type AppSwitcherPositio
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import { MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "../../ui/menu-core";
|
||||
import { screenWidth } from "../../ui/shell/geometry";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { AREA_OUTLINE, Diagram, diagramBandHeight, drawLayout, layoutAreaHeight } from "./layout-diagram";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
import { centredX, 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;
|
||||
/** Padding inside a cell's selection box, round the diagram and its caption. */
|
||||
@@ -37,35 +37,39 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
|
||||
* layout, Bottom and Popup on top, the recommended one selected at first;
|
||||
* swipes move through them in reading order, a tap saves the selected one.
|
||||
* The page is immersive, so the diagrams get 40% of the display's width
|
||||
* each. Choosing a layout reflows open windows (the dashboard controller
|
||||
* watches the setting).
|
||||
* each. The grid is centred in the window, its cells' selection boxes
|
||||
* keeping inside the padding of the window's edges. Choosing a layout
|
||||
* reflows open windows (the dashboard controller watches the setting).
|
||||
*/
|
||||
export class LayoutPage implements OnboardingPage {
|
||||
readonly immersive = true;
|
||||
/** Kept across visits, so going back returns to the last choice. */
|
||||
private selected = LAYOUT_ORDER.indexOf(recommendedLayout());
|
||||
|
||||
paint(image: GrayImage, focused: boolean): void {
|
||||
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
|
||||
const top = drawPageHeading(
|
||||
image,
|
||||
padding,
|
||||
"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;
|
||||
const available = image.height - top - padding.bottom;
|
||||
const availableWidth = image.width - padding.left - padding.right;
|
||||
// The most a diagram can take for two rows and two columns of cells to
|
||||
// fit, in whole pixels, so rounding its size can't push the grid past
|
||||
// the window's padding.
|
||||
const maxDiagramHeight = Math.floor((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight);
|
||||
const maxDiagramWidth = Math.floor((availableWidth - COLUMN_GAP) / 2 - 2 * CELL_PADDING);
|
||||
// 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) / layoutAreaHeight(),
|
||||
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / screenWidth(),
|
||||
);
|
||||
const scale = Math.max(0, Math.min(DIAGRAM_SCALE, maxDiagramHeight / layoutAreaHeight(), maxDiagramWidth / screenWidth()));
|
||||
const diagramWidth = Math.round(screenWidth() * scale);
|
||||
const diagramHeight = Math.round(layoutAreaHeight() * 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 left = centredX(image, padding, 2 * cellWidth + COLUMN_GAP);
|
||||
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);
|
||||
|
||||
@@ -84,9 +84,9 @@ export class OnboardingLayer implements Layer {
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
this.pages[this.index]!.paint(image, ctx.stack.isFocused());
|
||||
this.pages[this.index]!.paint(image, ctx.stack.isFocused(), padding);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { GrayImage } from "../../graphics/image";
|
||||
import { wrapText } from "../../graphics/textwrap";
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
|
||||
/** Page-to-flow navigation, handed to a page's input handler. */
|
||||
@@ -25,13 +26,31 @@ export interface OnboardingPage {
|
||||
applies?(): boolean;
|
||||
/** The page became current, going forward or back. */
|
||||
enter?(): void;
|
||||
paint(image: GrayImage, focused: boolean): void;
|
||||
/**
|
||||
* Paint the page over the whole image, the window's viewport. `padding`
|
||||
* is the padding suggested for each of its edges (viewport.ts): none on an
|
||||
* immersive page, whose edges are the screen's.
|
||||
*/
|
||||
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void;
|
||||
handleInput(event: InputEvent, nav: OnboardingNav): void | Promise<void>;
|
||||
}
|
||||
|
||||
/** Left margin and title position shared by the pages (the UI-wide (18, 10) title spot). */
|
||||
export const PAGE_X = 18;
|
||||
export const TITLE_Y = 10;
|
||||
/**
|
||||
* How far a page's text (its title and explanation, a list row's label)
|
||||
* sits inside the side padding. A list's selection boxes start at the
|
||||
* padding itself, so the title lines up with the rows' text.
|
||||
*/
|
||||
export const PAGE_TEXT_INSET = 10;
|
||||
/** The title's drop below the top padding. */
|
||||
const TITLE_OFFSET_Y = 2;
|
||||
|
||||
/**
|
||||
* The x that centres something `width` wide in the window, short of
|
||||
* entering either side's padding.
|
||||
*/
|
||||
export function centredX(image: GrayImage, padding: Edges<number>, width: number): number {
|
||||
return Math.max(padding.left, Math.min(image.width - padding.right - width, Math.round((image.width - width) / 2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a page's title and its wrapped explanation (at most `maxLines`
|
||||
@@ -39,17 +58,21 @@ export const TITLE_Y = 10;
|
||||
*/
|
||||
export function drawPageHeading(
|
||||
image: GrayImage,
|
||||
padding: Edges<number>,
|
||||
title: string,
|
||||
explanation: string,
|
||||
maxLines = 2,
|
||||
): number {
|
||||
const titleFont = onboardingFont("title");
|
||||
const detailFont = onboardingFont("detail");
|
||||
image.drawText(titleFont, PAGE_X, TITLE_Y, title, 230);
|
||||
let y = TITLE_Y + titleFont.lineHeight + 2;
|
||||
const lines = wrapText(detailFont, explanation, image.width - 2 * PAGE_X).slice(0, maxLines);
|
||||
const x = padding.left + PAGE_TEXT_INSET;
|
||||
const textWidth = Math.max(0, image.width - padding.left - padding.right - 2 * PAGE_TEXT_INSET);
|
||||
const titleY = padding.top + TITLE_OFFSET_Y;
|
||||
image.drawText(titleFont, x, titleY, title, 230);
|
||||
let y = titleY + titleFont.lineHeight + 2;
|
||||
const lines = wrapText(detailFont, explanation, textWidth).slice(0, maxLines);
|
||||
for (const line of lines) {
|
||||
image.drawText(detailFont, PAGE_X, y, line, 160);
|
||||
image.drawText(detailFont, x, y, line, 160);
|
||||
y += detailFont.lineHeight;
|
||||
}
|
||||
return y;
|
||||
|
||||
@@ -14,11 +14,11 @@ import { FONT_SIZE_CHOICES } from "../../ui/font-picker";
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import { Menu, type MenuBox, type MenuDrawArgs } from "../../ui/menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { drawPageHeading, PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
import { drawPageHeading, PAGE_TEXT_INSET, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
|
||||
const CONTENT_GAP = 10;
|
||||
const BOTTOM_MARGIN = 8;
|
||||
const COLUMN_GAP = 12;
|
||||
const PREVIEW_PADDING = 10;
|
||||
const ROW_GAP = 2;
|
||||
@@ -75,39 +75,40 @@ export class TextSizePage implements OnboardingPage {
|
||||
this.face = { kind: "fixed", label: selection.kind === "bitmap" ? fontSelectionLabel(selection) : "Terminus" };
|
||||
}
|
||||
|
||||
paint(image: GrayImage, focused: boolean): void {
|
||||
paint(image: GrayImage, focused: boolean, padding: Edges<number>): void {
|
||||
// The preview's frame keeps inside the padding of the window's edges.
|
||||
const right = image.width - padding.right;
|
||||
const bottom = image.height - padding.bottom;
|
||||
if (this.face.kind === "fixed") {
|
||||
const top = drawPageHeading(
|
||||
image,
|
||||
padding,
|
||||
"Text size",
|
||||
`Your UI font, ${this.face.label}, comes in one size. To choose a size, pick a different font in ` +
|
||||
"Settings > Customization. Tap to continue.",
|
||||
3,
|
||||
) + CONTENT_GAP;
|
||||
drawPreview(image, getDefaultSmallFont(), {
|
||||
x: PAGE_X - 10,
|
||||
y: top,
|
||||
width: image.width - 2 * (PAGE_X - 10),
|
||||
height: image.height - top - BOTTOM_MARGIN,
|
||||
});
|
||||
drawPreview(image, getDefaultSmallFont(), { x: padding.left, y: top, width: right - padding.left, height: bottom - top });
|
||||
return;
|
||||
}
|
||||
const top = drawPageHeading(
|
||||
image,
|
||||
padding,
|
||||
"Text size",
|
||||
"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 body = onboardingFont("body");
|
||||
// TTF widths are fractional; the menu's row images need whole pixels.
|
||||
const columnWidth = Math.ceil(20 + Math.max(...this.face.sizes.map((size) => body.measureText(sizeLabel(size)))) +
|
||||
const columnWidth = Math.ceil(2 * PAGE_TEXT_INSET + 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 };
|
||||
// The list scrolls, so it runs to the window's bottom edge, with that
|
||||
// edge's padding after its last row.
|
||||
const menuBox = { x: padding.left, y: top, width: columnWidth, height: Math.max(0, image.height - top), padBottom: padding.bottom };
|
||||
this.sizeMenu.paint(image, menuBox, focused);
|
||||
const previewX = menuBox.x + menuBox.width + COLUMN_GAP;
|
||||
const size = this.sizeMenu.selectedItem;
|
||||
const font = (size !== null ? TtfFont.load(this.face.path, size) : null) ?? getDefaultSmallFont();
|
||||
drawPreview(image, font, { x: previewX, y: top, width: image.width - (PAGE_X - 10) - previewX, height });
|
||||
drawPreview(image, font, { x: previewX, y: top, width: right - previewX, height: bottom - top });
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent, nav: OnboardingNav): void {
|
||||
@@ -136,11 +137,11 @@ export class TextSizePage implements OnboardingPage {
|
||||
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);
|
||||
image.drawText(body, x + PAGE_TEXT_INSET, y + LIST_ROW_TEXT_INSET, label, selected ? 255 : 190);
|
||||
if (size !== defaultUiFontSize()) 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);
|
||||
image.drawText(detail, x + PAGE_TEXT_INSET + body.measureText(label) + NOTE_GAP, noteY, RECOMMENDED_NOTE, selected ? 210 : 150);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,31 +2,35 @@ import type { GrayImage, UiFont } from "../../graphics/image";
|
||||
import { getFullLogo } from "../../graphics/logo";
|
||||
import { wrapText } from "../../graphics/textwrap";
|
||||
import type { InputEvent } from "../../ui/gestures";
|
||||
import type { Edges } from "../../ui/viewport";
|
||||
import { FACECLAW_VERSION } from "../../version";
|
||||
import { onboardingFont } from "./onboarding-fonts";
|
||||
import { PAGE_X, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
import { centredX, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
||||
|
||||
const LOGO_MAX_HEIGHT = 180;
|
||||
const LOGO_MARGIN = 12;
|
||||
const LOGO_TEXT_GAP = 28;
|
||||
const PROMPT_GAP = 22;
|
||||
const PROMPT = "Tap the ring or touchpad to continue";
|
||||
|
||||
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. */
|
||||
/**
|
||||
* The splash: logo beside the name, version and how to go on, centred in
|
||||
* the window as one group, which keeps inside the padding of its edges.
|
||||
*/
|
||||
export class WelcomePage implements OnboardingPage {
|
||||
readonly immersive = true;
|
||||
|
||||
paint(image: GrayImage): void {
|
||||
paint(image: GrayImage, _focused: boolean, padding: Edges<number>): void {
|
||||
const { width, height } = image;
|
||||
const logo = getFullLogo(Math.min(LOGO_MAX_HEIGHT, height - 2 * LOGO_MARGIN));
|
||||
const availableWidth = Math.max(0, width - padding.left - padding.right);
|
||||
const logo = getFullLogo(Math.min(LOGO_MAX_HEIGHT, height - padding.top - padding.bottom));
|
||||
const logoWidth = logo ? logo.width + LOGO_TEXT_GAP : 0;
|
||||
const body = onboardingFont("body");
|
||||
const lines: TextLine[] = [
|
||||
{ font: onboardingFont("hero"), text: "Faceclaw", value: 240, spaceBefore: 0 },
|
||||
{ font: body, text: `Version ${FACECLAW_VERSION}`, value: 150, spaceBefore: 0 },
|
||||
...wrapText(body, PROMPT, width - 2 * PAGE_X - logoWidth).map((text, index) => ({
|
||||
...wrapText(body, PROMPT, availableWidth - logoWidth).map((text, index) => ({
|
||||
font: body,
|
||||
text,
|
||||
value: 215,
|
||||
@@ -35,7 +39,7 @@ export class WelcomePage implements OnboardingPage {
|
||||
];
|
||||
const textWidth = Math.max(...lines.map((line) => line.font.measureText(line.text)));
|
||||
const textHeight = lines.reduce((total, line) => total + line.spaceBefore + line.font.lineHeight, 0);
|
||||
const left = Math.max(PAGE_X, Math.round((width - logoWidth - textWidth) / 2));
|
||||
const left = centredX(image, padding, logoWidth + textWidth);
|
||||
if (logo) {
|
||||
image.bitBlt(logo, left, Math.round((height - logo.height) / 2), { transparentZero: true });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user