Borderless modes have different padding inside the builtin apps

Most of the builtin apps had some padding between the window edge and
their content, because they expect to be displayed with a line border on
their edge. We added a customization option to remove the border, so,
that padding is not always necessary. Make the layouts dynamically
adjust, to omit the padding when it isn't needed.
This commit is contained in:
James Babcock committed 2026-11-11 15:19:29 -08:00
1 parent e158452ba4
commit a02b849200
115 files changed
+3600 -1583

No files matched your search

+23 -12
View File
@@ -13,6 +13,12 @@ import { shell } from "../../ui/shell/shell";
const IMU_REPORT_PACE = 200;
// How often to reconcile the IMU on/off state with window visibility.
const RECONCILE_INTERVAL_MS = 400;
/** The readout under the title sits this far in from the title's left edge. */
const BODY_INDENT = 2;
/** An axis row, from the readout's left edge: its value, then its bar, which stops this short of the right edge's padding. */
const VALUE_OFFSET_X = 22;
const BAR_OFFSET_X = 96;
const BAR_RIGHT_INSET = 4;
/**
* Accelerometer demo: turns the IMU stream on while this page is visible (the
@@ -77,12 +83,17 @@ export class AccelerometerDemoLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const small = getDefaultSmallFont();
const medium = getDefaultMediumFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
// The title line sits at the padding suggested for the top, left and
// right edges; everything under it is placed from there.
const top = padding.top;
const right = width - padding.right;
const bodyX = padding.left + BODY_INDENT;
image.drawText(small, 20, 8, "Accelerometer", 220);
image.drawText(small, padding.left, top, "Accelerometer", 220);
const status = this.enabled ? "IMU on" : "IMU off";
image.drawText(small, width - 20 - small.measureText(status), 8, status, 150);
image.drawText(small, right - small.measureText(status), top, status, 150);
if (this.reading) {
const axes: Array<[string, number]> = [
@@ -90,19 +101,19 @@ export class AccelerometerDemoLayer implements Layer {
["Y", this.reading.y],
["Z", this.reading.z],
];
const barX = 118;
const barW = width - barX - 24;
const barX = bodyX + BAR_OFFSET_X;
const barW = Math.max(0, right - BAR_RIGHT_INSET - barX);
const scale = Math.max(this.peak, 1e-6);
let y = 40;
let y = top + 32;
for (const [label, value] of axes) {
image.drawText(medium, 22, y, label, 210);
image.drawText(medium, 44, y, value.toFixed(3), 235);
image.drawText(medium, bodyX, y, label, 210);
image.drawText(medium, bodyX + VALUE_OFFSET_X, y, value.toFixed(3), 235);
drawCenteredBar(image, barX, y + 2, barW, 12, clamp(value / scale, -1, 1));
y += 30;
}
image.drawText(
small,
22,
bodyX,
y + 6,
`source: ${imuSourceLabel(this.reading.source)} samples: ${this.sampleCount}`,
130,
@@ -111,9 +122,9 @@ export class AccelerometerDemoLayer implements Layer {
const message = this.enabled
? "Waiting for IMU data…"
: "Paused (page not visible).";
image.drawText(small, 22, 44, message, 190);
image.drawText(small, 22, 66, "The firmware may not report the", 120);
image.drawText(small, 22, 82, "accelerometer at all — experimental.", 120);
image.drawText(small, bodyX, top + 36, message, 190);
image.drawText(small, bodyX, top + 58, "The firmware may not report the", 120);
image.drawText(small, bodyX, top + 74, "accelerometer at all — experimental.", 120);
}
return image;
+27 -16
View File
@@ -27,9 +27,12 @@ const POLL_INTERVAL_MS = 500;
// timeout drain + slack).
const POLL_DEADLINE_MS = DURATION_MS + 15_000;
const HEADER_HEIGHT = 30;
const LIST_X = 20;
const VALUE_X = 150;
/** The title band: the rows and the run's text start this far below the top edge's padding. */
const HEADER_HEIGHT = 22;
/** Horizontal inset of a row's text from its highlight box; the title and the text under the rows line up with it. */
const ROW_TEXT_INSET = 6;
/** A row's value column, from its label's left edge. */
const VALUE_OFFSET_X = 130;
type Phase = "config" | "arming" | "running" | "done";
type ConfigRow = "size" | "window" | "link" | "start";
@@ -126,36 +129,43 @@ export class BandwidthBenchmarkLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
// The rows' highlight boxes span the window inside the padding suggested
// for its side edges, and the title sits at the top edge's; the page's
// text shares the rows' text column.
const textX = padding.left + ROW_TEXT_INSET;
const bodyTop = padding.top + HEADER_HEIGHT;
image.drawText(font, 20, 8, "BLE bandwidth", 220);
image.drawText(font, textX, padding.top, "BLE bandwidth", 220);
if (this.phase === "arming" || this.phase === "running") {
image.drawText(font, LIST_X, HEADER_HEIGHT + 8, "Running: streaming no-op packets for 15 s...", 200);
image.drawText(font, textX, bodyTop + 8, "Running: streaming no-op packets for 15 s...", 200);
image.drawText(
font,
LIST_X,
HEADER_HEIGHT + 30,
textX,
bodyTop + 30,
`${MESSAGE_SIZES[this.sizeIndex]} B, window ${WINDOW_SIZES[this.windowIndex]}`
+ (LINK_REQUESTS_SUPPORTED ? `, ${LINK_MODES[this.linkModeIndex]}` : ""),
150,
);
image.drawText(font, LIST_X, HEADER_HEIGHT + 52, "Display updates pause until the run finishes.", 110);
image.drawText(font, textX, bodyTop + 52, "Display updates pause until the run finishes.", 110);
return image;
}
// The rows all fit their box, so it is a fixed block under the title
// rather than a scroller that would run to the window's bottom edge.
const rowH = tightRowHeight(font) + 4;
const rowCount = this.menu.items.length;
this.menu.paint(
image,
{ x: LIST_X - 6, y: HEADER_HEIGHT - 1, width: width - 2 * LIST_X + 12, height: rowCount * rowH },
{ x: padding.left, y: bodyTop - 1, width: Math.max(0, width - padding.left - padding.right), height: rowCount * rowH },
ctx.stack.isFocused(),
);
let y = HEADER_HEIGHT + rowCount * rowH + 10;
let y = bodyTop + rowCount * rowH + 10;
if (this.error) {
image.drawText(font, LIST_X, y, this.error, 180);
image.drawText(font, textX, y, this.error, 180);
} else if (this.result) {
const r = this.result;
const seconds = r.elapsedMs / 1000;
@@ -171,7 +181,9 @@ export class BandwidthBenchmarkLayer implements Layer {
lines.push(`Link request: ${LINK_MODES[r.linkMode] ?? "Current"}${phy}`);
}
for (const line of lines) {
image.drawText(font, LIST_X, y, line, 190);
// A window too short for every line (the RayNeo iO's) shows the first ones.
if (y + font.lineHeight > height) break;
image.drawText(font, textX, y, line, 190);
y += 20;
}
}
@@ -187,10 +199,9 @@ export class BandwidthBenchmarkLayer implements Layer {
: item === "link" ? ["Link request", LINK_MODES[this.linkModeIndex]!]
: [this.phase === "done" ? "Run again" : "Start", ""];
const textY = centeredTextY(font, y, height);
// Text sits 6px in from the row box (LIST_X), values at VALUE_X.
image.drawText(font, x + 6, textY, label, selected ? 255 : 200);
image.drawText(font, x + ROW_TEXT_INSET, textY, label, selected ? 255 : 200);
if (value) {
image.drawText(font, x + 6 + VALUE_X - LIST_X, textY, value, selected ? 235 : 160);
image.drawText(font, x + ROW_TEXT_INSET + VALUE_OFFSET_X, textY, value, selected ? 235 : 160);
}
}
+24 -14
View File
@@ -13,9 +13,12 @@ import {
type SoundEffect,
} from "../../ui/sound-effects";
const HEADER_HEIGHT = 30;
const LIST_X = 20;
const FOOTER_HEIGHT = 0;
/** The title band: the list starts this far below the top edge's padding. */
const HEADER_HEIGHT = 22;
/** Horizontal inset of a row's text from its highlight box; the title lines up with it. */
const ROW_TEXT_INSET = 6;
/** The status text ends this far short of the rows' right edge. */
const STATUS_INSET = 10;
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
@@ -39,19 +42,26 @@ export class BuzzerDemoLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
image.drawText(font, 20, 8, "Buzzer demo", 220);
image.drawText(font, padding.left + ROW_TEXT_INSET, padding.top, "Buzzer demo", 220);
const status = this.playing ? `Playing: ${this.playing}` : `${GESTURE_CLICK} play`;
image.drawText(font, width - 24 - font.measureText(status), 8, status, 140);
image.drawText(font, width - padding.right - STATUS_INSET - font.measureText(status), padding.top, status, 140);
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT;
this.menu.paint(
image,
{ x: LIST_X - 6, y: HEADER_HEIGHT - 1, width: width - 2 * LIST_X + 12, height: listHeight },
ctx.stack.isFocused(),
);
// The title line stays put, so the list starts right under it with no
// padding of its own there. It scrolls, so it runs to the window's
// bottom edge with the padding suggested for that edge inside it, after
// the last row.
const listTop = padding.top + HEADER_HEIGHT - 1;
if (height > listTop) {
this.menu.paint(
image,
{ x: padding.left, y: listTop, width: Math.max(0, width - padding.left - padding.right), height: height - listTop,
padTop: 0, padBottom: padding.bottom },
ctx.stack.isFocused(),
);
}
return image;
}
@@ -104,6 +114,6 @@ export class BuzzerDemoLayer implements Layer {
function drawEffectRow({ image, item: effect, x, y, height, selected }: MenuDrawArgs<SoundEffect>): void {
const font = getDefaultSmallFont();
const textY = centeredTextY(font, y, height);
image.drawText(font, x + 6, textY, effect.name, selected ? 255 : 200);
image.drawText(font, x + 6 + 110, textY, effect.desc, selected ? 180 : 120);
image.drawText(font, x + ROW_TEXT_INSET, textY, effect.name, selected ? 255 : 200);
image.drawText(font, x + ROW_TEXT_INSET + 110, textY, effect.desc, selected ? 180 : 120);
}
+3 -12
View File
@@ -12,7 +12,6 @@ import { RingStatusLayer } from "./ring-status";
import { LoadAppFromQrLayer, LoadAppFromUrlLayer } from "./load-app";
import { unicodeTestMenu } from "./unicode-test";
import { type AppContext } from "../app-definition";
import { appViewportSize } from "../../ui/shell/geometry";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -23,17 +22,9 @@ import {
export const DEVELOPER_WINDOW_ID = "developer";
export const DEVELOPER_SURFACE_ID = "window:developer";
const MENU_LAYOUT = {
x: 8,
y: 8,
width: 272,
showBorder: false,
minHeight: 0,
maxHeight: appViewportSize("min").height - 16,
// These menus are pages, not popups: "Debug tests" replaces the root menu
// visually instead of letting the taller root show through beneath it.
opaque: true,
};
// These menus are pages, not popups: "Debug tests" replaces the root menu
// visually instead of letting the taller root show through beneath it.
const MENU_LAYOUT = { page: true, width: 248 } as const;
type OpenPage = (ctx: Parameters<MenuItem["onSelect"]>[0]) => void;
+36 -15
View File
@@ -6,6 +6,14 @@ import { addInputListener, InputEventLog, inputTimestamp } from "../../ui/input-
import type { Layer, LayerContext } from "../../ui/layers";
import { drawListScrollbar, type MenuItem } from "../../ui/menu";
/** Room the log's rows keep free on the right for the scrollbar, and the bar's own width. */
const SCROLLBAR_GUTTER = 6;
const SCROLLBAR_WIDTH = 3;
/** A row's second (raw report) line is indented this far, and stops as far short of the row's end. */
const DETAIL_INDENT = 12;
/** Gap between the log and the hint line under it. */
const FOOTER_GAP = 6;
/** Gestures are samples here; back/clear/pause live in the tap-then-hold menu. */
export class InputEventsLayer implements Layer {
readonly acceptsDirectional = true;
@@ -48,30 +56,41 @@ export class InputEventsLayer implements Layer {
}
paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const font = getDefaultSmallFont();
image.drawText(font, 12, 8, "Input events", 230);
// The title and column-heading lines stay put at the top and the hint
// line at the bottom, each inside the padding suggested for its edge.
// The log scrolls between them, so it needs no padding of its own.
const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const footerY = height - padding.bottom - font.lineHeight;
const listTop = top + 42;
const listBottom = footerY - FOOTER_GAP;
// The rows stop short of the scrollbar, which keeps inside the padding.
const rowsRight = right - SCROLLBAR_GUTTER;
image.drawText(font, left, top, "Input events", 230);
const status = `${this.log.paused ? "Paused" : "Live"} ${this.log.count} events`;
image.drawText(font, width - 12 - font.measureText(status), 8, status, 180);
image.drawText(font, 12, 28, this.phoneTime ? "Phone receive time | gap ms | source | event" : "Time (R=ring tick) | gap | source | event", 140);
image.drawText(font, right - font.measureText(status), top, status, 180);
image.drawText(font, left, top + 20, this.phoneTime ? "Phone receive time | gap ms | source | event" : "Time (R=ring tick) | gap | source | event", 140);
const lineHeight = Math.max(18, font.lineHeight + 2);
const rowHeight = lineHeight * 2 + 4;
this.visibleRows = Math.max(1, Math.floor((height - 76) / rowHeight));
this.visibleRows = Math.max(1, Math.floor((listBottom - listTop) / rowHeight));
this.scrollRow = Math.min(this.scrollRow, Math.max(0, this.log.entries.length - this.visibleRows));
const timeX = 12;
const timeX = left;
const gapX = timeX + font.measureText("00:00:00.000") + 12;
const sourceX = gapX + font.measureText("+99999") + 12;
const eventX = sourceX + font.measureText("right-arm") + 12;
if (!this.log.entries.length) {
image.drawText(font, 12, 62, "Touch, tap, double-tap, hold, or swipe the ring.", 210);
image.drawText(font, 12, 82, "Press arrives before an interpreted gesture.", 150);
image.drawText(font, left, listTop + 12, "Touch, tap, double-tap, hold, or swipe the ring.", 210);
image.drawText(font, left, listTop + 32, "Press arrives before an interpreted gesture.", 150);
}
for (const [index, entry] of this.log.entries.slice(this.scrollRow, this.scrollRow + this.visibleRows).entries()) {
const { event } = entry;
const ringTime = !this.phoneTime && event.ringInput;
const gapMs = ringTime ? entry.ringGapTicks : entry.gapMs;
const y = 50 + index * rowHeight;
const y = listTop + index * rowHeight;
const gap = gapMs === null ? "-" : `${gapMs >= 0 ? "+" : ""}${gapMs}`;
const source = "source" in event ? event.source ?? "-" : "-";
const label = (entry.filtered ? "*" : "") + (event.type === "unknown"
@@ -80,18 +99,20 @@ export class InputEventsLayer implements Layer {
image.drawText(font, timeX, y, ringTime ? `R${ringTime.tick}` : inputTimestamp(event.timestampMs), 170);
image.drawText(font, gapX, y, truncateText(font, gap, sourceX - gapX - 4), 160);
image.drawText(font, sourceX, y, source, 180);
image.drawText(font, eventX, y, truncateText(font, label, width - eventX - 12), event.type === "ring-press" ? 255 : 200);
image.drawText(font, eventX, y, truncateText(font, label, rowsRight - eventX), event.type === "ring-press" ? 255 : 200);
if (event.ringInput) {
const { type, aux, speed } = event.ringInput;
// These are the original report bytes, not physical distance/speed units.
const details = `Raw ring: type ${type} AUX ${aux} speed ${speed}`;
image.drawText(font, timeX + 12, y + lineHeight,
truncateText(font, details, width - timeX - 36), 170);
image.drawText(font, timeX + DETAIL_INDENT, y + lineHeight,
truncateText(font, details, rowsRight - timeX - 2 * DETAIL_INDENT), 170);
}
}
if (this.log.paused) drawListScrollbar(image, width - 5, 50, height - 78,
this.scrollRow, this.visibleRows, this.log.entries.length);
image.drawText(font, 12, height - 20,
if (this.log.paused && listBottom > listTop) {
drawListScrollbar(image, right - SCROLLBAR_WIDTH, listTop, listBottom - listTop,
this.scrollRow, this.visibleRows, this.log.entries.length);
}
image.drawText(font, left, footerY,
this.log.paused ? "Scroll: history Tap-hold: controls" : "Unfiltered (*=dedup) Tap-hold: controls", 140);
return image;
}
+29 -16
View File
@@ -22,6 +22,10 @@ const RECONCILE_INTERVAL_MS = 400;
// Length of the on-screen trace.
const HISTORY_MS = 30_000;
const MAX_SAMPLES = Math.ceil(HISTORY_MS / 100) + 2;
/** The readout under the title sits this far in from the title's left edge. */
const BODY_INDENT = 2;
/** Gap between the trace's box and the footer line under it. */
const CHART_FOOTER_GAP = 18;
type Sample = { atMs: number; value: number; peak: number };
@@ -102,39 +106,47 @@ export class LightSensorDemoLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const small = getDefaultSmallFont();
const medium = getDefaultMediumFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
// The title line, the trace's box and the footer line sit at the padding
// suggested for the edges they reach; the rest is placed from them.
const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const bodyX = left + BODY_INDENT;
const footerY = height - padding.bottom - small.lineHeight;
image.drawText(small, 20, 8, "Light sensor", 220);
image.drawText(small, left, top, "Light sensor", 220);
const status = this.enabled ? "polling" : "paused";
image.drawText(small, width - 20 - small.measureText(status), 8, status, 150);
image.drawText(small, right - small.measureText(status), top, status, 150);
const report = this.report;
if (!report) {
const message = this.enabled ? "Waiting for a report…" : "Paused (page not visible).";
image.drawText(small, 22, 44, message, 190);
image.drawText(small, 22, 66, "Needs Faceclaw's custom firmware.", 120);
image.drawText(small, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
image.drawText(small, bodyX, top + 36, message, 190);
image.drawText(small, bodyX, top + 58, "Needs Faceclaw's custom firmware.", 120);
image.drawText(small, left, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
// Headline reading. The stock driver's unit is roughly a tenth of a lux.
const lux = (report.alsValue / 10).toFixed(1);
image.drawText(medium, 22, 30, `${lux} lux`, 245);
image.drawText(medium, bodyX, top + 22, `${lux} lux`, 245);
const peakText = `peak ${(report.peak / 10).toFixed(1)}`;
image.drawText(small, 22 + medium.measureText(`${lux} lux`) + 14, 36, peakText, 170);
image.drawText(small, bodyX + medium.measureText(`${lux} lux`) + 14, top + 28, peakText, 170);
const flags: string[] = [];
if (!report.opened) flags.push("sensor closed");
if (report.passive) flags.push("passive");
if (report.autoBrightness) flags.push("auto on");
if (report.passive && !report.readOk) flags.push("read failed");
image.drawText(small, 22, 58, flags.join(" ") || "stock polling", 150);
image.drawText(small, bodyX, top + 50, flags.join(" ") || "stock polling", 150);
const statsY = top + 68;
image.drawText(
small,
22,
76,
bodyX,
statsY,
`brightness ${report.brightness} stock target ${report.stockTarget} gear ${report.gear} scale ${(report.scaleQ10 / 1024).toFixed(2)}`,
170,
);
@@ -142,16 +154,17 @@ export class LightSensorDemoLayer implements Layer {
// 30 s trace of the reading (bright) and the driver's 5-sample peak (dim).
// The axis label sits between the stats line and the chart, so the chart
// starts a full text line lower than the stats.
const chartTop = 76 + small.lineHeight * 2 + 4;
const bounds = { x: 20, y: chartTop, width: width - 40, height: height - chartTop - 34 };
const chartTop = statsY + small.lineHeight * 2 + 4;
const bounds = { x: left, y: chartTop, width: right - left, height: footerY - CHART_FOOTER_GAP - chartTop };
const maxValue = Math.max(...this.samples.map((sample) => Math.max(sample.value, sample.peak)), 10);
const scale = roundUpScale(maxValue * 1.08);
image.drawText(small, bounds.x, bounds.y - small.lineHeight - 2, `0–${(scale / 10).toFixed(0)} lux, last 30 s`, 120);
drawTrace(image, this.samples, Date.now(), bounds, scale);
// A window too short for the trace (a large font on the RayNeo iO) goes without.
if (bounds.width > 1 && bounds.height > 1) drawTrace(image, this.samples, Date.now(), bounds, scale);
image.drawText(small, 20, height - 16, `reports: ${this.reportCount}`, 110);
image.drawText(small, left, footerY, `reports: ${this.reportCount}`, 110);
const back = `${GESTURE_DOUBLE_CLICK} back`;
image.drawText(small, width - 20 - small.measureText(back), height - 16, back, 110);
image.drawText(small, right - small.measureText(back), footerY, back, 110);
return image;
}
+21 -17
View File
@@ -9,8 +9,6 @@ import { lineStep } from "../../ui/metrics";
import { developerAppUrlSetting } from "../../ui/dashboard-settings";
import { cancelQrScan, isQrScannerAvailable, scanQrCode } from "../../native/qr-scan";
const MARGIN = 20;
/**
* "Load app from URL": the glasses side of the phone text editor. Entering the
* page opens the editor on developerAppUrlSetting, the typed URL echoes here
@@ -44,27 +42,30 @@ export class LoadAppFromUrlLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
// The page's text fills the window inside the padding suggested for its
// edges: the title at the top, the hint line at the bottom.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const step = lineStep(font);
const textWidth = width - 2 * MARGIN;
const left = padding.left;
const textWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, MARGIN, 8, "Load app from URL", 220);
let y = 8 + step + 6;
image.drawText(font, MARGIN, y, "Type the app's URL in the phone app", 150);
image.drawText(font, left, padding.top, "Load app from URL", 220);
let y = padding.top + step + 6;
image.drawText(font, left, y, "Type the app's URL in the phone app", 150);
y += step;
image.drawText(font, MARGIN, y, "(or use voice input from the menu).", 150);
image.drawText(font, left, y, "(or use voice input from the menu).", 150);
y += step + 8;
const url = developerAppUrlSetting.get();
for (const line of wrapText(font, url || "(empty)", textWidth).slice(0, 3)) {
image.drawText(font, MARGIN, y, line, url ? 230 : 110);
image.drawText(font, left, y, line, url ? 230 : 110);
y += step;
}
if (this.error) {
y += 4;
for (const line of wrapText(font, this.error, textWidth).slice(0, 2)) {
image.drawText(font, MARGIN, y, line, 150);
image.drawText(font, left, y, line, 150);
y += step;
}
}
@@ -72,7 +73,7 @@ export class LoadAppFromUrlLayer implements Layer {
const footer = this.launching
? "Loading..."
: `${GESTURE_CLICK} load ${GESTURE_DOUBLE_CLICK} cancel`;
image.drawText(font, MARGIN, height - font.lineHeight - 12, footer, 110);
image.drawText(font, left, height - padding.bottom - font.lineHeight, footer, 110);
return image;
}
@@ -145,19 +146,22 @@ export class LoadAppFromQrLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
// Laid out like the URL page: text inside the padding suggested for the
// window's edges, the hint line at the bottom.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const step = lineStep(font);
const left = padding.left;
image.drawText(font, MARGIN, 8, "Load app from QR code", 220);
let y = 8 + step + 6;
for (const line of wrapText(font, this.status, width - 2 * MARGIN).slice(0, 5)) {
image.drawText(font, MARGIN, y, line, 170);
image.drawText(font, left, padding.top, "Load app from QR code", 220);
let y = padding.top + step + 6;
for (const line of wrapText(font, this.status, Math.max(0, width - padding.left - padding.right)).slice(0, 5)) {
image.drawText(font, left, y, line, 170);
y += step;
}
const footer = this.busy ? `${GESTURE_DOUBLE_CLICK} back` : `${GESTURE_CLICK} scan again ${GESTURE_DOUBLE_CLICK} back`;
image.drawText(font, MARGIN, height - font.lineHeight - 12, footer, 110);
image.drawText(font, left, height - padding.bottom - font.lineHeight, footer, 110);
return image;
}
+24 -16
View File
@@ -37,6 +37,8 @@ const STOCK_COUNTER_OFFSET = 204;
// Counter gaps at or beyond this are late/duplicate copies, not losses.
const STOCK_LATE_GAP = 128;
const LEVEL_FLOOR_DB = -90;
/** Gap between the two temples' columns. */
const COLUMN_GAP = 16;
// wallMs (JS receipt time) windows the rates; arrivalMs (the session core's
// elapsed-realtime stamp, taken on the BLE thread) measures gaps without the
@@ -229,39 +231,45 @@ export class MicrophonesMonitorLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const line = font.lineHeight;
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const nowMs = Date.now();
// The title line, the two columns and the footer line span the window
// inside the padding suggested for its edges.
const left = padding.left;
const titleY = padding.top;
const right = width - padding.right;
const footerY = height - padding.bottom - line;
image.drawText(font, 16, 5, "Microphones (passive)", 230);
image.drawText(font, left, titleY, "Microphones (passive)", 230);
const capture = isFaceclawAudioCaptureActive() ? "Faceclaw capture: on" : "Faceclaw capture: off";
image.drawText(font, width - 16 - font.measureText(capture), 5, capture, 170);
image.drawText(font, right - font.measureText(capture), titleY, capture, 170);
if (!this.communicator) {
image.drawText(font, 16, 5 + line * 2, "Glasses not connected.", 190);
image.drawText(font, 16, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
image.drawText(font, left, titleY + line * 2, "Glasses not connected.", 190);
image.drawText(font, left, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
const gutter = 16;
const columnWidth = Math.floor((width - gutter * 3) / 2);
const columnWidth = Math.max(0, Math.floor((right - left - COLUMN_GAP) / 2));
const rightColumnX = left + columnWidth + COLUMN_GAP;
const stripHeight = 22;
const top = 5 + line + 6;
const bottom = height - 16 - stripHeight - 8;
this.paintArm(image, "L", "Left", gutter, top, columnWidth, bottom, nowMs);
this.paintArm(image, "R", "Right", gutter * 2 + columnWidth, top, columnWidth, bottom, nowMs);
const top = titleY + line + 6;
const bottom = footerY - stripHeight - 8;
this.paintArm(image, "L", "Left", left, top, columnWidth, bottom, nowMs);
this.paintArm(image, "R", "Right", rightColumnX, top, columnWidth, bottom, nowMs);
const stripY = height - 16 - stripHeight - 4;
const stripY = footerY - stripHeight - 4;
const stripMax = Math.max(1, ...this.stats.L.buckets, ...this.stats.R.buckets);
drawStrip(image, this.stats.L.buckets, gutter, stripY, columnWidth, stripHeight, stripMax);
drawStrip(image, this.stats.R.buckets, gutter * 2 + columnWidth, stripY, columnWidth, stripHeight, stripMax);
drawStrip(image, this.stats.L.buckets, left, stripY, columnWidth, stripHeight, stripMax);
drawStrip(image, this.stats.R.buckets, rightColumnX, stripY, columnWidth, stripHeight, stripMax);
const footer = this.unknownArmPackets > 0
? `last ${HISTORY_MS / 1000} s unattributed packets ${this.unknownArmPackets}`
: `packets per ${BUCKET_MS} ms, last ${HISTORY_MS / 1000} s`;
image.drawText(font, gutter, height - 16, footer, 110);
image.drawText(font, left, footerY, footer, 110);
const back = `${GESTURE_DOUBLE_CLICK} back tap reset`;
image.drawText(font, width - gutter - font.measureText(back), height - 16, back, 110);
image.drawText(font, right - font.measureText(back), footerY, back, 110);
return image;
}
+46 -21
View File
@@ -16,6 +16,14 @@ const HISTORY_MS = 60_000;
const MAX_SAMPLES = Math.ceil(HISTORY_MS / SAMPLE_INTERVAL_MS) + 2;
/** Line brightness per memory series, headline first. */
const MEMORY_SHADES = [240, 155, 80];
/** The charts' heights where the window has room for them. */
const MEMORY_CHART_HEIGHT = 70;
const CPU_CHART_HEIGHT = 60;
/** Between the charts: a gap, then the CPU chart's label line. */
const CHART_GAP = 10;
const CHART_LABEL_HEIGHT = 16;
/** Least gap between the CPU chart and the footer line. */
const CHART_FOOTER_GAP = 4;
type ChartSample = ResourceSample & { cpuPercent: number };
@@ -56,20 +64,26 @@ export class ResourceUsageLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const latest = this.samples[this.samples.length - 1];
// The title line, the charts and the footer line span the window inside
// the padding suggested for its edges; the rest is placed from the top.
const left = padding.left;
const top = padding.top;
const right = width - padding.right;
const footerY = height - padding.bottom - font.lineHeight;
image.drawText(font, 16, 5, "Resource usage — last minute", 230);
image.drawText(font, left, top, "Resource usage — last minute", 230);
if (!latest) {
image.drawText(font, 16, 30, this.sampleError || "Waiting for first sample…", 170);
image.drawText(font, 16, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
image.drawText(font, left, top + 25, this.sampleError || "Waiting for first sample…", 170);
image.drawText(font, left, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
const cpuText = `CPU ${formatPercent(latest.cpuPercent)} ${latest.threads} threads`;
image.drawText(font, width - 16 - font.measureText(cpuText), 5, cpuText, 200);
image.drawText(font, 16, 21, this.sampleError || latest.status, this.sampleError ? 170 : 140);
image.drawText(font, right - font.measureText(cpuText), top, cpuText, 200);
image.drawText(font, left, top + 16, this.sampleError || latest.status, this.sampleError ? 170 : 140);
const memorySeries = MEMORY_SERIES.map((label, index) => ({
label,
@@ -78,34 +92,44 @@ export class ResourceUsageLayer implements Layer {
}));
const memoryPeak = Math.max(...this.samples.flatMap((sample) => sample.memoryMb), 64);
const memoryScale = roundUp(memoryPeak * 1.08, 64);
const legendY = top + 43;
const legendLeft = drawLegend(
image,
font,
width,
48,
right,
legendY,
memorySeries.map((series) => [`${series.label} ${formatMb(series.value(latest))}`, series.shade] as const),
);
const scaleLabel = `Memory 0–${formatMb(memoryScale)}`;
const shortScaleLabel = `0–${formatMb(memoryScale)}`;
image.drawText(
font,
16,
48,
16 + font.measureText(scaleLabel) + 8 <= legendLeft ? scaleLabel : shortScaleLabel,
left,
legendY,
left + font.measureText(scaleLabel) + 8 <= legendLeft ? scaleLabel : shortScaleLabel,
140,
);
drawChart(image, this.samples, latest.atMs, { x: 16, y: 64, width: width - 32, height: 70 }, memoryScale, memorySeries);
// The charts shrink together where the window is too short for both
// above the footer line (the RayNeo iO's).
const chartsTop = legendY + CHART_LABEL_HEIGHT;
const room = footerY - CHART_FOOTER_GAP - chartsTop - CHART_GAP - CHART_LABEL_HEIGHT;
const fit = clamp(room / (MEMORY_CHART_HEIGHT + CPU_CHART_HEIGHT), 0, 1);
const memoryHeight = Math.floor(MEMORY_CHART_HEIGHT * fit);
const chartWidth = Math.max(0, right - left);
drawChart(image, this.samples, latest.atMs, { x: left, y: chartsTop, width: chartWidth, height: memoryHeight }, memoryScale, memorySeries);
const cpuPeak = Math.max(...this.samples.map((sample) => sample.cpuPercent), 100);
const cpuScale = roundUp(cpuPeak * 1.08, 25);
image.drawText(font, 16, 144, `CPU 0–${Math.round(cpuScale)}% (one core)`, 140);
drawChart(image, this.samples, latest.atMs, { x: 16, y: 160, width: width - 32, height: 60 }, cpuScale, [
{ value: (sample) => sample.cpuPercent, shade: 220 },
]);
const cpuLabelY = chartsTop + memoryHeight + CHART_GAP;
image.drawText(font, left, cpuLabelY, `CPU 0–${Math.round(cpuScale)}% (one core)`, 140);
drawChart(image, this.samples, latest.atMs,
{ x: left, y: cpuLabelY + CHART_LABEL_HEIGHT, width: chartWidth, height: Math.floor(CPU_CHART_HEIGHT * fit) }, cpuScale, [
{ value: (sample) => sample.cpuPercent, shade: 220 },
]);
image.drawText(font, 16, height - 16, `-60s`, 80);
image.drawText(font, left, footerY, `-60s`, 80);
const nowLabel = `now`;
image.drawText(font, width - 16 - font.measureText(nowLabel), height - 16, nowLabel, 110);
image.drawText(font, right - font.measureText(nowLabel), footerY, nowLabel, 110);
return image;
}
@@ -148,6 +172,7 @@ function drawChart(
scale: number,
series: readonly Series[],
): void {
if (bounds.width < 2 || bounds.height < 2) return;
image.drawRect(bounds.x, bounds.y, bounds.width, bounds.height, 45);
const midY = bounds.y + Math.round((bounds.height - 1) / 2);
image.drawLine(bounds.x + 1, midY, bounds.x + bounds.width - 2, midY, 24);
@@ -167,16 +192,16 @@ function drawChart(
}
}
/** Right-aligned legend of line swatches and labels; returns its left edge. */
/** Legend of line swatches and labels, right-aligned to end at `right`; returns its left edge. */
function drawLegend(
image: GrayImage,
font: ReturnType<typeof getDefaultSmallFont>,
width: number,
right: number,
y: number,
entries: ReadonlyArray<readonly [string, number]>,
): number {
const totalWidth = entries.reduce((sum, [label]) => sum + font.measureText(label) + 14, 0);
const left = width - 16 - totalWidth;
const left = right - totalWidth;
let x = left;
for (const [label, shade] of entries) {
image.drawLine(x, y + 6, x + 8, y + 6, shade);
+17 -10
View File
@@ -18,8 +18,10 @@ import {
} from "../../native/ring-status";
const POLL_INTERVAL_MS = 1_000;
const LEFT_X = 16;
const VALUE_X = 130;
/** The title sits this far in from the left edge of the rows and buttons under it. */
const TITLE_INDENT = 2;
/** A row's value column, from its label's left edge. */
const VALUE_OFFSET_X = 114;
const BUTTON_GAP = 8;
type Row = { label: string; value: string; dim?: boolean };
@@ -102,26 +104,31 @@ export class RingStatusLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const lineStep = font.lineHeight + 2;
const buttonHeight = font.lineHeight + 8;
const buttonTop = height - buttonHeight - 6;
// The rows and the button strip span the window inside the padding
// suggested for its side edges; the title sits at the top edge's and the
// buttons' outlines at the bottom edge's.
const left = padding.left;
const buttonTop = height - padding.bottom - buttonHeight;
image.drawText(font, 18, 10, "Ring status", 230);
let y = 10 + lineStep + 4;
image.drawText(font, left + TITLE_INDENT, padding.top, "Ring status", 230);
let y = padding.top + lineStep + 4;
const rows = this.rows();
if (this.notice) rows.push({ label: "", value: this.notice });
for (const row of rows) {
if (y + font.lineHeight > buttonTop - 4) break;
image.drawText(font, LEFT_X, y, row.label, row.dim ? 100 : 150);
image.drawText(font, VALUE_X, y, row.value, row.dim ? 120 : 220);
image.drawText(font, left, y, row.label, row.dim ? 100 : 150);
image.drawText(font, left + VALUE_OFFSET_X, y, row.value, row.dim ? 120 : 220);
y += lineStep;
}
const buttonWidth = Math.floor((width - 2 * LEFT_X - BUTTON_GAP * (BUTTONS.length - 1)) / BUTTONS.length);
const buttonWidth = Math.max(0,
Math.floor((width - padding.left - padding.right - BUTTON_GAP * (BUTTONS.length - 1)) / BUTTONS.length));
BUTTONS.forEach((button, index) => {
const x = LEFT_X + index * (buttonWidth + BUTTON_GAP);
const x = left + index * (buttonWidth + BUTTON_GAP);
const selected = index === this.selected;
if (selected) image.fillRoundedRect(x, buttonTop, buttonWidth, buttonHeight, 40, 4);
image.drawRoundedRect(x, buttonTop, buttonWidth, buttonHeight, selected ? 200 : 70, 4);
+15 -14
View File
@@ -3,7 +3,7 @@ import { fontSelectionLabel, getDefaultSmallFont, getUiFontSelection } from "../
import { GrayImage, type UiFont } from "../../graphics/image";
import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
import { MenuLayer, type MenuLayout } from "../../ui/menu";
import { MenuLayer, type MenuPageLayout } from "../../ui/menu";
/**
* Unicode test: sample texts chosen to exercise text-rendering features that
@@ -175,9 +175,6 @@ export const UNICODE_SAMPLES: readonly UnicodeSample[] = [
},
];
const MARGIN_X = 18;
const TITLE_Y = 8;
const FOOTER_MARGIN = 20;
const BODY_GAP = 6;
/**
@@ -196,32 +193,36 @@ export class UnicodeSampleLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
// The title and note stay put at the top and the footer line at the
// bottom, inside the padding suggested for the window's edges; the text
// pages between them, so it needs no padding of its own.
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const textWidth = width - 2 * MARGIN_X;
const left = padding.left;
const textWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, MARGIN_X, TITLE_Y, truncateText(font, this.sample.label, textWidth), 220);
const noteY = TITLE_Y + font.lineHeight;
image.drawText(font, left, padding.top, truncateText(font, this.sample.label, textWidth), 220);
const noteY = padding.top + font.lineHeight;
const noteLines = wrapText(font, this.sample.exercises, textWidth);
for (let i = 0; i < noteLines.length; i++) {
image.drawText(font, MARGIN_X, noteY + i * font.lineHeight, noteLines[i]!, 120);
image.drawText(font, left, noteY + i * font.lineHeight, noteLines[i]!, 120);
}
const bodyY = noteY + noteLines.length * font.lineHeight + BODY_GAP;
const footerY = height - FOOTER_MARGIN;
const footerY = height - padding.bottom - font.lineHeight;
this.bodyLineCount = Math.max(1, Math.floor((footerY - bodyY) / font.lineHeight));
const lines = this.getLines(font, textWidth);
this.clampScroll(lines.length);
const visible = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount);
for (let i = 0; i < visible.length; i++) {
image.drawText(font, MARGIN_X, bodyY + i * font.lineHeight, visible[i]!, 235);
image.drawText(font, left, bodyY + i * font.lineHeight, visible[i]!, 235);
}
const page = Math.floor(this.firstLine / this.pageStep()) + 1;
image.drawText(font, MARGIN_X, footerY, `Page ${page}/${this.pageCount(lines.length)}`, 110);
image.drawText(font, left, footerY, `Page ${page}/${this.pageCount(lines.length)}`, 110);
const fontLabel = fontSelectionLabel(getUiFontSelection());
image.drawText(font, width - MARGIN_X - font.measureText(fontLabel), footerY, fontLabel, 110);
image.drawText(font, width - padding.right - font.measureText(fontLabel), footerY, fontLabel, 110);
return image;
}
@@ -271,7 +272,7 @@ export class UnicodeSampleLayer implements Layer {
}
/** The language list; selecting a row opens its sample. */
export function unicodeTestMenu(layout: MenuLayout): MenuLayer {
export function unicodeTestMenu(layout: MenuPageLayout): MenuLayer {
return new MenuLayer(
"Unicode test",
UNICODE_SAMPLES.map((sample) => ({