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.
58 lines
2.4 KiB
TypeScript
58 lines
2.4 KiB
TypeScript
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 { centredX, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
|
|
|
|
const LOGO_MAX_HEIGHT = 180;
|
|
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 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, _focused: boolean, padding: Edges<number>): void {
|
|
const { width, height } = image;
|
|
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, availableWidth - logoWidth).map((text, index) => ({
|
|
font: body,
|
|
text,
|
|
value: 215,
|
|
spaceBefore: index === 0 ? PROMPT_GAP : 0,
|
|
})),
|
|
];
|
|
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 = centredX(image, padding, logoWidth + textWidth);
|
|
if (logo) {
|
|
image.bitBlt(logo, left, Math.round((height - logo.height) / 2), { transparentZero: true });
|
|
}
|
|
let y = Math.round((height - textHeight) / 2);
|
|
for (const line of lines) {
|
|
y += line.spaceBefore;
|
|
image.drawText(line.font, left + logoWidth, y, line.text, line.value);
|
|
y += line.font.lineHeight;
|
|
}
|
|
}
|
|
|
|
handleInput(event: InputEvent, nav: OnboardingNav): void {
|
|
if (event.type === "click") nav.next();
|
|
}
|
|
}
|