Adapt layouts for Rayneo screen resolution

This commit is contained in:
James Babcock committed 2026-11-01 19:02:05 -08:00
1 parent 4d101eefe1
commit dee60bbcd2
34 files changed
+721 -202

No files matched your search

+22 -11
View File
@@ -3,9 +3,9 @@
* page: to scale in real-display pixels, simplified, and drawn brighter
* than the real chrome, which they shrink to a few pixels.
*/
import { G2_LENS_WIDTH, type GrayImage } from "../../graphics/image";
import type { GrayImage } from "../../graphics/image";
import { statusBarPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
import { SIDEBAR_WIDTH, SWITCHER_ROW_HEIGHT, MIN_WINDOW_HEIGHT, TOP_BAR_HEIGHT } from "../../ui/shell/geometry";
import { MIN_WINDOW_HEIGHT, screenHeight, screenWidth, SIDEBAR_WIDTH, SWITCHER_ROW_HEIGHT, TOP_BAR_HEIGHT } from "../../ui/shell/geometry";
export const AREA_OUTLINE = 30;
const CHROME_LINE = 100;
@@ -80,14 +80,14 @@ export function drawLayout(d: Diagram, position: AppSwitcherPosition, band: Diag
switch (position) {
case "left":
case "right": {
const stripLeft = position === "left" ? 0 : G2_LENS_WIDTH - SIDEBAR_WIDTH;
const stripLeft = position === "left" ? 0 : screenWidth() - SIDEBAR_WIDTH;
const contentLeft = position === "left" ? SIDEBAR_WIDTH : 0;
const windowWidth = G2_LENS_WIDTH - SIDEBAR_WIDTH;
const windowWidth = screenWidth() - SIDEBAR_WIDTH;
drawStatusBar(d, contentLeft, top, windowWidth, TOP_BAR_HEIGHT - 1);
drawContent(d, contentLeft, top + TOP_BAR_HEIGHT, windowWidth, height - TOP_BAR_HEIGHT, 1);
// The strip keeps to the 288px band's height, even beside taller windows.
// The strip keeps to the min band's height (288px, or the whole short screen), even beside taller windows.
const separator = position === "left" ? SIDEBAR_WIDTH - 1 : stripLeft;
d.vline(separator, top + TOP_BAR_HEIGHT, MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT, CHROME_LINE);
d.vline(separator, top + TOP_BAR_HEIGHT, diagramBandHeight("left") - 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 + TOP_BAR_HEIGHT + 10 + slot * 40, slot === 0);
@@ -131,11 +131,11 @@ export function drawLayout(d: Diagram, position: AppSwitcherPosition, band: Diag
}
}
/** A bottom row or popup layout's window: centred at 576 wide and framed, or the panel's width without a frame. */
/** A bottom row or popup layout's window: centred, SIDEBAR_WIDTH narrower, framed; or the screen's width without a frame. */
function windowSpan(band: DiagramBand): { left: number; width: number; framed: boolean } {
return band.fullWidth
? { left: 0, width: G2_LENS_WIDTH, framed: false }
: { left: SIDEBAR_WIDTH / 2, width: G2_LENS_WIDTH - SIDEBAR_WIDTH, framed: true };
? { left: 0, width: screenWidth(), framed: false }
: { left: SIDEBAR_WIDTH / 2, width: screenWidth() - SIDEBAR_WIDTH, framed: true };
}
/**
@@ -173,5 +173,16 @@ function drawContent(d: Diagram, x: number, y: number, width: number, height: nu
}
}
/** Real-display rows the Layout page's diagrams cover: a 288px band and a bottom switcher row under it. */
export const LAYOUT_AREA_HEIGHT = MIN_WINDOW_HEIGHT + SWITCHER_ROW_HEIGHT;
/**
* Real-display rows the Layout page's diagrams cover: a 288px band and a
* bottom switcher row under it, or the whole screen where that is shorter
* (the RayNeo iO's 220 rows).
*/
export function layoutAreaHeight(): number {
return Math.min(MIN_WINDOW_HEIGHT + SWITCHER_ROW_HEIGHT, screenHeight());
}
/** A layout's min-height band within the diagram area: 288px, less a bottom row where the screen is short. */
export function diagramBandHeight(position: AppSwitcherPosition): number {
return Math.min(MIN_WINDOW_HEIGHT, layoutAreaHeight() - (position === "bottom" ? SWITCHER_ROW_HEIGHT : 0));
}
+26 -19
View File
@@ -1,9 +1,9 @@
import { G2_LENS_WIDTH, type GrayImage, type UiFont } from "../../graphics/image";
import { appSwitcherPositionSetting, type AppSwitcherPosition } from "../../ui/dashboard-settings";
import type { GrayImage, UiFont } from "../../graphics/image";
import { appSwitcherPositionSetting, glassesTypeSetting, 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 } from "../../ui/shell/geometry";
import { AREA_OUTLINE, Diagram, drawLayout, LAYOUT_AREA_HEIGHT } from "./layout-diagram";
import { screenWidth } from "../../ui/shell/geometry";
import { AREA_OUTLINE, Diagram, diagramBandHeight, drawLayout, layoutAreaHeight } from "./layout-diagram";
import { onboardingFont } from "./onboarding-fonts";
import { drawPageHeading, type OnboardingNav, type OnboardingPage } from "./onboarding-page";
@@ -19,8 +19,13 @@ 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";
/**
* Selected on the first visit, and marked: Bottom on the G2, whose 480 rows
* leave room for the row; a side strip on the RayNeo iO, whose 220 can't.
*/
export function recommendedLayout(): AppSwitcherPosition {
return glassesTypeSetting.get() === "rayneo-io" ? "left" : "bottom";
}
/** Whether a layout leaves the side margins the display's stereo depth shifts into (geometry.ts uiDepth). */
export function layoutHasDepth(position: AppSwitcherPosition): boolean {
@@ -29,7 +34,7 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
/**
* 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;
* 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
@@ -38,7 +43,7 @@ export function layoutHasDepth(position: AppSwitcherPosition): boolean {
export class LayoutPage implements OnboardingPage {
readonly immersive = true;
/** Kept across visits, so going back returns to the last choice. */
private selected = LAYOUT_ORDER.indexOf(RECOMMENDED_LAYOUT);
private selected = LAYOUT_ORDER.indexOf(recommendedLayout());
paint(image: GrayImage, focused: boolean): void {
const top = drawPageHeading(
@@ -53,11 +58,11 @@ export class LayoutPage implements OnboardingPage {
// 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) / LAYOUT_AREA_HEIGHT,
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / G2_LENS_WIDTH,
((available - ROW_GAP) / 2 - 2 * CELL_PADDING - captionHeight) / layoutAreaHeight(),
((image.width - COLUMN_GAP) / 2 - 2 * CELL_PADDING) / screenWidth(),
);
const diagramWidth = Math.round(G2_LENS_WIDTH * scale);
const diagramHeight = Math.round(LAYOUT_AREA_HEIGHT * scale);
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);
@@ -75,7 +80,7 @@ export class LayoutPage implements OnboardingPage {
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;
const caption = position === recommendedLayout() ? `${name} (Recommended)` : name;
centre(caption, title, captionTop, selected ? 255 : 190);
if (layoutHasDepth(position)) {
centre(DEPTH_SUBTITLE, subtitle, captionTop + title.lineHeight, selected ? 210 : 150);
@@ -103,12 +108,14 @@ export class LayoutPage implements OnboardingPage {
}
/**
* A layout's diagram: the 288px band, with the popup switcher open. 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.
* A layout's diagram: the min-height band, with the popup switcher open.
* 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 (none on a screen as short as the RayNeo iO's: the band fills it).
*/
function drawLayoutDiagram(d: Diagram, position: AppSwitcherPosition): void {
d.outline(0, 0, G2_LENS_WIDTH, LAYOUT_AREA_HEIGHT, AREA_OUTLINE, 12);
const top = position === "bottom" ? 0 : (LAYOUT_AREA_HEIGHT - MIN_WINDOW_HEIGHT) / 2;
drawLayout(d, position, { top, height: MIN_WINDOW_HEIGHT, fullWidth: false }, true);
d.outline(0, 0, screenWidth(), layoutAreaHeight(), AREA_OUTLINE, 12);
const height = diagramBandHeight(position);
const top = position === "bottom" ? 0 : (layoutAreaHeight() - height) / 2;
drawLayout(d, position, { top, height, fullWidth: false }, true);
}
+5 -5
View File
@@ -3,6 +3,7 @@ import { installedFontPath } from "../../graphics/installed-fonts";
import { wrapText } from "../../graphics/textwrap";
import { TtfFont } from "../../graphics/ttf-font";
import {
defaultUiFontSize,
fontSelectionLabel,
getDefaultSmallFont,
getUiFontSelection,
@@ -25,8 +26,6 @@ const ROW_GAP = 2;
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 = [
@@ -41,7 +40,8 @@ type Face =
| { kind: "fixed"; label: string };
/**
* The UI font's size, 12 to 18px (16 recommended, and selected at first),
* The UI font's size, 12 to 18px (the default size recommended, and
* selected at first: 16px, or 14px on the RayNeo iO),
* 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
@@ -67,7 +67,7 @@ export class TextSizePage implements OnboardingPage {
if (sizes.length) {
this.face = { kind: "sized", file: selection.file, path, sizes };
// The recommended size the first time; on a return, what was left selected.
this.sizeMenu.setItems(sizes, nearestIndex(sizes, this.sizeMenu.selectedItem ?? RECOMMENDED_SIZE));
this.sizeMenu.setItems(sizes, nearestIndex(sizes, this.sizeMenu.selectedItem ?? defaultUiFontSize()));
return;
}
}
@@ -137,7 +137,7 @@ export class TextSizePage implements OnboardingPage {
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;
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);
+35 -23
View File
@@ -56,7 +56,7 @@ import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from "../apps/onb
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
import { voiceControlBridge } from "../native/voice-control";
import { voiceActivity } from "../ui/shell/voice-activity";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, RAYNEO_IO_HEIGHT, RAYNEO_IO_WIDTH } from "../graphics/image";
import { GrayImage } from "../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../graphics/plane";
import { prepareFrameDraws } from "../graphics/glyph-wire";
import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from "./lock-screen";
@@ -75,7 +75,7 @@ import { ALL_APPS } from "../apps/all-apps";
import { type AppContext, type AppDefinition, type AppLaunchParams, type TextEditorHost } from "../apps/app-definition";
import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-process-window";
import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence";
import { appViewportRect, isOnSwitcherEdge, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
import { appViewportRect, isOnSwitcherEdge, screenHeight, screenWidth, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
import { appSwitcherPositionSetting, glassesTypeSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
@@ -191,8 +191,8 @@ const EVEN_APP_DETECTED_MESSAGE =
const LAUNCHABLE_APPS = ALL_APPS.filter((app) => app.showInLauncher !== false);
/**
* The global settings window viewport sizes depend on: the display mode's
* size (a band's position only moves windows), whether the app switcher
* The global settings window viewport sizes depend on: the paired glasses'
* screen, the display mode's size (a band's position only moves windows), whether the app switcher
* takes width beside windows, height below them or neither (a popup), and
* the chrome rows each window loses to it: below them, whether the status
* bar joins the row (dropping the top bar); with a popup, whether the
@@ -205,7 +205,7 @@ function viewportSizesKey(): string {
: position === "popup" ? `popup|${statusBarVisibilitySetting.get()}|${windowBorderSetting.get()}`
: "strip";
const layout = displayLayoutSetting.get();
return `${layout.startsWith("band-") ? "band" : layout}|${switcher}`;
return `${screenWidth()}x${screenHeight()}|${layout.startsWith("band-") ? "band" : layout}|${switcher}`;
}
/** The global settings that move window surfaces without resizing them. */
@@ -214,7 +214,7 @@ function windowPlacementKey(): string {
}
function createInitialDisplayPreview(): ImageSource | null {
return grayImageToPreviewSource(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0));
return grayImageToPreviewSource(new GrayImage(screenWidth(), screenHeight(), 0));
}
/** Echo the controller's appendLog() trace to the console. */
@@ -609,14 +609,28 @@ class DashboardController {
* are. Windows that can't resize keep the surface they have, the switcher
* covering any of it that it now overlaps, rather than being relaunched
* for it.
*
* A window is judged by its own size as well as its surface's rect: other
* paths (connect, a launch) configure surfaces from the geometry without
* resizing windows, so a window laid out before the row's height was known
* (restored at startup, at the default height) can sit behind a surface
* that already matches, and its frames would not fit it.
*/
private applySwitcherBarHeight(): void {
void (async () => {
for (const window of Array.from(shell.getWindows())) {
const rect = JSON.stringify(appViewportRect(window.heightMode, window.appId));
if (!window.relayout || this.windowSurfaceRects.get(window.surfaceId) === rect) continue;
window.relayout();
await this.configureWindowSurface(window.surfaceId, this.isForegroundWindow(window.windowId), window.heightMode);
if (!window.relayout) continue;
const rect = appViewportRect(window.heightMode, window.appId);
const size = window.layoutSize?.();
const resized = !!size && (size.width !== rect.width || size.height !== rect.height);
if (!resized && this.windowSurfaceRects.get(window.surfaceId) === JSON.stringify(rect)) continue;
try {
window.relayout();
await this.configureWindowSurface(window.surfaceId, this.isForegroundWindow(window.windowId), window.heightMode);
} catch (error) {
// The rest still need to follow the row.
this.appendLog(`switcher height change failed for ${window.windowId}: ${this.formatError(error)}`);
}
}
shell.foregroundWindow()?.requestRender();
this.requestShellRender();
@@ -807,8 +821,8 @@ class DashboardController {
await communicator.configureSurface(LOCK_SCREEN_SURFACE_ID, {
x: 0,
y: 0,
width: G2_LENS_WIDTH,
height: G2_LENS_HEIGHT,
width: screenWidth(),
height: screenHeight(),
zOrder: 1000,
transparency: "opaque",
});
@@ -1386,12 +1400,12 @@ class DashboardController {
// is in place before any real render can reach the compositor.
this.previewTarget = target;
try {
await target.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
await target.configureCompositorScreen(screenWidth(), screenHeight());
await target.configureSurface(SHELL_SURFACE_ID, {
x: 0,
y: 0,
width: G2_LENS_WIDTH,
height: G2_LENS_HEIGHT,
width: screenWidth(),
height: screenHeight(),
zOrder: SHELL_SURFACE_Z_ORDER,
transparency: "color-key",
});
@@ -1517,10 +1531,8 @@ class DashboardController {
// configure their surfaces through this.communicator, and the Java call
// queue is FIFO, so enqueuing the screen size first guarantees it lands
// ahead of them. Mirrors ensurePreviewDisplay.
// The iO shows 540x220: the layout stays the G2's and is cropped at the right and
// bottom (geometry.ts pins the band to the top-left while an iO is configured).
if (glassesType === "rayneo-io") await communicator.configureCompositorScreen(RAYNEO_IO_WIDTH, RAYNEO_IO_HEIGHT);
else await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT);
// The paired glasses' screen: the G2's 640x480 or the RayNeo iO's 540x220.
await communicator.configureCompositorScreen(screenWidth(), screenHeight());
await communicator.configureBrightness(getBrightnessPreferences());
this.offState = communicator.onStateChange((state) => {
if (state.phase !== "connected") resetRingInputFilter();
@@ -1702,8 +1714,8 @@ class DashboardController {
await communicator.configureSurface(SHELL_SURFACE_ID, {
x: 0,
y: 0,
width: G2_LENS_WIDTH,
height: G2_LENS_HEIGHT,
width: screenWidth(),
height: screenHeight(),
zOrder: SHELL_SURFACE_Z_ORDER,
transparency: "color-key",
});
@@ -2006,8 +2018,8 @@ class DashboardController {
return;
}
const at = mirrorToPanelFraction(this.displayPreviewCrop, nx, ny);
const x = Math.round(Math.min(1, Math.max(0, at.nx)) * G2_LENS_WIDTH);
const y = Math.round(Math.min(1, Math.max(0, at.ny)) * G2_LENS_HEIGHT);
const x = Math.round(Math.min(1, Math.max(0, at.nx)) * screenWidth());
const y = Math.round(Math.min(1, Math.max(0, at.ny)) * screenHeight());
const foreground = shell.foregroundWindow();
const stripShown = sidebarStripVisible(shell.getFocus(), foreground?.appId);
this.appendLog(`mirror tap at ${x},${y}`);
+8 -5
View File
@@ -1,23 +1,26 @@
import { GrayImage, G2_LENS_WIDTH, G2_LENS_HEIGHT } from "../graphics/image";
import { GrayImage } from "../graphics/image";
import { screenHeight, screenWidth } from "../graphics/screen-size";
import { getDefaultMediumFont } from "../graphics/ui-fonts";
import { wrapText } from "../graphics/textwrap";
export const LOCK_SCREEN_SURFACE_ID = "lock-screen";
const LOCK_SCREEN_MESSAGE = "Glasses locked; unlock the phone to unlock the glasses.";
/** The paired glasses' whole screen, black, with the message in a box at its centre. */
export function createLockScreenImage(): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const width = screenWidth(), height = screenHeight();
const image = new GrayImage(width, height, 0);
const font = getDefaultMediumFont();
const boxWidth = 480;
const boxHeight = 150;
const boxX = Math.round((G2_LENS_WIDTH - boxWidth) / 2);
const boxY = Math.round((G2_LENS_HEIGHT - boxHeight) / 2);
const boxX = Math.round((width - boxWidth) / 2);
const boxY = Math.round((height - boxHeight) / 2);
image.drawRoundedRect(boxX, boxY, boxWidth, boxHeight, 150, 12);
const lines = wrapText(font, LOCK_SCREEN_MESSAGE, boxWidth - 64);
const textHeight = lines.length * font.lineHeight;
const firstY = boxY + Math.round((boxHeight - textHeight) / 2);
lines.forEach((line, index) => {
const x = Math.round((G2_LENS_WIDTH - font.measureText(line)) / 2);
const x = Math.round((width - font.measureText(line)) / 2);
image.drawText(font, x, firstY + index * font.lineHeight, line, 230);
});
return image;
+4 -5
View File
@@ -1,6 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
import { previewScalingSetting } from "../ui/dashboard-settings";
import { phonePreviewRect, usedScreenRect, type ScreenRect } from "../ui/shell/geometry";
import { phonePreviewRect, screenHeight, screenWidth, usedScreenRect, type ScreenRect } from "../ui/shell/geometry";
import { shell } from "../ui/shell/shell";
/**
@@ -14,7 +13,7 @@ export function phonePreviewCrop(locked: boolean, glanceRect: ScreenRect | null)
if (locked || previewScalingSetting.get() === "raw") return null;
const window = shell.foregroundWindow();
const crop = phonePreviewRect(glanceRect ?? usedScreenRect(window?.heightMode ?? "min", window?.appId));
const wholePanel = crop.x === 0 && crop.y === 0 && crop.width === G2_LENS_WIDTH && crop.height === G2_LENS_HEIGHT;
const wholePanel = crop.x === 0 && crop.y === 0 && crop.width === screenWidth() && crop.height === screenHeight();
return wholePanel ? null : crop;
}
@@ -27,7 +26,7 @@ export function phonePreviewCrop(locked: boolean, glanceRect: ScreenRect | null)
export function mirrorToPanelFraction(crop: ScreenRect | null, nx: number, ny: number): { nx: number; ny: number } {
if (!crop) return { nx, ny };
return {
nx: (crop.x + nx * crop.width) / G2_LENS_WIDTH,
ny: (crop.y + ny * crop.height) / G2_LENS_HEIGHT,
nx: (crop.x + nx * crop.width) / screenWidth(),
ny: (crop.y + ny * crop.height) / screenHeight(),
};
}
+27
View File
@@ -0,0 +1,27 @@
/**
* The paired glasses' screen (per eye), which the shell and UI lay out in:
* the G2's 640x480, or the RayNeo iO's 540x220 with the Faceclaw firmware.
*
* Read straight from the settings store (the key dashboard-settings.ts's
* glassesTypeSetting writes), so this stays a leaf that UI primitives can
* import without pulling in the settings module, and every isolate (the
* main one, app workers, the phone preview) agrees with the session.
*/
import { getStringSetting } from "../native/settings-store";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, RAYNEO_IO_HEIGHT, RAYNEO_IO_WIDTH } from "./image";
/** Settings key of the paired glasses' type: "g2" (default) or "rayneo-io". */
export const GLASSES_TYPE_KEY = "deviceType";
/** Whether the paired glasses are a RayNeo iO. */
export function isRayNeoIoConfigured(): boolean {
return getStringSetting(GLASSES_TYPE_KEY, "g2") === "rayneo-io";
}
export function screenWidth(): number {
return isRayNeoIoConfigured() ? RAYNEO_IO_WIDTH : G2_LENS_WIDTH;
}
export function screenHeight(): number {
return isRayNeoIoConfigured() ? RAYNEO_IO_HEIGHT : G2_LENS_HEIGHT;
}
+16 -4
View File
@@ -13,6 +13,7 @@ import type { UiFont } from "./image";
import { TtfFont } from "./ttf-font";
import { ensurePreinstalledFonts, getInstalledFont, installedFontPath } from "./installed-fonts";
import { getStringSetting, onSettingsStoreChanged, setStringSetting } from "../native/settings-store";
import { GLASSES_TYPE_KEY, isRayNeoIoConfigured } from "./screen-size";
export type BitmapFace = "terminus" | "terminusv";
@@ -72,8 +73,18 @@ export function parseFontSelection(raw: string): UiFontSelection | null {
return null;
}
/** Default UI font when the user has never picked one. */
const DEFAULT_UI_FONT: UiFontSelection = { kind: "ttf", file: "Roboto-Light.ttf", size: 16 };
/**
* The default UI font's size, which onboarding recommends: 16, or 14 on the
* RayNeo iO, whose 540x220 screen fits fewer rows.
*/
export function defaultUiFontSize(): number {
return isRayNeoIoConfigured() ? 14 : 16;
}
/** Default UI font when the user has never picked one: Roboto Light at the default size. */
function defaultUiFont(): UiFontSelection {
return { kind: "ttf", file: "Roboto-Light.ttf", size: defaultUiFontSize() };
}
export function getUiFontSelection(): UiFontSelection {
const parsed = parseFontSelection(getStringSetting(UI_FONT_SELECTION_KEY, ""));
@@ -84,7 +95,7 @@ export function getUiFontSelection(): UiFontSelection {
if (legacy === "terminus" || legacy === "terminusv") {
return { kind: "bitmap", face: legacy };
}
return DEFAULT_UI_FONT;
return defaultUiFont();
}
export function setUiFontSelection(selection: UiFontSelection): void {
@@ -113,7 +124,8 @@ export function fontSelectionLabel(selection: UiFontSelection): string {
type UiFontRole = "small" | "medium" | "large";
const UI_FONT_KEYS: readonly string[] = [UI_FONT_SELECTION_KEY, LEGACY_UI_FONT_KEY];
/** Keys whose change re-resolves the UI fonts (the glasses type picks the default size). */
const UI_FONT_KEYS: readonly string[] = [UI_FONT_SELECTION_KEY, LEGACY_UI_FONT_KEY, GLASSES_TYPE_KEY];
/**
* The three role fonts for one selection source, resolved lazily and cached
+8 -5
View File
@@ -25,10 +25,13 @@ import { isValidMacAddress, loadDeviceAddresses } from "../g2/device-addresses";
import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-policy";
import { isPreviewOnlyMode } from "./onboarding-state";
import { formatErrorMessage } from "../util/format-error";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
import { screenHeight, screenWidth } from "../ui/shell/geometry";
import { type PhoneUiButton } from "../apps/evenhub/manager";
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
/** The paired glasses' screen aspect (4:3 on the G2, 27:11 on the RayNeo iO). */
function lensAspectRatio(): number {
return screenWidth() / screenHeight();
}
type LayoutOrientation = "portrait" | "landscape";
@@ -228,7 +231,7 @@ export class MainViewModel extends RemoteControlsViewModel {
}
get displayPreviewHeight(): number {
return Screen.mainScreen.widthDIPs / LENS_ASPECT_RATIO;
return Screen.mainScreen.widthDIPs / lensAspectRatio();
}
get landscapeDisplayPreviewWidth(): number {
@@ -244,8 +247,8 @@ export class MainViewModel extends RemoteControlsViewModel {
// and controls, and updates for rotation, split-screen, and the keyboard.
const { width, height } = args.object.getActualSize();
if (width <= 0 || height <= 0) return;
const previewHeight = Math.min(height, width / LENS_ASPECT_RATIO);
const previewWidth = previewHeight * LENS_ASPECT_RATIO;
const previewHeight = Math.min(height, width / lensAspectRatio());
const previewWidth = previewHeight * lensAspectRatio();
if (previewWidth === this._landscapePreviewWidth && previewHeight === this._landscapePreviewHeight) return;
this._landscapePreviewWidth = previewWidth;
this._landscapePreviewHeight = previewHeight;
+24 -19
View File
@@ -153,37 +153,40 @@ type ConfigSettingEnumOptions<TValue extends string, TId extends string> = Confi
normalize?: (value: string | null | undefined) => TValue;
/** Dynamic availability check used by enum picker rows. */
isDisabled?: (value: TValue) => boolean;
/** A value forced regardless of storage while it returns one (stored choice untouched). */
pinned?: () => TValue | undefined;
/** The default while nothing is stored, when it depends on context (else `defaultValue`). */
dynamicDefault?: () => TValue | undefined;
};
export class ConfigSettingEnum<TValue extends string, TId extends string = string> extends ConfigSetting<TValue, TId> {
readonly values: readonly TValue[];
private readonly normalizer: (value: string | null | undefined) => TValue;
private readonly disabledPredicate: (value: TValue) => boolean;
protected readonly pinned: (() => TValue | undefined) | undefined;
private readonly dynamicDefault: (() => TValue | undefined) | undefined;
constructor(options: ConfigSettingEnumOptions<TValue, TId>) {
super(options);
this.pinned = options.pinned;
this.dynamicDefault = options.dynamicDefault;
if (options.reportInAnalytics !== false) fixedChoiceSettings.set(options.storageKey, this);
this.values = options.values;
this.disabledPredicate = options.isDisabled ?? (() => false);
if (options.normalize) {
this.normalizer = (value: string | null | undefined) => {
const normalized = options.normalize(value) as TValue|undefined;
if (normalized === undefined) return this.defaultValue;
if (normalized === undefined) return this.currentDefault();
return normalized;
}
} else {
this.normalizer = (value) => this.values.includes(value as TValue) ? value as TValue : this.defaultValue;
this.normalizer = (value) => this.values.includes(value as TValue) ? value as TValue : this.currentDefault();
}
}
/** What an unset (or invalid) value reads as now. */
protected currentDefault(): TValue {
return this.dynamicDefault?.() ?? this.defaultValue;
}
get(): TValue {
const pinned = this.pinned?.();
if (pinned !== undefined) return pinned;
return this.normalizer(getStringSetting(this.storageKey, this.defaultValue));
return this.normalizer(getStringSetting(this.storageKey, this.currentDefault()));
}
set(value: TValue): TValue {
@@ -379,7 +382,7 @@ export type GlassesType = "g2" | "rayneo-io";
export const glassesTypeSetting = new ConfigSettingEnum<GlassesType>({
id: "glasses-type",
label: "Glasses",
storageKey: "deviceType",
storageKey: "deviceType", // graphics/screen-size.ts GLASSES_TYPE_KEY reads it directly
defaultValue: "g2",
values: ["g2", "rayneo-io"],
reportInAnalytics: false,
@@ -398,8 +401,8 @@ export const appSwitcherPositionSetting = new ConfigSettingEnum<AppSwitcherPosit
storageKey: "display.appSwitcherPosition",
defaultValue: "bottom",
values: ["left", "right", "bottom", "popup"],
// RayNeo iO, until its own layout: windows at x=0, the strip past the 540 px it shows.
pinned: () => (glassesTypeSetting.get() === "rayneo-io" ? "right" : undefined),
// The RayNeo iO's 220 rows can't spare a bottom row: a side strip by default there.
dynamicDefault: () => (glassesTypeSetting.get() === "rayneo-io" ? "left" : undefined),
formatValue: (value) => APP_SWITCHER_POSITION_LABELS[value] ?? value,
description:
"Where the open-app icons go. Left and right take a column beside windows; bottom puts a row beneath the window, which makes full-height windows a little shorter; popup shows them only while you're in the app switcher, in a box over the dimmed window. Bottom and popup leave room at the sides to set the display's depth. Open apps reopen at their new size when a change resizes windows.",
@@ -415,8 +418,6 @@ class ConfigSettingEnumWithLegacy<TValue extends string> extends ConfigSettingEn
}
get(): TValue {
const pinned = this.pinned?.();
if (pinned !== undefined) return pinned;
return getStringSetting(this.storageKey, "") === "" ? this.legacyValue() : super.get();
}
}
@@ -478,8 +479,6 @@ export const displayLayoutSetting = new ConfigSettingEnumWithLegacy<DisplayLayou
storageKey: "display.layout",
defaultValue: "band-middle",
values: DISPLAY_LAYOUT_VALUES,
// RayNeo iO, until its own layout: the band at the top, where its 220 rows look.
pinned: () => (glassesTypeSetting.get() === "rayneo-io" ? "band-top" : undefined),
formatValue: displayLayoutLabel,
isDisabled: (value) => value === "fullscreen" && !fullScreenAvailable(),
description:
@@ -1683,11 +1682,17 @@ export class EditTextSettingLayer implements Layer {
for (let index = 0; index < message.length; index++) {
image.drawText(font, 22, messageTop + index * step, message[index]!, 200);
}
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.get(), 52), 220);
const valueY = messageTop + (message.length + 2) * step;
image.drawText(font, 22, valueY, truncateSetting(this.setting.get(), 52), 220);
const error = this.setting.validationError();
if (error) wrapText(font, error, width - 48).forEach((line, index) =>
const errorLines = error ? wrapText(font, error, width - 48) : [];
errorLines.forEach((line, index) =>
image.drawText(font, 22, messageTop + (message.length + 4 + index) * step, line, 180));
image.drawText(font, 22, height - 24 - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
// The back hint at the bottom, unless a short window (the RayNeo iO's)
// leaves it no room under the value and error.
const contentBottom = errorLines.length ? messageTop + (message.length + 4 + errorLines.length) * step : valueY + step;
const hintY = height - 24 - font.lineHeight;
if (hintY >= contentBottom) image.drawText(font, 22, hintY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
+25 -1
View File
@@ -36,6 +36,8 @@ const ROW_GAP = 2;
/** Horizontal inset of row text (and custom row content) from its selection box. */
const ROW_TEXT_X = 10;
const MAX_DESCRIPTION_LINES = 3;
/** Rows a section's list keeps beside its detail while focus is in it (see detailCrowdsList). */
const MIN_LIST_ROWS = 3;
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
// settings items never use it (they act via ctx only).
const NO_MENU = new MenuLayer(null, []);
@@ -134,7 +136,7 @@ export class SettingsPanelLayer implements Layer {
const rightX = divX + 14;
const rightW = width - rightX - PAD;
let rightTop = top;
if (section.renderDetail) {
if (section.renderDetail && !this.detailCrowdsList(section, ctx, font, { x: rightX, y: top, width: rightW, height: listBottom - top })) {
const used = section.renderDetail({ image, x: rightX, y: top, width: rightW, height: listBottom - top, ctx });
rightTop = typeof used === "number" ? Math.min(top + used, listBottom) : listBottom;
}
@@ -157,6 +159,28 @@ export class SettingsPanelLayer implements Layer {
return image;
}
/**
* Whether the section's detail (About's blurb, the watch status) would
* leave its rows less than MIN_LIST_ROWS while focus is in them, as on a
* short screen (the RayNeo iO's): the list then takes the whole pane, the
* detail staying in the preview. Measured by drawing the detail on a
* scratch image.
*/
private detailCrowdsList(
section: SettingsSection,
ctx: LayerContext,
font: UiFont,
pane: { x: number; y: number; width: number; height: number },
): boolean {
if (this.focus !== "right" || !section.items.length || !section.renderDetail) return false;
const scratch = new GrayImage(pane.x + pane.width, pane.y + pane.height, 0);
const used = section.renderDetail({ image: scratch, ...pane, ctx });
if (typeof used !== "number") return false;
const rows = Math.min(MIN_LIST_ROWS, section.items.length);
const room = pane.height - used - this.descriptionHeight(font, pane.width);
return room < rows * (listRowHeight(font) + ROW_GAP);
}
/** The selected item's wrapped help text, or [] when none applies. */
private descriptionLines(font: UiFont, rightW: number): string[] {
if (this.focus !== "right") return [];
+32 -9
View File
@@ -13,6 +13,7 @@ import { getFont } from "../graphics/bdffont";
import { GrayImage, type UiFont } from "../graphics/image";
import { TtfFont } from "../graphics/ttf-font";
import { listInstalledFonts, type InstalledFont } from "../graphics/installed-fonts";
import { wrapText } from "../graphics/textwrap";
import {
fontSelectionLabel,
getDefaultSmallFont,
@@ -140,18 +141,40 @@ export class FontPickerLayer implements Layer {
const rowWidth = width - 2 * rowX;
const rowHeight = listRowHeight(font);
const rowsTop = 24 + font.lineHeight;
this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: rowWidth + 20, height: ROWS.length * rowHeight }, focused);
// Preview: a separator, then the sample line in the draft font.
const previewTop = rowsTop + ROWS.length * rowHeight + 10;
image.drawLine(rowX - 10, previewTop, rowX + rowWidth + 10, previewTop, 60);
const rowsHeight = ROWS.length * rowHeight;
const preview = this.previewFont();
const sample =
preview.measureText(PREVIEW_TEXT) <= rowWidth + 20 ? PREVIEW_TEXT : "The quick brown fox 0123";
preview.drawText(image, rowX - 4, previewTop + 8, sample, 230);
const info = `Line height: ${preview.lineHeight}px`;
image.drawText(font, rowX - 4, previewTop + 8 + preview.lineHeight + 6, info, 110);
// Preview under the rows, where its sample line and the info line fit
// (the G2's window): a separator, then the sample line in the draft font.
const previewTop = rowsTop + rowsHeight + 10;
if (previewTop + 8 + preview.lineHeight + 6 + font.lineHeight <= height) {
this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: rowWidth + 20, height: rowsHeight }, focused);
image.drawLine(rowX - 10, previewTop, rowX + rowWidth + 10, previewTop, 60);
const sample =
preview.measureText(PREVIEW_TEXT) <= rowWidth + 20 ? PREVIEW_TEXT : "The quick brown fox 0123";
preview.drawText(image, rowX - 4, previewTop + 8, sample, 230);
image.drawText(font, rowX - 4, previewTop + 8 + preview.lineHeight + 6, info, 110);
return image;
}
// Else beside them (a short window, as on the RayNeo iO), the sample
// wrapped to the column, as many lines as fit above the info line.
const columnWidth = Math.round(rowWidth / 2);
const bottom = height - 8;
this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: columnWidth + 20, height: Math.min(rowsHeight, bottom - rowsTop) }, focused);
const dividerX = rowX + columnWidth + 20;
image.drawLine(dividerX, rowsTop, dividerX, Math.min(rowsTop + rowsHeight, bottom), 60);
const previewX = dividerX + 12;
const lines = wrapText(preview, PREVIEW_TEXT, width - previewX - 12);
const infoY = bottom - font.lineHeight;
let y = rowsTop + 4;
for (const line of lines) {
if (y + preview.lineHeight > infoY - 6) break;
preview.drawText(image, previewX, y, line, 230);
y += preview.lineHeight;
}
image.drawText(font, previewX, Math.min(infoY, y + 6), info, 110);
return image;
}
+4 -3
View File
@@ -1,4 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import { GrayImage } from "../graphics/image";
import { screenHeight, screenWidth } from "../graphics/screen-size";
import { dimPlanes, type Plane } from "../graphics/plane";
import { spanCurrent } from "../native/frame-timings";
import { type ConfigSettingBoolean, type ConfigSettingString, type VoiceProvider } from "./dashboard-settings";
@@ -172,8 +173,8 @@ export class LayerStack {
stack: this,
actions,
};
this.baseWidth = baseSize?.width ?? G2_LENS_WIDTH;
this.baseHeight = baseSize?.height ?? G2_LENS_HEIGHT;
this.baseWidth = baseSize?.width ?? screenWidth();
this.baseHeight = baseSize?.height ?? screenHeight();
this.focusedFn = isFocused;
}
+13 -4
View File
@@ -1,4 +1,5 @@
import { G2_LENS_HEIGHT, GrayImage, type UiFont } from "../graphics/image";
import { GrayImage, type UiFont } from "../graphics/image";
import { screenHeight } from "../graphics/screen-size";
import { wrapText } from "../graphics/textwrap";
import { getDefaultSmallFont } from "../graphics/ui-fonts";
import { getStringSetting } from "../native/settings-store";
@@ -18,9 +19,14 @@ setMenuAnimationReader(() => normalizeAnimationSpeed(getStringSetting(MENU_ANIMA
const DEFAULT_MENU_X = 8;
const DEFAULT_MENU_Y = 8;
const DEFAULT_MENU_WIDTH = 272;
/** Windows shorter than this (the RayNeo iO's, not the G2's) get tighter modal margins. */
const SHORT_WINDOW_HEIGHT = 200;
// Menus grow with their item count, from half the screen (matching the old
// fixed quarter-screen-era look) up to the full screen, then scroll.
const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y;
/** Half the screen, less the menu's top and bottom offsets. */
function defaultMenuMinHeight(): number {
return screenHeight() / 2 - 2 * DEFAULT_MENU_Y;
}
const MENU_BODY_PADDING = 8;
/** Gap between the last item row and a footer hint line. */
const MENU_FOOTER_GAP = 8;
@@ -302,7 +308,7 @@ export class MenuLayer implements Layer {
const { y, width } = this.layout;
const x = this.layout.x === "center" ? ((image.width - width) / 2) | 0 : this.layout.x;
const chromeTop = (this.title ? menuTitleHeight(font) : 0) + MENU_BODY_PADDING;
const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT;
const minHeight = this.layout.minHeight ?? defaultMenuMinHeight();
// Cap to the surface being painted on: a window's stack image may be much
// shorter than the full screen (min-height windows).
const maxHeight = Math.min(
@@ -376,7 +382,10 @@ export function openModalMenu(
const font = getDefaultSmallFont();
const menuWidth = Math.min(320, width - 40);
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font);
const menuHeight = Math.min(naturalHeight, height - 40);
// 20px clear above and below, or 8 in a short window (the RayNeo iO's),
// where those rows are worth more than the margin.
const marginY = height < SHORT_WINDOW_HEIGHT ? 8 : 20;
const menuHeight = Math.min(naturalHeight, height - 2 * marginY);
const layout: MenuLayout = {
x: ((width - menuWidth) / 2) | 0,
y: ((height - menuHeight) / 2) | 0,
+13 -7
View File
@@ -8,7 +8,11 @@ import { appViewportRect, SHELL_OPAQUE_BLACK } from "./geometry";
const DIALOG_WIDTH = 272;
const BAR_WIDTH = 12;
/** The bar's height where the window has room (the G2's); it shrinks to fit a shorter one, down to MIN_BAR_HEIGHT. */
const BAR_HEIGHT = 100;
const MIN_BAR_HEIGHT = 24;
/** Clear space kept above and below the dialog in the window. */
const MARGIN_Y = 4;
/** Manual brightness changes apply immediately so the wearer can judge the level. */
export class BrightnessPickerLayer implements Layer {
@@ -22,7 +26,9 @@ export class BrightnessPickerLayer implements Layer {
const image = paintBelow();
const font = getDefaultSmallFont();
const viewport = appViewportRect("min");
const height = BAR_HEIGHT + 3 * font.lineHeight + 56;
const chrome = 3 * font.lineHeight + 56;
const barHeight = clamp(viewport.height - 2 * MARGIN_Y - chrome, MIN_BAR_HEIGHT, BAR_HEIGHT);
const height = barHeight + chrome;
const left = viewport.x + Math.round((viewport.width - DIALOG_WIDTH) / 2);
const top = viewport.y + Math.round((viewport.height - height) / 2);
image.fillRect(left, top, DIALOG_WIDTH, height, SHELL_OPAQUE_BLACK);
@@ -35,14 +41,14 @@ export class BrightnessPickerLayer implements Layer {
const barX = left + Math.round((DIALOG_WIDTH - BAR_WIDTH) / 2);
const barY = top + font.lineHeight + 24;
const level = brightnessSettingToLevel(brightnessSetting.get());
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, BAR_HEIGHT + 4, 150);
const filledHeight = Math.round(BAR_HEIGHT * (level ?? 0) / 100);
image.fillRect(barX, barY + BAR_HEIGHT - filledHeight, BAR_WIDTH, filledHeight, 255);
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((BAR_HEIGHT - font.lineHeight) / 2),
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, barHeight + 4, 150);
const filledHeight = Math.round(barHeight * (level ?? 0) / 100);
image.fillRect(barX, barY + barHeight - filledHeight, BAR_WIDTH, filledHeight, 255);
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((barHeight - font.lineHeight) / 2),
level === null ? "Auto" : `${level}%`, 235);
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + BAR_HEIGHT + 12, 150);
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + barHeight + 12, 150);
centeredText(gestureHints([[`${GESTURE_CLICK} / ${GESTURE_DOUBLE_CLICK}`, "confirm"]]),
barY + BAR_HEIGHT + font.lineHeight + 16, 150);
barY + barHeight + font.lineHeight + 16, 150);
return image;
}
+20 -15
View File
@@ -1,7 +1,7 @@
import { shellCrop } from "../../graphics/shell-scene";
import type { Plane } from "../../graphics/plane";
import { DrawOp, type ListCall, type ListClip } from "../../graphics/display-list";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, grayToNibble } from "../../graphics/image";
import { GrayImage, grayToNibble } from "../../graphics/image";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
import { truncateText } from "../../graphics/textwrap";
import { activeAmbientCards } from "./ambient-cards";
@@ -29,7 +29,9 @@ import { lineStep } from "../metrics";
import {
appViewportRect,
isImmersive,
MIN_WINDOW_HEIGHT,
minWindowHeight,
screenHeight,
screenWidth,
minWindowTop,
setSwitcherBarHeight,
SHELL_OPAQUE_BLACK,
@@ -68,7 +70,10 @@ const TWO_COLUMN: SidebarVariant = { columns: 2, columnWidth: 32, iconSize: 28 }
const ICON_SPACING = 8;
/** Icon list top/bottom margins within the sidebar band, below the top bar (and a bottom row's end margins). */
const LIST_MARGIN = 10;
const LIST_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
/** Height of the sidebar's icon list: the min-height band less its top bar and margins. */
function listHeight(appId?: string): number {
return minWindowHeight(appId) - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
}
/** Bottom-row icons: one tall tab's worth of row, the icon inset 2px all round. */
const ROW_ICON_SIZE = SWITCHER_ROW_HEIGHT - 4;
@@ -123,7 +128,7 @@ const POPUP_DIM = 0.5;
/** Icon rows that fit in one sidebar column. */
function rowsPerColumn(variant: SidebarVariant): number {
return Math.max(1, ((LIST_HEIGHT + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
return Math.max(1, ((listHeight() + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
}
function sidebarVariant(windowCount: number): SidebarVariant {
@@ -136,7 +141,7 @@ function sidebarVariant(windowCount: number): SidebarVariant {
*/
function columnLeft(variant: SidebarVariant, column: number, position: AppSwitcherPosition): number {
return position === "right"
? G2_LENS_WIDTH - SIDEBAR_WIDTH + column * variant.columnWidth
? screenWidth() - SIDEBAR_WIDTH + column * variant.columnWidth
: SIDEBAR_WIDTH - (column + 1) * variant.columnWidth;
}
@@ -382,7 +387,7 @@ export function sidebarContentSpan(windowCount: number): { left: number; right:
const variant = sidebarVariant(windowCount);
const width = variant.columns * variant.columnWidth;
return switcherPosition() === "right"
? { left: G2_LENS_WIDTH - SIDEBAR_WIDTH, right: G2_LENS_WIDTH - SIDEBAR_WIDTH + width }
? { left: screenWidth() - SIDEBAR_WIDTH, right: screenWidth() - SIDEBAR_WIDTH + width }
: { left: SIDEBAR_WIDTH - width, right: SIDEBAR_WIDTH };
}
@@ -396,7 +401,7 @@ function topBarSpan(state: ShellChromeState): { left: number; right: number } {
if (sidebarStripVisible(state.focus, state.foregroundAppId)) {
const position = switcherPosition();
if (position === "left") left = Math.max(left, SIDEBAR_WIDTH);
if (position === "right") right = Math.min(right, G2_LENS_WIDTH - SIDEBAR_WIDTH);
if (position === "right") right = Math.min(right, screenWidth() - SIDEBAR_WIDTH);
}
return { left, right };
}
@@ -624,7 +629,7 @@ export class ShellChromeLayer implements Layer {
) {}
paint(): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const image = new GrayImage(screenWidth(), screenHeight(), 0);
const state = this.getState();
this.statusEntries = [];
this.bottomBar = this.layoutBottomBar(state);
@@ -651,7 +656,7 @@ export class ShellChromeLayer implements Layer {
this.statusEntries = [];
this.bottomBar = this.layoutBottomBar(state);
const statusInRow = statusInSwitcherRow(state.foregroundAppId);
const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const canvas = new GrayImage(screenWidth(), screenHeight(), 0);
const span = topBarSpan(state);
const bar = statusBarPlacement(state);
if (bar) {
@@ -664,7 +669,7 @@ export class ShellChromeLayer implements Layer {
return parts;
}
if (switcherShown) {
const stripCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const stripCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
const statusLeft = this.drawSidebar(stripCanvas, state, statusInRow ? canvas : undefined);
// The window frame rides on the switcher row, whose top edge is its
// bottom side, and so replays after any top bar, whose bottom row is
@@ -704,14 +709,14 @@ export class ShellChromeLayer implements Layer {
// to be sent at all, so the frame rides on one at its top-left corner,
// outside its curve, which it paints black anyway. As in the bottom
// row's case, it plays at the screen's own depth.
const frameCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const frameCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
frameCanvas.fillRect(frame.x, frame.y, 1, 1, SHELL_OPAQUE_BLACK);
drawWindowFrame(frameCanvas, frame, false, true);
parts.push(shellCrop(frameCanvas, frame.x, frame.y, 1, 1, 1));
}
drawAmbientCards(canvas, topBarSpan(state).right, parts);
if (!switcherShown) return;
const popupCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const popupCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
const box = this.drawPopup(popupCanvas, state);
this.popupKey ??= LayerStack.allocateShellKey();
parts.push({ ...shellCrop(popupCanvas, box.x, box.y, box.width, box.height, this.popupKey), depth: POPUP_DEPTH });
@@ -892,8 +897,8 @@ export class ShellChromeLayer implements Layer {
const batteries = batteryItems(state);
if (batteries.length) {
// Measured by drawing it: each battery style lays itself out as it draws.
const scratch = new GrayImage(G2_LENS_WIDTH, TOP_BAR_HEIGHT, 0);
const width = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN - drawBatteryBlock(scratch, batteries, 0, G2_LENS_WIDTH);
const scratch = new GrayImage(screenWidth(), TOP_BAR_HEIGHT, 0);
const width = screenWidth() - BATTERY_BLOCK_RIGHT_MARGIN - drawBatteryBlock(scratch, batteries, 0, screenWidth());
// The block keeps its usual right margin inside the edge it's given.
items.push({ kind: "batteries", width,
draw: (image, x, top) => drawBatteryBlock(image, batteries, top, x + width + BATTERY_BLOCK_RIGHT_MARGIN) });
@@ -1237,7 +1242,7 @@ function drawAmbientCards(image: GrayImage, right: number, parts?: Plane[]): voi
if (!cards.length) return;
const font = getDefaultSmallFont();
const bandTop = minWindowTop();
const bandBottom = bandTop + MIN_WINDOW_HEIGHT - windowFooterHeight();
const bandBottom = bandTop + minWindowHeight() - windowFooterHeight();
// Right-aligned with the top bar: clear of a right-hand sidebar.
const x = right - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
const textWidth = AMBIENT_CARD_WIDTH - 2 * AMBIENT_CARD_PADDING_X;
+36 -22
View File
@@ -1,4 +1,4 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
import { screenHeight, screenWidth } from "../../graphics/screen-size";
import {
appSwitcherPositionSetting,
type AppSwitcherPosition,
@@ -12,6 +12,9 @@ import {
windowBorderSetting,
} from "../dashboard-settings";
/** The paired glasses' screen, which the shell lays out in (graphics/screen-size.ts). */
export { screenHeight, screenWidth };
/** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28;
/**
@@ -174,15 +177,15 @@ export function switcherRect(heightMode: WindowHeightMode, appId?: string): { x:
const height = reserved || switcherBarHeights.overlay;
return {
x: appViewportLeft(appId),
y: reserved > 0 ? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId) : G2_LENS_HEIGHT - height,
y: reserved > 0 ? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId) : screenHeight() - height,
width: appViewportWidth(appId),
height,
};
}
case "right":
return { x: G2_LENS_WIDTH - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
return { x: screenWidth() - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: minWindowHeight(appId) };
default:
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: minWindowHeight(appId) };
}
}
@@ -293,15 +296,15 @@ export function isOnSwitcherEdge(x: number, y: number, heightMode: WindowHeightM
case "bottom":
return y >= switcherRect(heightMode, appId).y;
case "right":
return x >= G2_LENS_WIDTH - SIDEBAR_WIDTH;
return x >= screenWidth() - SIDEBAR_WIDTH;
default:
return x < SIDEBAR_WIDTH;
}
}
/** Width of app windows: the panel's when Full Screen or immersive, else 576 (see SIDEBAR_WIDTH). */
/** Width of app windows: the screen's when Full Screen or immersive, else SIDEBAR_WIDTH less (576 on the G2). */
function appViewportWidth(appId?: string): number {
return fullWidth(appId) ? G2_LENS_WIDTH : G2_LENS_WIDTH - SIDEBAR_WIDTH;
return fullWidth(appId) ? screenWidth() : screenWidth() - SIDEBAR_WIDTH;
}
/**
@@ -353,7 +356,7 @@ export function effectiveHeightMode(mode: WindowHeightMode, appId?: string): Win
* rather than use the viewport's own centre.
*/
export function screenCenterInViewportX(): number {
return Math.round(G2_LENS_WIDTH / 2) - appViewportLeft();
return Math.round(screenWidth() / 2) - appViewportLeft();
}
/**
@@ -374,15 +377,23 @@ export const SHELL_OPAQUE_BLACK = 1;
*/
export type WindowHeightMode = "min" | "medium" | "max";
/** Total height (header + content) of a min-height window. */
/** Total height (header + content) of a min-height window on a screen with room for it: the G2's stock band. */
export const MIN_WINDOW_HEIGHT = 288;
/**
* Total height of a min-height window here: the stock 288px band, or the
* whole window area on a screen too short for it (the RayNeo iO's 220 rows).
*/
export function minWindowHeight(appId?: string): number {
return Math.min(MIN_WINDOW_HEIGHT, windowAreaHeight(appId));
}
/**
* Height of the screen area windows are placed in: the whole screen, less
* a bottom switcher's height.
*/
function windowAreaHeight(appId?: string): number {
return G2_LENS_HEIGHT - switcherRowHeight(appId);
return screenHeight() - switcherRowHeight(appId);
}
/** Total height (header + content + footer) of a window's band in the given mode. */
@@ -391,9 +402,9 @@ export function windowBandHeight(mode: WindowHeightMode, appId?: string): number
case "max":
return windowAreaHeight(appId);
case "medium":
return MIN_WINDOW_HEIGHT + windowHeaderHeight(appId) + windowFooterHeight(appId);
return Math.min(windowAreaHeight(appId), minWindowHeight(appId) + windowHeaderHeight(appId) + windowFooterHeight(appId));
default:
return MIN_WINDOW_HEIGHT;
return minWindowHeight(appId);
}
}
@@ -425,7 +436,7 @@ export function minWindowTop(appId?: string): number {
*/
export function windowTop(mode: WindowHeightMode, appId?: string): number {
const band = windowBandHeight(mode, appId);
const oneRowArea = G2_LENS_HEIGHT - (switcherRowHeight(appId) > 0 ? SWITCHER_ROW_HEIGHT : 0);
const oneRowArea = screenHeight() - (switcherRowHeight(appId) > 0 ? SWITCHER_ROW_HEIGHT : 0);
const top = Math.round((oneRowArea - band) * verticalPositionFraction(appId));
return Math.min(top, windowAreaHeight(appId) - band);
}
@@ -473,13 +484,13 @@ function unionRect(a: ScreenRect, b: ScreenRect): ScreenRect {
* the whole panel. The phone mirror's Scaled preview zooms to this.
*/
export function usedScreenRect(heightMode: WindowHeightMode, appId?: string): ScreenRect {
if (isImmersive(appId)) return { x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT };
if (isImmersive(appId)) return { x: 0, y: 0, width: screenWidth(), height: screenHeight() };
const frame = windowFramed(appId) ? 1 : 0;
const x = appViewportLeft(appId) - frame;
const width = appViewportWidth(appId) + 2 * frame;
let used = unionRect(
{ x, y: windowTop(heightMode, appId), width, height: windowBandHeight(heightMode, appId) },
{ x, y: minWindowTop(appId), width, height: MIN_WINDOW_HEIGHT },
{ x, y: minWindowTop(appId), width, height: minWindowHeight(appId) },
);
if (switcherPosition() !== "popup") used = unionRect(used, switcherRect(heightMode, appId));
return used;
@@ -487,15 +498,18 @@ export function usedScreenRect(heightMode: WindowHeightMode, appId?: string): Sc
/**
* The screen area the phone mirror shows to present `used` as large as it
* fits, centred, at the panel's own 4:3 aspect (so the mirror keeps its
* shape whatever the display mode): `used` grown along one axis, past the
* panel's edges if need be (the mirror shows black there).
* fits, centred, at the screen's own aspect (4:3 on the G2, 27:11 on the iO),
* so the mirror keeps its shape whatever the display mode: `used` grown along
* one axis, past the screen's edges if need be (the mirror shows black there).
*/
export function phonePreviewRect(used: ScreenRect): ScreenRect {
// Whole 4:3 units, so the aspect is exact.
const units = Math.ceil(Math.max(used.width / 4, used.height / 3));
const width = units * 4;
const height = units * 3;
// Whole aspect units, so the aspect is exact.
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
const unit = gcd(screenWidth(), screenHeight());
const aspectW = screenWidth() / unit, aspectH = screenHeight() / unit;
const units = Math.ceil(Math.max(used.width / aspectW, used.height / aspectH));
const width = units * aspectW;
const height = units * aspectH;
return {
x: Math.round(used.x + (used.width - width) / 2),
y: Math.round(used.y + (used.height - height) / 2),
+1
View File
@@ -226,6 +226,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
options.reconfigureSurface?.(heightMode);
requestRender();
},
layoutSize: () => stack.getBaseSize(),
hitTest: async (x, y) => {
const handled = await stack.hitTest(x, y);
if (handled) requestRender();
+23 -14
View File
@@ -1,9 +1,9 @@
import { G2_LENS_WIDTH, GrayImage, type UiFont } from "../../graphics/image";
import { GrayImage, type UiFont } from "../../graphics/image";
import { wrapText, truncateText } from "../../graphics/textwrap";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { Menu, type MenuDrawArgs } from "../menu-core";
import { listRowHeight, textInkBounds } from "../metrics";
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
import { minWindowHeight, minWindowTop, screenWidth } from "./geometry";
/**
* The shared look of the shell's text dialogs (voice input, phone keyboard
@@ -13,17 +13,26 @@ import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
*/
const DIALOG_X = 40;
const DIALOG_W = G2_LENS_WIDTH - 80;
/** The screen less DIALOG_X on each side. */
function dialogW(): number {
return screenWidth() - 2 * DIALOG_X;
}
// The dialog fits inside the min-height window band (like the other shell
// overlays), wherever the vertical position setting puts it.
const DIALOG_MARGIN_Y = 28;
const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y;
const TEXT_MAX_WIDTH = DIALOG_W - 32;
function dialogH(): number {
return minWindowHeight() - 2 * DIALOG_MARGIN_Y;
}
function textMaxWidth(): number {
return dialogW() - 32;
}
const TEXT_LEFT = DIALOG_X + 16;
// Menu row boxes: 4px left of the text column, 2px shorter than the row
// pitch, with each row's label inset 8px / 4px into its box.
const MENU_X = TEXT_LEFT - 4;
const MENU_W = DIALOG_W - 24;
function menuW(): number {
return dialogW() - 24;
}
const MENU_ROW_GAP = 2;
const MENU_LABEL_INSET_X = 8;
const MENU_LABEL_INSET_Y = 4;
@@ -89,28 +98,28 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
// Solid dialog box over the underlying UI. Fill 1, not 0: identical after
// 4bpp quantization, but 0 is transparent on the color-key shell surface.
image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1);
image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90);
image.fillRect(DIALOG_X, top, dialogW(), dialogH(), 1);
image.drawRect(DIALOG_X, top, dialogW(), dialogH(), 90);
// Title and status share one header line, the status in the space after the title.
const left = TEXT_LEFT;
const headerY = top + 12;
image.drawText(font, left, headerY, content.title, 220);
const statusLeft = left + Math.ceil(font.measureText(content.title)) + HEADER_STATUS_GAP;
const statusWidth = TEXT_LEFT + TEXT_MAX_WIDTH - statusLeft;
const statusWidth = TEXT_LEFT + textMaxWidth() - statusLeft;
image.drawText(font, statusLeft, headerY, truncateText(font, content.status, statusWidth), content.statusValue ?? 130);
const menu = content.menu;
const rowCount = menu?.items.length ?? 0;
// Reserve space for the actual number of rows this menu has, or one row for the hint.
const reservedRows = rowCount > 0 ? rowCount : content.hint ? 1 : 0;
const textBottom = top + DIALOG_H - reservedRows * menuRowH - 8;
const textBottom = top + dialogH() - reservedRows * menuRowH - 8;
const textTop = headerY + font.lineHeight + 12;
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
// The tail of a long message stays in view: it is what was said last (or
// where the phone keyboard is typing).
const wrapped = wrapText(font, content.text, TEXT_MAX_WIDTH);
const wrapped = wrapText(font, content.text, textMaxWidth());
const firstLine = Math.max(0, wrapped.length - maxLines);
for (let index = firstLine; index < wrapped.length; index++) {
image.drawText(font, left, textTop + (index - firstLine) * 16, wrapped[index]!, 235);
@@ -118,11 +127,11 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
if (menu && rowCount > 0) {
// Row boxes are one pitch apart, the last ending 6px above the dialog's bottom edge.
const menuTop = top + DIALOG_H - rowCount * menuRowH - 4;
menu.paint(image, { x: MENU_X, y: menuTop, width: MENU_W, height: rowCount * menuRowH - MENU_ROW_GAP }, true);
const menuTop = top + dialogH() - rowCount * menuRowH - 4;
menu.paint(image, { x: MENU_X, y: menuTop, width: menuW(), height: rowCount * menuRowH - MENU_ROW_GAP }, true);
} else if (content.hint) {
// On the line the last menu row's label would occupy, floating in front of the dialog.
drawDepthText(image, font, truncateText(font, content.hint, TEXT_MAX_WIDTH), left, top + DIALOG_H - menuRowH, HINT_VALUE, HINT_DEPTH);
drawDepthText(image, font, truncateText(font, content.hint, textMaxWidth()), left, top + dialogH() - menuRowH, HINT_VALUE, HINT_DEPTH);
}
}
+17 -6
View File
@@ -1,5 +1,5 @@
import { encodeShellScene } from "../../graphics/shell-scene";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { GrayImage } from "../../graphics/image";
import { singlePlane, type Plane } from "../../graphics/plane";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from "../../g2/events";
@@ -82,6 +82,8 @@ import {
windowFramed,
windowTop,
type WindowHeightMode,
screenHeight,
screenWidth,
} from "./geometry";
import type { AppSwitcherPosition } from "../dashboard-settings";
@@ -163,6 +165,12 @@ export type ShellWindow = {
* they opened with when the bottom switcher changes height.
*/
relayout?: () => void;
/**
* The viewport size the window is laid out at (it changes on relayout), so
* the controller can tell a window whose size fell behind the geometry from
* one whose surface merely moved.
*/
layoutSize?: () => { width: number; height: number };
/**
* A touch from the phone's mirror at (x, y) in app-viewport coordinates.
* True if the window acted on it; otherwise the controller sends a select.
@@ -354,7 +362,10 @@ class ShellOverlayMenuLayer extends MenuLayer {
/** How long a show_alert popup stays before auto-dismissing. */
const ALERT_DISMISS_MS = 6000;
const ALERT_X = 40;
const ALERT_W = G2_LENS_WIDTH - 80;
/** Alert width: the screen less ALERT_X on each side. */
function alertW(): number {
return screenWidth() - 2 * ALERT_X;
}
const ALERT_Y = 96;
const ALERT_H = 96;
@@ -378,14 +389,14 @@ class ShellAlertLayer implements Layer {
const font = getDefaultSmallFont();
// Positioned within the min-height window band, like the other shell overlays.
const alertY = minWindowTop() + ALERT_Y;
image.fillRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1);
image.drawRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90);
image.fillRect(ALERT_X, alertY, alertW(), ALERT_H, 1);
image.drawRect(ALERT_X, alertY, alertW(), ALERT_H, 90);
image.drawText(font, ALERT_X + 16, alertY + 12, "Assistant", 200);
image.drawTextWrapped({
font,
x: ALERT_X + 16,
y: alertY + 18 + font.lineHeight + 4,
width: ALERT_W - 32,
width: alertW() - 32,
text: this.text,
value: 235,
});
@@ -965,7 +976,7 @@ class Shell {
paintSurface(): Plane[] {
if (!this.screenOn) {
return singlePlane(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0));
return singlePlane(new GrayImage(screenWidth(), screenHeight(), 0));
}
return this.stack.paint();
}
+7 -2
View File
@@ -445,12 +445,13 @@ export class WorkerAppHost {
const surfaceId = `window:${spec.windowId}`;
const heightMode = spec.heightMode ?? "min";
this.openWindows.add(spec.windowId);
let viewport = appViewportSize(heightMode, this.options.appId);
this.post({
type: "open-window",
windowId: spec.windowId,
surfaceId,
title: spec.title,
viewport: appViewportSize(heightMode, this.options.appId),
viewport,
});
const window: ShellWindow = {
appId: this.options.appId,
@@ -463,7 +464,11 @@ export class WorkerAppHost {
// Every app worker resizes its live content in place, keeping its state
// (a game in progress, a route): the bottom switcher's height changes
// with what it holds, and full-height windows give way to it.
relayout: () => this.post({ type: "resize-window", windowId: spec.windowId, viewport: appViewportSize(heightMode, this.options.appId) }),
relayout: () => {
viewport = appViewportSize(heightMode, this.options.appId);
this.post({ type: "resize-window", windowId: spec.windowId, viewport });
},
layoutSize: () => viewport,
hasAppMenu: () => this.windowGestures.get(spec.windowId)?.hasAppMenu ?? false,
claimsLongPress: () => this.windowGestures.get(spec.windowId)?.claimsLongPress ?? false,
close: () => {
+2
View File
@@ -258,6 +258,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
const layers = load('app/ui/layers.ts', {
'../graphics/image': images, '../graphics/plane': { dimPlanes: (planes) => planes },
'../native/frame-timings': timings, './gestures': gestures,
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
});
class Menu {
constructor(title, items) { this.title = title; this.items = items; this.selectedIndex = 0; }
@@ -285,6 +286,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../../native/notification-icons': {}, '../../native/notification-sources': {},
'../../assistant/tool-registry': {}, './geometry': {
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
screenWidth: () => 640, screenHeight: () => 480,
appViewportRect: () => ({ x: 64, y: 124, width: 576, height: 260 }),
},
});
+76 -3
View File
@@ -9,20 +9,21 @@ const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
function geometry() {
// The shell geometry over a G2's 640x480 screen, or `screen` (a RayNeo iO is 540x220).
function geometry(screen = { width: 640, height: 480 }) {
const settings = Object.fromEntries(Object.entries({
displayLayoutSetting: 'band-middle', navigateDisplayLayoutSetting: 'global', terminalDisplayLayoutSetting: 'default',
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
const context = { exports: {}, require: (name) => {
if (name === '../../graphics/image') return { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 };
if (name === '../../graphics/screen-size') return { screenWidth: () => screen.width, screenHeight: () => screen.height };
assert.equal(name, '../dashboard-settings');
return settings;
} };
vm.runInNewContext(js(read('app/ui/shell/geometry.ts')), context);
const rect = (mode, appId) => ({ ...context.exports.appViewportRect(mode, appId) });
return { ...context.exports, settings, rect };
return { ...context.exports, settings, screen, rect };
}
const LAYOUTS = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
@@ -263,6 +264,78 @@ test('an immersive app fills the panel without chrome rows, frame or depth, in a
}
});
test('on a RayNeo iO\'s 540x220 screen windows take every row under the bar, beside the strip or over the row', () => {
const g = geometry({ width: 540, height: 220 });
const panel = { x: 0, y: 0, width: 540, height: 220 };
// A band is the whole screen's height, so every band position is the same.
for (const layout of LAYOUTS) {
g.settings.displayLayoutSetting.value = layout;
g.settings.appSwitcherPositionSetting.value = 'left';
assert.equal(g.minWindowHeight(), 220);
assert.equal(g.minWindowTop(), 0);
for (const mode of ['min', 'medium', 'max']) assert.deepEqual(g.rect(mode), { x: 64, y: 28, width: 476, height: 192 }, layout);
assert.deepEqual({ ...g.switcherRect('min') }, { x: 0, y: 0, width: 64, height: 220 });
g.settings.appSwitcherPositionSetting.value = 'right';
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 476, height: 192 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 476, y: 0, width: 64, height: 220 });
}
assert.equal(g.isOnSwitcherEdge(500, 10, 'min'), true);
assert.equal(g.screenCenterInViewportX(), 270);
// A bottom row: the window centred above it, its sides room for the deepest shift.
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.displayLayoutSetting.value = 'band-middle';
assert.deepEqual(g.rect('min'), { x: 32, y: 28, width: 476, height: 156 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 184, width: 476, height: 36 });
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 540, height: 156 });
// The phone mirror shows the whole screen, at its 27:11.
g.settings.displayLayoutSetting.value = 'band-middle';
for (const position of ['left', 'bottom', 'popup']) {
g.settings.appSwitcherPositionSetting.value = position;
assert.deepEqual({ ...g.phonePreviewRect({ ...g.usedScreenRect('min') }) }, panel, position);
}
// Every layout stays on the screen.
g.settings.uiDepthSetting.value = '62';
for (const switcher of ['left', 'right', 'bottom', 'popup']) {
g.settings.appSwitcherPositionSetting.value = switcher;
for (const statusBar of ['top', 'bottom']) {
g.settings.statusBarPositionSetting.value = statusBar;
for (const layout of LAYOUTS) {
g.settings.displayLayoutSetting.value = layout;
for (const mode of ['min', 'medium', 'max']) {
const rect = g.rect(mode), row = g.switcherRect(mode);
const where = `${switcher} ${statusBar} ${layout} ${mode}`;
assert.ok(rect.x >= 0 && rect.y >= 0 && rect.x + rect.width <= 540 && rect.y + rect.height <= 220, where);
assert.ok(row.y >= 0 && row.y + row.height <= 220, where);
if (g.windowFramed()) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 540, where);
}
}
}
}
// The G2's band is unchanged.
assert.equal(geometry().minWindowHeight(), 288);
});
test('on a RayNeo iO the chrome paints the screen\'s size, its strip and row within it', () => {
for (const position of ['left', 'right', 'bottom', 'popup']) {
const g = geometry({ width: 540, height: 220 });
g.settings.appSwitcherPositionSetting.value = position;
const { chrome, state } = chromeLayer(g, { windows: 3, notifications: 2, phoneBattery: 80 });
state.focus = 'sidebar';
const image = chrome.paint();
assert.deepEqual([image.width, image.height], [540, 220], position);
const parts = chrome.paintParts();
assert.ok(parts.length > 0, position);
for (const part of parts) {
assert.ok(part.x >= 0 && part.y >= 0 && part.x + part.image.width <= 540 && part.y + part.image.height <= 220,
`${position} part ${part.shellKey} at ${[part.x, part.y, part.image.width, part.image.height]}`);
}
// And it draws something there.
const lit = (x0, y0, w, h) => { for (let y = y0; y < y0 + h; y++) for (let x = x0; x < x0 + w; x++) if (image.pixels[y * 540 + x]) return true; return false; };
assert.ok(lit(0, 0, 540, 220), position);
}
});
test('the phone mirror zooms to the area the shell uses, centred at the panel\'s 4:3', () => {
const g = geometry();
const preview = (mode, appId) => {
+18 -1
View File
@@ -25,9 +25,10 @@ const fonts = { getDefaultSmallFont: () => font };
const layers = load('app/ui/layers.ts', {
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
});
const menu = load('app/ui/menu.ts', {
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap,
'../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'),
@@ -108,6 +109,22 @@ test('the thin bar fills upward in proportion to brightness in each viewport', (
}
});
test('in a short window (a RayNeo iO\'s) the bar shrinks so the dialog stays inside it', () => {
for (const viewport of [{ x: 64, y: 28, width: 476, height: 192 }, { x: 32, y: 1, width: 476, height: 155 }]) {
const f = fixture('100', viewport);
const image = f.stack.paint().at(-1).image;
// The dialog's border (110) and the full bar (255), all within the window.
let top = Infinity, bottom = -1, fill = 0;
for (let y = 0; y < image.height; y++) for (let x = 0; x < image.width; x++) {
const value = image.getPixel(x, y);
if (value === 110) { top = Math.min(top, y); bottom = Math.max(bottom, y); }
if (value === 255) fill++;
}
assert.ok(top >= viewport.y && bottom < viewport.y + viewport.height, `dialog ${top}..${bottom} in ${JSON.stringify(viewport)}`);
assert.ok(fill > 0 && fill < 12 * 100, 'a shorter bar, still drawn');
}
});
test('system menu hides brightness in Auto and opens its picker between Voice input and Debug', async () => {
const f = fixture('auto');
const { shell } = load('app/ui/shell/shell.ts', {
+14 -7
View File
@@ -65,16 +65,23 @@ test('Full Screen is offered only with a bottom or popup app switcher', () => {
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
});
test('a RayNeo iO pins the band to the top and the switcher to the right, leaving the stored choice alone', () => {
const store = new Map([['display.layout', 'band-middle'], ['display.appSwitcherPosition', 'bottom']]);
test('a RayNeo iO defaults the app switcher to the left, and keeps a chosen position and the band', () => {
const store = new Map();
const api = settingsFixture(store);
assert.equal(api.displayLayoutSetting.get(), 'band-middle');
assert.equal(api.appSwitcherPositionSetting.get(), 'bottom');
api.glassesTypeSetting.set('rayneo-io');
assert.equal(api.displayLayoutSetting.get(), 'band-top');
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
assert.equal(store.get('display.layout'), 'band-middle');
api.glassesTypeSetting.set('g2');
assert.equal(api.appSwitcherPositionSetting.get(), 'left');
assert.equal(api.displayLayoutSetting.get(), 'band-middle');
assert.equal(store.has('display.appSwitcherPosition'), false);
// A stored position is the user's, on either glasses.
api.appSwitcherPositionSetting.set('right');
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
api.glassesTypeSetting.set('g2');
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
store.delete('display.appSwitcherPosition');
assert.equal(api.appSwitcherPositionSetting.get(), 'bottom');
// An unknown stored value falls back to the glasses' default.
store.set('display.appSwitcherPosition', 'sideways');
api.glassesTypeSetting.set('rayneo-io');
assert.equal(api.appSwitcherPositionSetting.get(), 'left');
});
+88
View File
@@ -0,0 +1,88 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
function load(file, modules) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const context = { exports: {}, console, require(name) { assert.ok(name in modules, `${file}: ${name}`); return modules[name]; } };
vm.runInNewContext(ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
return context.exports;
}
const build = (name) => require(`../.test-build/app/${name}.js`);
const graphics = build('graphics/image');
const metrics = build('ui/metrics');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const bdf = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8'));
const font = bdf(14);
const textwrap = load('app/graphics/textwrap.ts', {});
const coreDeps = {
'../graphics/image': graphics, './menu-highlight-motion': build('ui/menu-highlight-motion'),
'../graphics/menu-scroll-list': build('graphics/menu-scroll-list'), './menu-scroll-motion': build('ui/menu-scroll-motion'),
'../graphics/draw-expression': build('graphics/draw-expression'),
};
const menuCore = load('app/ui/menu-core.ts', coreDeps);
const menu = load('app/ui/menu.ts', {
...coreDeps, './menu-animation-pref': build('ui/menu-animation-pref'), './animation-speed': build('ui/animation-speed'),
'../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'../graphics/screen-size': { screenWidth: () => 540, screenHeight: () => 220 },
'../graphics/textwrap': textwrap, '../graphics/ui-fonts': { getDefaultSmallFont: () => font },
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, './gestures': {}, './metrics': metrics, './menu-core': menuCore,
});
// The UI font picker on Roboto Light 20, drawn in Terminus (TTF rendering is native).
const preview = bdf(20);
const picker = load('app/ui/font-picker.ts', {
'../graphics/bdffont': { getFont: () => font }, '../graphics/image': graphics, '../graphics/textwrap': textwrap,
'../graphics/ttf-font': { TtfFont: { load: () => preview } },
'../graphics/installed-fonts': { listInstalledFonts: () => [{ path: '/fonts/Roboto-Light.ttf', fileName: 'Roboto-Light.ttf',
family: 'Roboto', style: 'Light', weightOrder: 300, monospace: false }] },
'../graphics/ui-fonts': { fontSelectionLabel: () => 'Roboto Light 20', getDefaultSmallFont: () => font, uiFontSizeAllowed: () => true,
getTerminalFontSelection: () => null, getUiFontSelection: () => ({ kind: 'ttf', file: 'Roboto-Light.ttf', size: 20 }),
setTerminalFontSelection() {}, setUiFontSelection() {} },
'./gestures': {}, './menu': menu, './menu-core': menuCore, './metrics': metrics,
});
function stackOf(size) {
const layers = [];
return { layers, ctx: { stack: { getBaseSize: () => size, isFocused: () => true, push: (layer) => layers.push(layer) } } };
}
const glyphRuns = (image, f) => image.draws.filter((d) => d.kind === 'glyph' && d.font === f);
test('the font picker previews under its rows where they fit, else beside them, on the window either way', () => {
// At 192 rows either fits, by the font's metrics: only the bounds are checked.
for (const [size, beside] of [[{ width: 576, height: 260 }, false], [{ width: 476, height: 192 }, null], [{ width: 476, height: 155 }, true]]) {
const { layers, ctx } = stackOf(size);
picker.uiFontPickerMenuItem().onSelect(ctx);
const image = layers[0].paint(ctx);
const sample = glyphRuns(image, preview);
// The rows' labels and values (255 selected, 200 not; the title is 220, the info line 110).
const rows = glyphRuns(image, font).filter((d) => d.value === 255 || d.value === 200);
assert.ok(sample.length > 20, `the sample is drawn at ${size.height}`);
for (const d of image.draws) {
if (d.kind !== 'glyph') continue;
assert.ok(d.x >= 0 && d.y >= 0 && d.x + d.glyph.bbxWidth <= size.width && d.y + d.font.lineHeight <= size.height,
`glyph at ${d.x},${d.y} outside ${size.width}x${size.height}`);
}
const rowsRight = Math.max(...rows.map((d) => d.x)), rowsBottom = Math.max(...rows.map((d) => d.y));
if (beside === true) assert.ok(Math.min(...sample.map((d) => d.x)) > rowsRight, 'the sample right of the rows');
if (beside === false) assert.ok(Math.min(...sample.map((d) => d.y)) > rowsBottom, 'the sample under the rows');
}
});
test('a modal menu in a short window (a RayNeo iO\'s) keeps narrow margins, so four choices all show', () => {
const items = ['Left', 'Right', 'Bottom', 'Popup'].map((label) => ({ label, onSelect() {} }));
for (const [size, margin] of [[{ width: 576, height: 260 }, 20], [{ width: 476, height: 155 }, 8]]) {
const { layers, ctx } = stackOf(size);
menu.openModalMenu(ctx, 'App switcher position', items, 0);
const { layout } = layers[0];
assert.ok(layout.y >= margin && layout.y + layout.maxHeight <= size.height - margin, `${size.height}: ${layout.y}+${layout.maxHeight}`);
// Title, body padding (8 above and below) and the four rows.
const natural = metrics.menuTitleHeight(font) + 2 * 8 + items.length * metrics.listRowHeight(font);
assert.equal(layout.maxHeight, natural, `${size.height}: every row fits`);
}
});
+1
View File
@@ -65,6 +65,7 @@ function loadIconGrid({ lastInputWasWatch = false } = {}) {
'./menu-animation-pref': build('ui/menu-animation-pref'),
'./animation-speed': build('ui/animation-speed'),
'../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
});
const grid = load('app/ui/icon-grid.ts', {
...common,
+29
View File
@@ -0,0 +1,29 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const graphics = require('../.test-build/app/graphics/image.js');
// lock-screen.ts on a screen of the given size; the text is not drawn.
function lockScreen(width, height) {
const font = { lineHeight: 20, measureText: (text) => text.length * 10, drawText() {} };
const load = loader({}, {
'../graphics/image': graphics,
'../graphics/screen-size': { screenWidth: () => width, screenHeight: () => height },
'../graphics/ui-fonts': { getDefaultMediumFont: () => font },
'../graphics/textwrap': { wrapText: (_font, text) => [text] },
});
return load('app/g2/lock-screen.ts').createLockScreenImage();
}
// The lock surface is the screen's size, so its frame must be too.
test('the lock screen fills the paired glasses\' screen, its box centred on it', () => {
for (const [width, height] of [[640, 480], [540, 220]]) {
const image = lockScreen(width, height);
assert.deepEqual([image.width, image.height], [width, height]);
const lit = [];
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) if (image.pixels[y * width + x]) lit.push([x, y]);
const xs = lit.map(([x]) => x), ys = lit.map(([, y]) => y);
const box = [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)];
assert.deepEqual(box, [(width - 480) / 2, (height - 150) / 2, (width + 480) / 2 - 1, (height + 150) / 2 - 1], `${width}x${height}`);
}
});
+4 -4
View File
@@ -18,7 +18,7 @@ const menuCore=load('app/ui/menu-core.ts',{
'../graphics/image':graphics,'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
});
const {MenuLayer,TextPageLayer}=load('app/ui/menu.ts',{
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'../graphics/image':graphics,'../graphics/textwrap':{wrapText:(_font,text)=>text.split('\n')},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
'../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{},
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
@@ -50,7 +50,7 @@ test('later opaque planes add an occlusion to a replayed selection',()=>{
});
const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'./gestures':{},
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},'./gestures':{},
});
test('context menu surface and selected row both use +4 without changing the app screen',()=>{
const base=new graphics.GrayImage(100,90,96);
@@ -104,7 +104,7 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
'../../native/notification-icons':{},'../../native/notification-types':require('../.test-build/app/native/notification-types.js'),'../../native/phone-battery':{},'../../util/render-freshness':{},
'../../graphics/icons':{},'../dashboard-settings':{},'../clock-format':{},'../../graphics/bdffont':{},
'../layers':{LayerStack},'../menu':{scrollToKeepSelectionVisible:()=>0},'../metrics':{},
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24,
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowHeight:()=>280,screenWidth:()=>640,screenHeight:()=>480,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24,
SWITCHER_ROW_HEIGHT:36,switcherPosition:()=>'left',switcherRect:()=>({x:0,y:0,width:64,height:280})},
});
const state={selectedIndex:0,focus:'sidebar',windows:[0,1,2].map(n=>({attention:n===1,drawIcon:(image,x,y)=>image.fillRect(x,y,4,4,240)}))};
@@ -122,7 +122,7 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
test('shell modal carries its inner menu highlight animation instead of baking its first frame',async()=>{
const {ShellModalLayer}=load('app/ui/shell/modal-layer.ts',{
'../../graphics/image':graphics,'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},
'./gestures':{isDirectionalInput:()=>false},
}),
'./geometry':{appViewportSize:()=>({width:120,height:110}),appViewportRect:()=>({x:10,y:20,width:120,height:110}),SHELL_OPAQUE_BLACK:1},
+1 -1
View File
@@ -161,7 +161,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics': load('app/ui/metrics.ts'), './gestures': {},
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
};
deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]);
const menu = load('app/ui/menu.ts', (name) => deps[name]);
+1 -1
View File
@@ -87,7 +87,7 @@ function ui(fontSize = 12) {
'../util/render-freshness': { renderPassAllowsStaleData: () => false },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics': load('app/ui/metrics.ts'),
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'./gestures': {},
};
const requireModule = (name) => {
+53 -5
View File
@@ -11,19 +11,22 @@ function setting(value, values) {
writes: [], displayValue: (v) => v[0].toUpperCase() + v.slice(1) };
}
function harness() {
// The onboarding pages over G2 glasses (640x480), or a RayNeo iO's 540x220 screen.
function harness(glasses = 'g2') {
const screen = glasses === 'rayneo-io' ? { width: 540, height: 220 } : { width: 640, height: 480 };
const settings = {
glassesTypeSetting: setting(glasses, ['g2', 'rayneo-io']),
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 },
'../../ui/shell/geometry': { MIN_WINDOW_HEIGHT: 288, SIDEBAR_WIDTH: 64, SWITCHER_ROW_HEIGHT: 36, TOP_BAR_HEIGHT: 28,
screenWidth: () => screen.width, screenHeight: () => screen.height },
});
return { settings, load };
return { settings, screen, load };
}
/** An image that records what is drawn, checking it all lands on the image. */
@@ -111,7 +114,7 @@ test('the text size page offers 12 to 18px, starts on the recommended 16px, and
'./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'),
'../../graphics/ui-fonts': { defaultUiFontSize: () => 16, 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] },
@@ -148,6 +151,51 @@ test('the text size page offers 12 to 18px, starts on the recommended 16px, and
assert.equal(menu.selectedItem, 15);
});
test('on a RayNeo iO the text size page recommends and starts on 14px, its default', () => {
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; } };
let menuOptions;
const load = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../graphics/installed-fonts': { installedFontPath: (file) => `/fonts/${file}` },
'../../graphics/ttf-font': { TtfFont: { load: () => font('detail') } },
'../../graphics/ui-fonts': { defaultUiFontSize: () => 14, fontSelectionLabel: () => 'Terminus', getDefaultSmallFont: () => font('detail'),
getUiFontSelection: () => ({ kind: 'ttf', file: 'Roboto-Light.ttf', size: 14 }), setUiFontSelection: () => assert.fail('nothing to save'),
uiFontSizeAllowed: () => true },
'../../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.equal(menu.selectedItem, 14);
const notes = menu.items.filter((size) => {
const row = recorder(200, 32);
menuOptions.draw({ image: row, item: size, x: 0, y: 0, width: 200, height: 32, selected: false });
return row.calls.some((call) => call.text === 'Recommended');
});
assert.deepEqual(notes, [14]);
// Taking the default leaves the size unset, so it keeps following the glasses.
page.handleInput({ type: 'click' }, { next: () => {} });
});
test('on a RayNeo iO the layout page recommends and starts on Left, and fits the 540x220 screen', () => {
const { load, settings } = harness('rayneo-io');
const { LayoutPage, recommendedLayout } = load('app/apps/onboarding/layout-page.ts');
assert.equal(recommendedLayout(), 'left');
const page = new LayoutPage();
const image = recorder(540, 220);
page.paint(image, true);
const captions = image.calls.filter((call) => call.kind === 'text').map((call) => call.text);
assert.ok(captions.includes('Left (Recommended)'));
assert.ok(captions.includes('Bottom'));
page.handleInput({ type: 'click' }, { next() {} });
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['left']);
// The G2 still recommends Bottom.
assert.equal(harness().load('app/apps/onboarding/layout-page.ts').recommendedLayout(), 'bottom');
});
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; },
+23 -1
View File
@@ -22,7 +22,7 @@ const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/te
const textwrap = load('app/graphics/textwrap.ts', {});
const fonts = { getDefaultSmallFont: () => font };
const menu = load('app/ui/menu.ts', {
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'../graphics/image': graphics, '../graphics/textwrap': textwrap, '../graphics/ui-fonts': fonts,
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, './gestures': {},
'./metrics': metrics, './menu-core': menuCore,
@@ -111,3 +111,25 @@ test('the selected row stays clear of its description band', async () => {
assert.ok(row.y + row.source.height <= bandTop, `row ends at ${row.y + row.source.height}, band starts at ${bandTop}`);
assert.ok(row.y + row.source.height > bandTop - 30, 'the last item scrolled down to just above the band');
});
test('a section\'s detail gives its rows the pane while focus is in them, where the two don\'t fit (a RayNeo iO\'s window)', async () => {
const docs = ['README', 'License', 'Privacy policy', 'Acknowledgements'];
const detailDraws = [];
// About's blurb under its 72px logo: about 145px.
const about = { label: 'About', items: docs.map((label) => ({ label, onSelect() {} })),
renderDetail: ({ image, x, y }) => { detailDraws.push(image); image.fillRect(x, y, 72, 72, 90); return 145; } };
for (const [size, keeps] of [[{ width: 576, height: 260 }, true], [{ width: 476, height: 192 }, false], [{ width: 476, height: 155 }, false]]) {
const layer = new SettingsPanelLayer([about]);
const ctx = { stack: { getBaseSize: () => size, isFocused: () => true } };
const paint = () => { detailDraws.length = 0; const image = layer.paint(ctx); return { image, drawn: detailDraws.includes(image) }; };
// The preview (focus in the left column) always shows the detail.
assert.equal(paint().drawn, true, `preview at ${size.height}`);
await layer.handleInput({ type: 'click', timestampMs: 0 }, ctx);
const { image, drawn } = paint();
assert.equal(drawn, keeps, `focused at ${size.height}`);
const row = selections(image)[1];
if (keeps) assert.ok(row.y >= 8 + 145, 'the rows under the detail');
else assert.equal(row.y, 8, 'the first row at the top of the pane');
assert.ok(row.y + row.source.height <= size.height - 8);
}
});
+45
View File
@@ -0,0 +1,45 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
// ui-fonts.ts and screen-size.ts over an in-memory settings store, with each
// TTF "loaded" as its path and size.
function fixture(entries = []) {
const store = new Map(entries);
const listeners = [];
const load = loader({}, {
'../native/settings-store': {
getStringSetting: (key, fallback) => store.get(key) ?? fallback,
setStringSetting: (key, value) => { store.set(key, value); for (const listener of listeners) listener(key); },
onSettingsStoreChanged: (listener) => listeners.push(listener),
},
'./image': { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480, RAYNEO_IO_WIDTH: 540, RAYNEO_IO_HEIGHT: 220 },
'./bdffont': { getFont: (name) => ({ name }) },
'./ttf-font': { TtfFont: { load: (path, size) => ({ path, size, lineHeight: size + 4 }) } },
'./installed-fonts': { ensurePreinstalledFonts() {}, getInstalledFont: () => null, installedFontPath: (file) => `/fonts/${file}` },
});
return { fonts: load('app/graphics/ui-fonts.ts'), screen: load('app/graphics/screen-size.ts'), store, listeners };
}
test('the screen and the default UI font follow the paired glasses: 640x480 at 16px, or a RayNeo iO\'s 540x220 at 14px', () => {
const { fonts, screen, store, listeners } = fixture();
assert.deepEqual([screen.screenWidth(), screen.screenHeight(), screen.isRayNeoIoConfigured()], [640, 480, false]);
assert.equal(fonts.defaultUiFontSize(), 16);
assert.deepEqual({ ...fonts.getUiFontSelection() }, { kind: 'ttf', file: 'Roboto-Light.ttf', size: 16 });
assert.equal(fonts.getDefaultSmallFont().size, 16);
// Pairing a RayNeo iO: the cached fonts re-resolve at its size.
store.set(screen.GLASSES_TYPE_KEY, 'rayneo-io');
for (const listener of listeners) listener(screen.GLASSES_TYPE_KEY);
assert.deepEqual([screen.screenWidth(), screen.screenHeight(), screen.isRayNeoIoConfigured()], [540, 220, true]);
assert.equal(fonts.defaultUiFontSize(), 14);
assert.deepEqual({ ...fonts.getUiFontSelection() }, { kind: 'ttf', file: 'Roboto-Light.ttf', size: 14 });
assert.equal(fonts.getDefaultSmallFont().size, 14);
});
test('a chosen UI font keeps its size on either glasses', () => {
const { fonts, screen, store } = fixture([['deviceType', 'rayneo-io']]);
fonts.setUiFontSelection({ kind: 'ttf', file: 'Roboto-Light.ttf', size: 17 });
assert.equal(fonts.getUiFontSelection().size, 17);
store.set(screen.GLASSES_TYPE_KEY, 'g2');
assert.equal(fonts.getUiFontSelection().size, 17);
});