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

+38 -2
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
function load(file, deps, globals = {}) {
const exports = {};
@@ -256,6 +257,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
const timings = { spanCurrent: (_, fn) => fn(), span: (_, __, fn) => fn(), spanAsync: (_, __, fn) => fn(),
startFrame: () => 0, annotateFrame() {}, finishFrame() {}, runWithFrame: (_, fn) => fn() };
const layers = load('app/ui/layers.ts', {
'./viewport': require('../.test-build/app/ui/viewport.js'),
'../graphics/image': images, '../graphics/plane': { dimPlanes: (planes) => planes },
'../native/frame-timings': timings, './gestures': gestures,
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
@@ -295,7 +297,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../../graphics/image': images, '../../native/frame-timings': timings,
'../../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false },
'../layers': layers, '../window-menu': { WindowMenuLayer: Menu },
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewportSize: () => ({ width: 576, height: 260 }), setAppImmersive: () => false },
'./chrome-layer': { windowIcon: () => () => null }, './geometry': { appViewport: () => ({ width: 576, height: 260 }), setAppImmersive: () => false },
'./shell': { shell },
});
const input = [], menus = [];
@@ -399,7 +401,9 @@ function chatLayerEnv() {
});
createAiChatWindow({ actions: {}, setSurfaceVisible() {}, onClosed() {} });
const layer = windowOptions.baseLayer;
return { ...env, layer, paint: (width = 576, height = 260) => layer.paint({ stack: { getBaseSize: () => ({ width, height }) } }) };
// A framed window (8px of padding all round) unless a viewport says otherwise.
return { ...env, layer, paint: (width = 576, height = 260, viewport = bordered(width, height)) =>
layer.paint({ stack: { getBaseSize: () => viewport } }) };
}
test('scrollback stays anchored during streaming, follows at the bottom and resets on session switch', () => {
@@ -441,3 +445,35 @@ test('chat paints at both window heights with pending speech pinned beneath hist
}
}
});
test('chat keeps inside the padding of the edges a border runs along, and uses the room where there is none', () => {
const env = chatLayerEnv();
const session = env.store.ensureSession();
for (let i = 0; i < 30; i++) session.transcript.push({ role: i % 2 ? 'assistant' : 'user', text: `Message ${i}: sample conversation text.` });
// The rows and columns holding any ink, text included.
const inkBounds = (image) => {
const baked = image.withDrawsBaked();
const bounds = { left: Infinity, top: Infinity, right: -1, bottom: -1 };
for (let y = 0; y < baked.height; y++) for (let x = 0; x < baked.width; x++) {
if (!baked.getPixel(x, y)) continue;
bounds.left = Math.min(bounds.left, x); bounds.right = Math.max(bounds.right, x);
bounds.top = Math.min(bounds.top, y); bounds.bottom = Math.max(bounds.bottom, y);
}
return bounds;
};
for (const viewport of [
bordered(576, 260), unbordered(576, 260), edged(576, 260, 'top', 'left'), edged(576, 452, 'bottom', 'right'),
bordered(476, 155), unbordered(476, 155), edged(640, 480, 'bottom'),
]) {
const { width, height, padding } = viewport;
const where = JSON.stringify(viewport);
const ink = inkBounds(env.paint(width, height, viewport));
assert.ok(env.layer.maxFirstLine > 0, where);
// The footer's rule starts right at the left padding and the scrollbar hugs the right.
assert.equal(ink.left, padding.left, where);
assert.equal(ink.right, width - padding.right - 1, where);
// The title's line starts at the top padding and the footer's last line ends at the bottom.
assert.ok(ink.top >= padding.top && ink.top < padding.top + 12, where);
assert.ok(ink.bottom < height - padding.bottom && ink.bottom >= height - padding.bottom - 12, where);
}
});
+119 -14
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged, sameViewport } = require('./helpers/viewport.cjs');
const read = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
@@ -18,6 +19,7 @@ function geometry(screen = { width: 640, height: 480 }) {
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
const context = { exports: {}, require: (name) => {
if (name === '../../graphics/screen-size') return { screenWidth: () => screen.width, screenHeight: () => screen.height };
if (name === '../viewport') return require('../.test-build/app/ui/viewport.js');
assert.equal(name, '../dashboard-settings');
return settings;
} };
@@ -346,6 +348,96 @@ test('on a RayNeo iO the chrome paints the screen\'s size, its strip and row wit
}
});
test('each window edge is labelled by whether a border line runs along it, with padding only there', () => {
const g = geometry();
// top, right, bottom, left: B = a border line right outside it, o = nothing.
const edges = (appId) => {
const e = g.windowEdges(appId);
return [e.top, e.right, e.bottom, e.left].map((kind) => (kind === 'border' ? 'B' : 'o')).join('');
};
const set = (switcher, statusBar = 'top', border = 'all', visibility = 'always') => {
g.settings.appSwitcherPositionSetting.value = switcher;
g.settings.statusBarPositionSetting.value = statusBar;
g.settings.windowBorderSetting.value = border;
g.settings.statusBarVisibilitySetting.value = visibility;
};
// A side strip: the top bar's divider and the strip's separator; the
// other side and the bottom are the screen's edge or blank. The Border
// setting doesn't reach it.
set('left');
assert.equal(edges(), 'BooB');
set('right', 'top', 'none');
assert.equal(edges(), 'BBoo');
// A bottom row: the frame all round; with only the status line, the edge
// the status bar is past; with no border, nothing.
set('bottom');
assert.equal(edges(), 'BBBB');
set('bottom', 'bottom');
assert.equal(edges(), 'BBBB');
set('bottom', 'top', 'status');
assert.equal(edges(), 'Booo');
set('bottom', 'bottom', 'status');
assert.equal(edges(), 'ooBo');
set('bottom', 'top', 'none');
assert.equal(edges(), 'oooo');
set('bottom', 'bottom', 'none');
assert.equal(edges(), 'oooo');
// A popup: the frame, or the line by a status bar with rows of its own
// (one that only overlays has none).
set('popup');
assert.equal(edges(), 'BBBB');
set('popup', 'bottom', 'status');
assert.equal(edges(), 'ooBo');
set('popup', 'top', 'status');
assert.equal(edges(), 'Booo');
set('popup', 'top', 'status', 'switcher');
assert.equal(edges(), 'oooo');
set('popup', 'top', 'all', 'switcher');
assert.equal(edges(), 'BBBB');
set('popup', 'top', 'none');
assert.equal(edges(), 'oooo');
// Full Screen has no room for the frame's sides: the status bar's divider
// and the switcher row's separator are the lines left.
g.settings.displayLayoutSetting.value = 'fullscreen';
set('bottom');
assert.equal(edges(), 'BoBo');
set('bottom', 'bottom');
assert.equal(edges(), 'ooBo');
set('bottom', 'top', 'status');
assert.equal(edges(), 'Booo');
set('popup');
assert.equal(edges(), 'Booo');
set('popup', 'bottom');
assert.equal(edges(), 'ooBo');
// An immersive window has the whole panel.
g.settings.displayLayoutSetting.value = 'band-middle';
set('bottom');
g.setAppImmersive('onboarding', true);
assert.equal(edges('onboarding'), 'oooo');
assert.equal(edges('launcher'), 'BBBB');
set('left');
assert.equal(edges('onboarding'), 'oooo');
g.setAppImmersive('onboarding', false);
// The viewport a window lays out in carries the labels and the padding
// suggested for them: 8px beside a line, none beside blank space.
const plain = (value) => JSON.parse(JSON.stringify(value));
set('left');
assert.deepEqual(plain(g.appViewport('min')), {
width: 576, height: 260,
edges: { top: 'border', right: 'offscreen', bottom: 'offscreen', left: 'border' },
padding: { top: 8, right: 0, bottom: 0, left: 8 },
});
set('bottom', 'bottom', 'none');
assert.deepEqual(plain(g.appViewport('min').padding), { top: 0, right: 0, bottom: 0, left: 0 });
set('bottom', 'bottom');
assert.deepEqual(plain(g.appViewport('min').padding), { top: 8, right: 8, bottom: 8, left: 8 });
for (const mode of ['min', 'medium', 'max']) {
const { width, height } = g.appViewport(mode, 'terminal');
assert.deepEqual({ width, height }, { ...g.appViewportSize(mode, 'terminal') });
}
});
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) => {
@@ -1053,33 +1145,42 @@ test('with the selection out on a notification, the windows stay scrolled as the
});
// Exercise the real worker message handler with platform work stubbed out.
function resizeHandler(file, globals) {
// `own` names the worker's own functions and constants the handler runs with.
function resizeHandler(file, globals, own = []) {
const source = ts.createSourceFile(file, read(file), ts.ScriptTarget.Latest, true);
const handler = source.statements.find((s) => ts.isExpressionStatement(s)
&& ts.isBinaryExpression(s.expression) && s.expression.left.getText(source) === 'global.onmessage');
assert.ok(handler);
const named = source.statements.filter((s) => ts.isFunctionDeclaration(s) && own.includes(s.name?.text)
|| ts.isVariableStatement(s) && s.declarationList.declarations.some((d) => own.includes(d.name.getText(source))));
assert.equal(named.length, own.length);
const context = { global: {}, ...globals };
vm.runInNewContext(js(handler.getText(source)), context);
vm.runInNewContext(js([...named, handler].map((s) => s.getText(source)).join('\n')), context);
return (viewport) => context.global.onmessage({ data: { type: 'resize-window', windowId: 'test', viewport } });
}
test('Navigate resize preserves its active route and window, and remeasures an open menu', () => {
let paints = 0;
let menuSize;
const window = { windowId: 'test', viewportWidth: 640, viewportHeight: 452,
const window = { windowId: 'test', viewportWidth: 640, viewportHeight: 452, viewport: bordered(640, 452),
menu: { resize: (size) => { menuSize = size; } }, lastSubmittedFingerprint: 'old' };
const route = { destination: 'Home' };
const resize = resizeHandler('app/apps/navigate/navigate-app.worker.ts', {
window, route, phase: 'navigating', render: () => { paints++; },
window, route, phase: 'navigating', render: () => { paints++; }, sameViewport,
});
resize({ width: 576, height: 260 });
resize(bordered(576, 260));
assert.equal(window.viewportHeight, 260);
assert.equal(window.viewportWidth, 576);
assert.deepEqual(window.viewport, bordered(576, 260));
assert.equal(window.lastSubmittedFingerprint, '');
assert.equal(route.destination, 'Home');
assert.deepEqual(menuSize, { width: 576, height: 260 });
resize({ width: 576, height: 260 });
assert.deepEqual(menuSize, bordered(576, 260));
resize(bordered(576, 260));
assert.equal(paints, 1);
// What the edges touch changing is a new layout too, at the same size.
resize(edged(576, 260, 'top'));
assert.equal(paints, 2);
assert.deepEqual(menuSize, edged(576, 260, 'top'));
});
test('Terminal resize keeps the view identity, negotiates its grid and skips position-only changes', () => {
@@ -1123,13 +1224,17 @@ test('the games and Roam resize in place, keeping their state, and repaint when
}
let paints = 0, viewSize;
const window = { windowId: 'test', viewportWidth: 576, viewportHeight: 443, menu: null, lastSubmittedFingerprint: 'old',
view: { resize: (...size) => { viewSize = size; } } };
const resize = resizeHandler('app/apps/roam/roam-app.worker.ts', {
window, render: () => paints++, DOC_MARGIN: 6, HEADER_HEIGHT: 30, BOTTOM_MARGIN: 6,
});
resize({ width: 576, height: 415 });
// The document re-wraps for the region under its header.
assert.deepEqual([window.viewportHeight, viewSize, window.lastSubmittedFingerprint, paints], [415, [564, 379], '', 1]);
view: { resize: (size) => { viewSize = { ...size }; } } };
const resize = resizeHandler('app/apps/roam/roam-app.worker.ts', { window, render: () => paints++ },
['HEADER_HEIGHT', 'headerBottom', 'documentBox']);
resize(bordered(576, 415));
// The document re-wraps for the region under its header: between the side
// padding and down to the window's bottom edge, whose padding goes inside it.
assert.deepEqual([window.viewportHeight, viewSize, window.lastSubmittedFingerprint, paints],
[415, { x: 8, y: 32, width: 560, height: 383, padBottom: 8 }, '', 1]);
assert.deepEqual(window.viewport, bordered(576, 415));
resize(unbordered(576, 415));
assert.deepEqual(viewSize, { x: 0, y: 24, width: 576, height: 391, padBottom: 0 });
});
test('resizing a terminal reconnects with the new grid and ignores callbacks from the old socket', () => {
+1
View File
@@ -23,6 +23,7 @@ const { BdfFont } = load('app/graphics/bdffont.ts');
const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/terminus/ter-u18n.bdf'), 'utf8'));
const fonts = { getDefaultSmallFont: () => font };
const layers = load('app/ui/layers.ts', {
'./viewport': require('../.test-build/app/ui/viewport.js'),
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
+1 -1
View File
@@ -9,7 +9,7 @@ test('iOS game worker forwards an immutable byte payload through its host and ig
const load = loader({ global: { isIOS: true, postMessage: data => worker.onmessage({ data }) } }, {
'../../graphics/image': {}, './chrome-layer': { windowIcon() {} },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: () => ({ width: 576, height: 260 }) },
'./geometry': { appViewport: () => ({ width: 576, height: 260 }) },
'../../native/frame-timings': {}, './worker-state': {},
'./shell': { shell: { registerWindow() {} } },
});
+33 -15
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
function load(file, modules = {}, globals = {}) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
@@ -23,7 +24,7 @@ const font = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../ap
const small = font(18), large = font(32);
const diagnostics = { magneticAccuracy: 3, magneticAnomalies: 2, orientationSource: 3, flags: 0x8c, sampleTimeMs: 1234 };
function compass(width = 576, height = 260, glasses = 'g2') {
function compass(width = 576, height = 260, glasses = 'g2', viewport = bordered(width, height)) {
let listener, window;
class RecordingImage extends graphics.GrayImage {
texts = [];
@@ -60,7 +61,7 @@ function compass(width = 576, height = 260, glasses = 'g2') {
'./calibration-layer': {}, './declination': { onDeclinationChanged: () => () => {} },
'./heading': { getNorthReference: () => 'magnetic', resolveHeading: (v) => ({ displayDegrees: v }) },
}, { setInterval: () => 1, clearInterval() {} });
const ctx = { stack: { getBaseSize: () => ({ width, height }), pop() {} } };
const ctx = { stack: { getBaseSize: () => viewport, pop() {} } };
app.createCompassAppWindow({ onClosed() {} });
return { menu: () => window.menuItems(),
paint: () => window.baseLayer.paint(ctx),
@@ -96,23 +97,40 @@ test('calibration dots track firmware magnetic accuracy and never go stale', ()
});
test('calibration readout fits the viewport without overlapping the heading or status', () => {
for (const [width, height] of [[240, 260], [320, 260], [576, 260], [640, 260], [576, 288], [576, 140]]) {
const app = compass(width, height); app.heading({ ...diagnostics, magneticAccuracy: 2 });
const image = app.paint();
const label = calibrationText(image);
assert.ok(label.x >= 0 && label.y >= 0, `${width}x${height}`);
assert.ok(label.x + label.width <= width && label.y + label.height <= image.height, `${width}x${height}`);
for (const other of image.texts.filter((t) => t !== label)) {
assert.ok(!overlaps(label, other), `${width}x${height}: overlaps "${other.text}"`);
}
if (process.env.COMPASS_PREVIEW && width === 576 && height === 260) {
fs.writeFileSync(process.env.COMPASS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
for (const [width, height] of [[240, 260], [320, 260], [576, 260], [640, 260], [576, 288], [576, 140], [476, 155]]) {
for (const viewport of [bordered(width, height), unbordered(width, height), edged(width, height, 'top', 'left'), edged(width, height, 'bottom')]) {
const where = `${width}x${height} ${JSON.stringify(viewport.padding)}`;
const app = compass(width, height, 'g2', viewport); app.heading({ ...diagnostics, magneticAccuracy: 2 });
const image = app.paint();
const label = calibrationText(image);
const { padding } = viewport;
// Every line of text keeps inside the padding of the window's edges.
for (const text of image.texts) {
assert.ok(text.x >= padding.left && text.y >= padding.top, `${where}: "${text.text}"`);
assert.ok(text.x + text.width <= width - padding.right && text.y + text.height <= height - padding.bottom, `${where}: "${text.text}"`);
}
for (const other of image.texts.filter((t) => t !== label)) {
assert.ok(!overlaps(label, other), `${where}: overlaps "${other.text}"`);
}
if (process.env.COMPASS_PREVIEW && width === 576 && height === 260 && viewport.padding.top && viewport.padding.right) {
fs.writeFileSync(process.env.COMPASS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
}
}
}
});
test('the calibration readout sits in the top-right corner, at the padding of those edges', () => {
const corner = (viewport) => {
const label = calibrationText(compass(576, 260, 'g2', viewport).paint());
return [label.x + label.width, label.y];
};
assert.deepEqual(corner(bordered(576, 260)), [568, 8]);
assert.deepEqual(corner(unbordered(576, 260)), [576, 0]);
assert.deepEqual(corner(edged(576, 260, 'top')), [576, 8]);
});
test('glasses without a magnetometer say so and offer no calibration', () => {
const app = compass(576, 260, 'g1');
const image = app.paint();
+8 -2
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
function load(file, modules = {}, extra = '', globals = {}) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8') + extra;
@@ -124,7 +125,8 @@ test('heading updates reuse the texture; brightness, layout and clipping changes
const layer = new compass.CompassLayer(() => {});
layer.enabled = true;
let height = 260;
const ctx = { stack: { getBaseSize: () => ({ width: viewportWidth, height }) } };
let viewport = bordered;
const ctx = { stack: { getBaseSize: () => viewport(viewportWidth, height) } };
const texture = () => layer.paint(ctx).draws.find((draw) => draw.kind === 'image').source;
const waiting = texture();
layer.rawHeading = 0;
@@ -143,7 +145,11 @@ test('heading updates reuse the texture; brightness, layout and clipping changes
const wide = texture();
assert.notEqual(wide, tall);
layer.firmwareStatus = 'Calibration status '.repeat(12);
assert.notEqual(texture(), wide);
const wrapped = texture();
assert.notEqual(wrapped, wide);
// Losing the borders moves the rose toward the edges, at the same size.
viewport = unbordered;
assert.notEqual(texture(), wrapped);
viewportWidth = 576;
});
+1
View File
@@ -22,6 +22,7 @@ const { BdfFont } = load('app/graphics/bdffont.ts');
const font = (name) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/${name}.bdf`), 'utf8'));
const fonts = { getDefaultSmallFont: () => font('ter-u12n'), getDefaultMediumFont: () => font('ter-u16n') };
const layers = load('app/ui/layers.ts', {
'./viewport': require('../.test-build/app/ui/viewport.js'),
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
});
+3 -2
View File
@@ -5,6 +5,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered } = require('./helpers/viewport.cjs');
const gestures = loader({}, {})('app/ui/gestures.ts');
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
@@ -74,7 +75,7 @@ const loadStore = () => {
const stackCalls = { push: 0, clearToBase: 0 };
const ctx = {
stack: {
getBaseSize: () => ({ width: 476, height: 180 }),
getBaseSize: () => bordered(476, 180),
isFocused: () => true,
clearToBase() { stackCalls.clearToBase++; },
push() { stackCalls.push++; },
@@ -159,7 +160,7 @@ const loadWarning = () => {
// The real stack calls onRemoved as it pops.
const ctx = {
stack: {
getBaseSize: () => ({ width: 476, height: 180 }),
getBaseSize: () => bordered(476, 180),
isFocused: () => true,
pop() { outcome.popped++; dialog.onRemoved(); },
},
+2 -1
View File
@@ -9,6 +9,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered } = require('./helpers/viewport.cjs');
const setting = (initial = '') => {
let value = initial;
@@ -74,7 +75,7 @@ const makeCtx = () => {
const stack = {
cleared: 0,
pushed: [],
getBaseSize: () => ({ width: 576, height: 136 }),
getBaseSize: () => bordered(576, 136),
isFocused: () => true,
clearToBase() { stack.cleared++; stack.pushed.length = 0; },
push(layer) { stack.pushed.push(layer); },
+51 -6
View File
@@ -6,13 +6,14 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const gestures = loader({}, {})('app/ui/gestures.ts');
const font = { lineHeight: 10, measureText: (text) => text.length * 6 };
/** Records drawn text; every other drawing call is a no-op. */
/** Records drawn text (and where, in `drawn.positions`); every other drawing call is a no-op. */
const makeImageClass = (drawn) => class {
drawText(_font, _x, _y, text) { drawn.push(text); }
drawText(_font, x, y, text) { drawn.push(text); (drawn.positions ??= new Map()).set(text, { x, y }); }
fillRect() {}
fillRoundedRect() {}
drawRoundedRect() {}
@@ -20,6 +21,8 @@ const makeImageClass = (drawn) => class {
/** Stand-in for ui/menu-core's Menu: draws every row in order, scrolls the selection by one. */
class FakeMenu {
/** The box and scrollbar track of the latest paint, whichever tab's menu it was. */
static painted = { box: null, scrollbar: null };
constructor(options) {
this.options = options;
this.items = options.items;
@@ -37,9 +40,10 @@ class FakeMenu {
if (event.type === 'scroll-up') this.selectedIndex = Math.max(0, this.selectedIndex - 1);
}
paint(image, box) {
FakeMenu.painted.box = box;
this.items.forEach((item, index) => this.options.draw({ image, item, index, x: box.x, y: box.y, width: box.width }));
}
drawScrollbar() {}
drawScrollbar(_image, x, y, height) { FakeMenu.painted.scrollbar = { x, y, height }; }
}
const storeApp = (packageId, name, version) => ({
@@ -93,9 +97,9 @@ const loadStore = ({ updates = [] } = {}) => {
return { layer, drawn, installs };
};
const makeCtx = () => ({
const makeCtx = (viewport = bordered(576, 288)) => ({
stack: {
getBaseSize: () => ({ width: 576, height: 288 }),
getBaseSize: () => viewport,
isFocused: () => true,
clearToBase() {},
push() {},
@@ -191,6 +195,47 @@ test('the Updates tab has no Update All row when nothing can be installed', asyn
assert.ok(!painted.includes('Update All'));
});
test('the list scrolls to the window\'s bottom edge under the fixed header, inside the side padding', async () => {
const updates = [{ installed: { packageId: 'c', name: 'Gamma', version: '1' } }];
const layout = async (viewport) => {
const { layer, drawn } = loadStore({ updates });
const ctx = makeCtx(viewport);
await openUpdatesTab(layer, ctx);
repaint(layer, drawn, ctx);
return { ...FakeMenu.painted, title: drawn.positions.get('EvenHub'), row: drawn.positions.get('Gamma') };
};
// Framed: rows start at the left padding and stop short of the scrollbar,
// which hugs the right padding. The header keeps the top padding; the list
// box runs to the bottom edge with that edge's padding inside it.
const framed = await layout(bordered(576, 288));
assert.equal(framed.box.x, 8);
assert.equal(framed.box.x + framed.box.width, 576 - 8 - 6);
assert.equal(framed.box.y + framed.box.height, 288, 'the box reaches the bottom edge');
assert.equal(framed.box.padTop, 0, 'no padding under the fixed header');
assert.equal(framed.box.padBottom, 8);
assert.deepEqual(framed.title, { x: 14, y: 11 }, 'a focused tab\'s highlight, 3px above the title line, sits at the padding');
assert.equal(framed.row.x, framed.title.x, 'the title lines up with the row text');
assert.deepEqual(framed.scrollbar, { x: 576 - 8 - 3, y: framed.box.y, height: 288 - 8 - framed.box.y });
// Nothing bordering the window: content runs to every edge.
const bare = await layout(unbordered(576, 288));
assert.equal(bare.box.x, 0);
assert.equal(bare.box.padBottom, 0);
assert.equal(bare.box.y + bare.box.height, 288);
assert.deepEqual(bare.title, { x: 6, y: 3 });
assert.equal(bare.box.y, framed.box.y - 8, 'the header moves up by the top padding');
assert.equal(bare.scrollbar.x, 576 - 3, 'the scrollbar stays clear of the rows');
assert.ok(bare.box.x + bare.box.width <= bare.scrollbar.x);
// Each edge follows its own padding.
const mixed = await layout(edged(576, 288, 'top', 'left'));
assert.equal(mixed.box.x, 8);
assert.equal(mixed.box.x + mixed.box.width, 576 - 6);
assert.equal(mixed.box.y, framed.box.y);
assert.equal(mixed.box.padBottom, 0);
});
// ---- permission dialog ---------------------------------------------------
const loadDialog = (detailLines) => {
@@ -216,7 +261,7 @@ const loadDialog = (detailLines) => {
() => { outcome.confirmed = true; },
() => { outcome.confirmed = false; },
);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 136 }), isFocused: () => true, pop() {} } };
const ctx = { stack: { getBaseSize: () => bordered(576, 136), isFocused: () => true, pop() {} } };
const paint = () => {
drawn.length = 0;
dialog.paint(ctx, () => new ImageClass());
+6 -1
View File
@@ -1,5 +1,6 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
@@ -55,7 +56,9 @@ const glyphRuns = (image, f) => image.draws.filter((d) => d.kind === 'glyph' &&
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]]) {
// Framed windows, and ones nothing borders (so no padding: the rows reach the edges).
for (const [size, beside] of [[bordered(576, 260), false], [bordered(476, 192), null], [bordered(476, 155), true],
[unbordered(576, 260), false], [unbordered(476, 155), true], [edged(576, 260, 'top', 'left'), false]]) {
const { layers, ctx } = stackOf(size);
picker.uiFontPickerMenuItem().onSelect(ctx);
const image = layers[0].paint(ctx);
@@ -71,6 +74,8 @@ test('the font picker previews under its rows where they fit, else beside them,
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');
// The rows' text keeps the same inset from wherever the padding puts their boxes.
assert.equal(Math.min(...rows.map((d) => d.x)), size.padding.left + 10);
}
});
+17
View File
@@ -0,0 +1,17 @@
// Viewports for layout tests: what ctx.stack.getBaseSize() (or a worker's
// open-window message) hands a layout. Needs `tsc -p tests/tsconfig.json`.
const viewport = require('../../.test-build/app/ui/viewport.js');
/** A window with a border line along every edge (a framed window): 8px of padding all round. */
const bordered = (width, height) => viewport.viewportWith({ width, height }, viewport.uniformEdges('border'));
/** A window nothing borders (Border: None, or immersive): no padding. */
const unbordered = (width, height) => viewport.viewportWith({ width, height }, viewport.uniformEdges('offscreen'));
/** A window with border lines along just the named edges, e.g. edged(576, 260, 'top', 'left'). */
const edged = (width, height, ...borders) => viewport.viewportWith({ width, height }, {
top: 'offscreen', right: 'offscreen', bottom: 'offscreen', left: 'offscreen',
...Object.fromEntries(borders.map((edge) => [edge, 'border'])),
});
module.exports = { ...viewport, bordered, unbordered, edged };
+44 -8
View File
@@ -124,18 +124,53 @@ function shown(image, at) {
return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4)));
}
test('a box topped at the band inset less the highlight inset pads the first row band evenly', () => {
// The launcher's root grid (launcher-app.ts ROOT_GRID_TOP) relies on this.
const { grid } = makeGrid();
const { ICON_GRID_BAND_INSET_X: insetX, ICON_GRID_HIGHLIGHT_INSET_Y: insetY } = loadIconGrid();
const image = paint(grid, 1000, { x: 0, y: insetX - insetY, width: 500, height: 190 });
/** Bounds of the selection highlight's stroke in a painted image: [top, left, right margin]. */
function bandBounds(image) {
const stroke = build('ui/menu-core').MENU_HIGHLIGHT_STROKE;
let left = 500, right = -1, top = 200;
image.pixels.forEach((v, i) => {
if (v !== stroke) return;
left = Math.min(left, i % 500); right = Math.max(right, i % 500); top = Math.min(top, (i / 500) | 0);
});
assert.deepEqual([top, left, 500 - 1 - right], [insetX, insetX, insetX]);
return [top, left, 500 - 1 - right];
}
test('a box inset at the sides, with as much padTop, pads the first row band evenly', () => {
// The launcher's grid (launcher-app.ts) relies on this: its box runs to the
// window's top edge, with the edge's suggested padding as padTop.
const pad = 8;
const image = paint(makeGrid().grid, 1000, { x: pad, y: 0, width: 500 - 2 * pad, height: 190, padTop: pad });
assert.deepEqual(bandBounds(image), [pad, pad, pad]);
// Beside blank space there is no padding: the band spans the box, its own
// 2px inside its row.
assert.deepEqual(bandBounds(paint(makeGrid().grid, 1000, { x: 0, y: 0, width: 500, height: 190 })), [2, 0, 0]);
});
test('padTop scrolls away with the first row, and the scroll still animates to the static paint', async () => {
const box = { x: 0, y: 0, width: 500, height: 180, padTop: 8, padBottom: 8 };
const { grid } = makeGrid({ items: Array.from({ length: 20 }, (_, i) => `item${i}`) });
const iconYs = (image) => [...new Set(image.draws.filter((d) => d.kind === 'image' && !d.presentation).map((d) => d.y))];
// The first row starts below the padding (less the band's own 2px inset).
assert.deepEqual(iconYs(paint(grid, 500, box)), [6 + 4, 6 + 4 + ROW_H]);
await grid.handleInput(ring('scroll-down'), null);
paint(grid, 1000, box);
// Once the band's slide onto the second row is over.
const settledBefore = paint(grid, 2000, box);
await grid.handleInput(ring('scroll-down'), null);
const moving = paint(grid, 3000, box);
assert.ok(animation(moving), 'the scroll is retained as a display list');
assert.deepEqual(shown(moving, 3000), shown(settledBefore, 2000));
const end = 3000 + MENU_HIGHLIGHT_DURATION_MS;
const settled = paint(grid, end, box);
// Scrolled, the rows run from the box's top edge.
assert.deepEqual(iconYs(settled), [4, 4 + ROW_H]);
assert.deepEqual(shown(moving, end), shown(settled, end));
// A touch lands on the row under it either way.
const { grid: touched, log } = makeGrid();
paint(touched, 1000, box);
assert.equal(await touched.hitTest(50, 3, null), false, 'the padding is no row');
assert.equal(await touched.hitTest(50, 6 + ROW_H + 10, null), true);
assert.deepEqual(log.activated.map((a) => a.index), [5]);
});
test('rows keep their content height instead of stretching, and the next row peeks clipped', () => {
@@ -203,8 +238,9 @@ test('item selection slides the highlight between cells without redrawing past t
assert.equal(list.calls[0].clip.width, 495, 'the scrollbar gutter is left to the static paint');
const rect = list.calls[1];
const { evaluate } = build('graphics/draw-expression');
assert.equal(evaluate(rect.x, 0).value, 200 + 6, 'starts on the middle cell');
assert.equal(evaluate(rect.x, MENU_HIGHLIGHT_DURATION_MS).value, 300 + 6, 'rests on the next cell');
// The rows keep clear of the gutter: five 99px columns in the 495 left of it.
assert.equal(evaluate(rect.x, 0).value, 198 + 6, 'starts on the middle cell');
assert.equal(evaluate(rect.x, MENU_HIGHLIGHT_DURATION_MS).value, 297 + 6, 'rests on the next cell');
assert.deepEqual(shown(moving, 2000), shown(before, 1000));
const end = 2000 + MENU_HIGHLIGHT_DURATION_MS;
assert.deepEqual(shown(moving, end), shown(paint(grid, end), end));
+23 -5
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
const read = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
@@ -103,8 +104,16 @@ test('Input events captures while visible, pauses for history, and unsubscribes
});
let visible = true, renders = 0, removed = 0, pops = 0;
const layer = new InputEventsLayer(() => renders++, () => visible, () => removed++);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 260 }),
let viewport = bordered(576, 260);
const ctx = { stack: { getBaseSize: () => viewport,
pop: () => pops++, popThrough: (page) => { assert.equal(page, layer); page.onRemoved(); } } };
const inBounds = (image) => {
for (const text of image.texts) {
assert.ok(text.x >= 0 && text.x + text.width <= image.width, text.text);
assert.ok(text.y >= 0 && text.y + text.height <= image.height, text.text);
}
};
const at = (image, start) => image.texts.find(t => t.text.startsWith(start));
try {
for (const type of ['ring-press','click','ring-press','ring-press','double-click','long-press','long-press-release','short-then-long-press']) {
const e = { ...event(type, 1000 + renders * 75), ringInput: { tick: 4294967200 + renders, type: 1, aux:0, speed:0 } };
@@ -117,10 +126,19 @@ test('Input events captures while visible, pauses for history, and unsubscribes
assert.ok(image.texts.some(t => t.text.startsWith("*")));
layer.menuItems()[2].onSelect(ctx);
assert.ok(layer.paint(ctx).texts.some(t => t.text.startsWith("Phone receive time")));
for (const text of image.texts) {
assert.ok(text.x >= 0 && text.x + text.width <= image.width, text.text);
assert.ok(text.y >= 0 && text.y + text.height <= image.height, text.text);
}
inBounds(image);
// Framed: the title and the hint line sit at the padding; the log is between them.
assert.deepEqual([at(image, 'Input events').x, at(image, 'Input events').y], [8, 8]);
assert.equal(at(image, 'Unfiltered').y + font.lineHeight, 260 - 8);
assert.ok(Math.max(...image.texts.map(t => t.x + t.width)) <= 576 - 8, 'nothing runs into the right padding');
// Nothing bordering the window: the same lines run to its edges.
viewport = unbordered(576, 260);
const bare = layer.paint(ctx);
inBounds(bare);
assert.deepEqual([at(bare, 'Input events').x, at(bare, 'Input events').y], [0, 0]);
assert.equal(at(bare, 'Unfiltered').y + font.lineHeight, 260);
assert.ok(bare.texts.length >= image.texts.length, 'the log has no less room');
viewport = bordered(576, 260);
if (process.env.INPUT_EVENTS_PREVIEW) fs.writeFileSync(process.env.INPUT_EVENTS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
+16 -4
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
function load(file, modules = {}, globals = {}) {
const sandbox = { exports: {}, require: id => {
@@ -150,9 +151,9 @@ function screenFixture() {
const f = provider(), timers = new Map(); let nextTimer = 0;
const font = { lineHeight: 12, measureText: text => text.length * 6 };
class Image {
constructor(width = 300, height = 288) { this.width = width; this.height = height; this.text = []; }
drawText(_font, _x, _y, text) { this.text.push(text); }
fillRoundedRect() {} drawRoundedRect() {}
constructor(width = 300, height = 288) { this.width = width; this.height = height; this.text = []; this.at = {}; this.boxes = []; }
drawText(_font, x, y, text) { this.text.push(text); this.at[text] = [x, y]; }
fillRoundedRect(x, y, width, height) { this.boxes.push([x, y, width, height]); } drawRoundedRect() {}
}
const common = {
'graphics/image': { GrayImage: Image }, 'graphics/ui-fonts': { getDefaultSmallFont: () => font, getDefaultMediumFont: () => font },
@@ -173,7 +174,8 @@ function screenFixture() {
test('Calendar and Glanceboard show permission, loading, error and event states with widget cleanup', () => {
const f = screenFixture(); let renders = 0, requests = 0;
const widget = new f.CalendarWidget(), layer = new f.CalendarLayer(() => requests++);
const ctx = { stack: { getBaseSize: () => ({ width: 300, height: 288 }) } };
let viewport = bordered(300, 288);
const ctx = { stack: { getBaseSize: () => viewport } };
const paintWidget = () => { const image = new f.Image(); widget.paint(image); return image.text.join(' '); };
widget.start(() => renders++); widget.start(() => renders++); assert.equal(f.timers.size, 1);
f.permission(false); assert.match(layer.paint(ctx).text.join(' '), /Grant calendar permission/);
@@ -187,6 +189,16 @@ test('Calendar and Glanceboard show permission, loading, error and event states
f.reads[1].done(JSON.stringify([f.event('event')]), null);
assert.match(layer.paint(ctx).text.join(' '), /Meeting/);
assert.match(paintWidget(), /Meeting/);
// Beside border lines the selection box keeps the suggested padding and the
// title lines up with row text; with nothing past the edges they run to them.
const framed = layer.paint(ctx);
assert.deepEqual(framed.at.Calendar, [18, 10]);
assert.deepEqual(framed.boxes[0], [8, 54, 284, 32]);
assert.equal(framed.at.Office[0], 18);
viewport = unbordered(300, 288);
const bare = layer.paint(ctx);
assert.deepEqual(bare.at.Calendar, [10, 2]);
assert.deepEqual(bare.boxes[0], [0, 46, 300, 32]);
widget.stop(); const before = renders; f.bridge.changeHandler();
assert.equal(renders, before); assert.equal(f.timers.size, 0);
});
+4 -1
View File
@@ -191,7 +191,10 @@ function fixture() {
: ({ 0: 'click', 1: 'scroll-up', 2: 'scroll-down', 3: 'double-click', 9: 'long-press',
10: 'long-press-release', 11: 'short-then-long-press' })[event.eventType] ?? 'unknown', source: 'ring',
}) },
'../ui/shell/geometry': { appViewportRect: () => ({ x: 0, y: 0, width: 640, height: 480 }) },
'../ui/shell/geometry': {
appViewportRect: () => ({ x: 0, y: 0, width: 640, height: 480 }),
windowEdges: () => ({ top: 'offscreen', right: 'offscreen', bottom: 'offscreen', left: 'offscreen' }),
},
};
const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', modules, {
...clock, console: { log() {}, warn() {}, error: text => errors.push(text) },
+10 -7
View File
@@ -81,20 +81,23 @@ test('the header puts title and status on one line, truncated before the meter',
const h = harness();
const meter = new h.MicLevelMeter();
const image = fakeImage(300);
const bodyTop = h.paintListeningHeader(image, font, 'Translate', 'Listening (ElevenLabs)...', meter);
assert.equal(bodyTop, 20 + 18 + 2);
assert.deepEqual(image.texts.map(({ x, y, gray }) => [x, y, gray]), [[24, 20, 200], [24 + 54, 20, 110]]);
// Inside the padding suggested for the window's edges: here a border at
// the top and left, blank space at the right.
const padding = { top: 8, right: 0, bottom: 8, left: 8 };
const bodyTop = h.paintListeningHeader(image, font, 'Translate', 'Listening (ElevenLabs)...', meter, padding);
assert.equal(bodyTop, 8 + 18 + 2);
assert.deepEqual(image.texts.map(({ x, y, gray }) => [x, y, gray]), [[8, 8, 200], [8 + 54, 8, 110]]);
assert.equal(image.texts[0].text, 'Translate');
const status = image.texts[1].text;
assert.ok(status.startsWith(' · Listening') && status.endsWith('...'), status);
const meterX = Math.min(...image.rects.map(rect => rect.x));
assert.equal(meterX, 300 - 24 - meter.width);
assert.ok(24 + 54 + status.length * 6 <= meterX - 10, 'status stops short of the meter');
assert.equal(meterX, 300 - meter.width, 'the meter ends at the unpadded right edge');
assert.ok(8 + 54 + status.length * 6 <= meterX - 10, 'status stops short of the meter');
// Segments sit on the text baseline.
assert.ok(image.rects.every(rect => rect.y + rect.h === 20 + font.ascent));
assert.ok(image.rects.every(rect => rect.y + rect.h === 8 + font.ascent));
const idle = fakeImage(300);
h.paintListeningHeader(idle, font, 'Transcribe', 'Starting microphone...', null);
h.paintListeningHeader(idle, font, 'Transcribe', 'Starting microphone...', null, padding);
assert.equal(idle.rects.length, 0);
assert.equal(idle.texts[1].text, ' · Starting microphone...');
});
+34
View File
@@ -75,6 +75,40 @@ test('scrolling keeps the selection and its neighbors visible and aligns the vie
assert.equal(menu.scrollTop, 0);
});
test('padTop and padBottom are blank rows inside the scrolled content, shown only at its ends', async () => {
// A box that runs to a window's edges: 8px of padding scrolls with the rows.
const box = { x: 10, y: 5, width: 80, height: 60, padTop: 8, padBottom: 8 };
const { menu, paint, image } = stringMenu();
const step = async (type) => { await menu.handleInput({ type }); paint(true, box); return menu.scrollTop; };
const rows = paint(true, box);
assert.equal(menu.scrollTop, 0);
assert.equal(rows[1].y, 5 + 8 + 20, 'rows start below the padding');
assert.equal(menu.indexAt(5 + 4), null, 'the padding is no row');
assert.equal(menu.indexAt(5 + 8), 0);
assert.equal(menu.overflows, true);
// Rows scrolled off are cut at the box's edge: the viewport rests on a row
// top, without the padding, until the first row comes back.
assert.equal(await step('scroll-down'), 0);
assert.equal(await step('scroll-down'), 28, 'b sits right at the top edge');
assert.equal(menu.indexAt(5), 1);
assert.equal(await step('scroll-down'), 28);
assert.equal(await step('scroll-down'), 68, 'the last row shows with the padding under it');
assert.equal(menu.selectedIndex, 4);
assert.equal(await step('scroll-up'), 68);
assert.equal(await step('scroll-up'), 28);
assert.equal(await step('scroll-up'), 28);
assert.equal(await step('scroll-up'), 0, 'back at the first row, its padding shows again');
// Content that fits just sits below the top padding.
const short = stringMenu({ items: ['a', 'b'] });
const drawn = short.paint(true, box);
assert.equal(short.menu.overflows, false);
assert.equal(drawn[1].y, 5 + 8 + 20);
// A scrollbar spans the padded content.
const before = image.pixels.slice();
menu.drawScrollbar(image, 95, 5, 60);
assert.ok(image.pixels.some((value, index) => value !== before[index]));
});
test('without wrap the ends call the exit callbacks and hold the selection', async () => {
const { menu, exits } = stringMenu();
await menu.handleInput({ type: 'scroll-up' });
+15 -3
View File
@@ -50,6 +50,7 @@ test('later opaque planes add an occlusion to a replayed selection',()=>{
});
const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{
'./viewport':require('../.test-build/app/ui/viewport.js'),
'../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',()=>{
@@ -121,7 +122,9 @@ 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',{
'../viewport':require('../.test-build/app/ui/viewport.js'),
'../../graphics/image':graphics,'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
'./viewport':require('../.test-build/app/ui/viewport.js'),
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},
'./gestures':{isDirectionalInput:()=>false},
}),
@@ -147,6 +150,7 @@ test('a stack without its own size follows the screen when the glasses type chan
// RayNeo iO must not leave its overlays painting on a 540x220 canvas.
const screen={width:540,height:220};
const {LayerStack}=load('app/ui/layers.ts',{
'./viewport':require('../.test-build/app/ui/viewport.js'),
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},
'../graphics/screen-size':{screenWidth:()=>screen.width,screenHeight:()=>screen.height},'./gestures':{},
});
@@ -156,10 +160,18 @@ test('a stack without its own size follows the screen when the glasses type chan
const sizes=()=>JSON.parse(JSON.stringify(stack.paint().map(p=>[p.image.width,p.image.height])));
assert.deepEqual(sizes(),[[540,220],[540,220]]);
screen.width=640;screen.height=480;
assert.deepEqual({...stack.getBaseSize()},{width:640,height:480});
const plain=value=>JSON.parse(JSON.stringify(value));
const unbordered={edges:{top:'offscreen',right:'offscreen',bottom:'offscreen',left:'offscreen'},padding:{top:0,right:0,bottom:0,left:0}};
assert.deepEqual(plain(stack.getBaseSize()),{width:640,height:480,...unbordered});
assert.deepEqual(sizes(),[[640,480],[640,480]]);
// An explicit size (a window's viewport, the modal's interior) stays put.
// An explicit size (a window's viewport, the modal's interior) stays put;
// given bare, nothing borders it, so it suggests no padding.
const sized=new LayerStack({paint:()=>new graphics.GrayImage(100,90,0)},noopLayerActions,{width:100,height:90});
screen.width=540;screen.height=220;
assert.deepEqual({...sized.getBaseSize()},{width:100,height:90});
assert.deepEqual(plain(sized.getBaseSize()),{width:100,height:90,...unbordered});
// A host that says what its edges touch hands layers the padding for them.
const viewport=require('../.test-build/app/ui/viewport.js');
const edges={top:'border',right:'offscreen',bottom:'offscreen',left:'border'};
sized.setBaseSize(viewport.viewportWith({width:100,height:90},edges));
assert.deepEqual(plain(sized.getBaseSize()),{width:100,height:90,edges,padding:{top:8,right:0,bottom:0,left:8}});
});
+2 -1
View File
@@ -1,5 +1,6 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { bordered } = require('./helpers/viewport.cjs');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
@@ -177,7 +178,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
};
const { MusicSettingsLayer } = load('app/apps/music/music-settings.ts', (name) => uiDeps[name]);
const layer = new MusicSettingsLayer();
const ctx = { stack: { getBaseSize: () => ({ width: 540, height: 224 }), isFocused: () => true, pop: () => closes++ } };
const ctx = { stack: { getBaseSize: () => bordered(540, 224), isFocused: () => true, pop: () => closes++ } };
const paint = () => layer.paint(ctx, () => new RecordingImage(540, 224));
const input = (type) => layer.handleInput({ type }, ctx);
assert.equal(refreshes, 1);
+23 -8
View File
@@ -5,6 +5,7 @@ const vm = require('node:vm');
const ts = require('typescript');
const path = require('node:path');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const flush = () => new Promise(resolve => setImmediate(resolve));
const route = { coordinates: [[-122.4, 37.7], [-122.4, 37.71]], distanceMeters: 1112, durationSec: 600,
@@ -13,7 +14,7 @@ const route = { coordinates: [[-122.4, 37.7], [-122.4, 37.71]], distanceMeters:
const fix = latitude => ({ latitude, longitude: -122.4, timestampMs: Date.now(), bearingDeg: 0, speedMps: 1.5, accuracyMeters: 5 });
function fixture() {
const messages = [], timers = new Set(), timeouts = new Set(), holds = [], maps = [], errors = [], requests = [];
let callbacks, compass, delayRoute = null, delayMap = null, routeError = null, distanceUnit = 'miles', timeFormat = '24h';
let callbacks, compass, delayRoute = null, delayMap = null, routeError = null, distanceUnit = 'miles', timeFormat = '24h', paints = 0;
const routeMath = loader()('app/apps/navigate/route-follower.ts');
const tracker = { running: false, isRunning() { return this.running; }, start() { this.running = true; }, stop() { this.running = false; } };
const sensor = { LocationTracker: function (value) { callbacks = value; return tracker; }, COMPASS_CHANGED: 15,
@@ -22,7 +23,8 @@ function fixture() {
handleNavigationSensorEvent: event => { if (event.kind === 'location') callbacks.onLocation(event.location); } };
const modules = {
'@nativescript/core/globals': {},
'../../graphics/bdffont': { getFont: () => ({}) }, '../../graphics/ui-fonts': { getDefaultSmallFont: () => ({}) },
// The footer hint's line height sets how much of the window the map-mode map gets.
'../../graphics/bdffont': { getFont: () => ({}) }, '../../graphics/ui-fonts': { getDefaultSmallFont: () => ({ lineHeight: 12 }) },
'../../native/settings-store': { onSettingsStoreChanged() {} },
'../../ui/dashboard-settings': { distanceUnitSetting: { get: () => distanceUnit } },
'../../ui/clock-format': loader({}, { './dashboard-settings': { timeFormatSetting: { get: () => timeFormat } } })('app/ui/clock-format.ts'),
@@ -34,7 +36,8 @@ function fixture() {
'../../native/frame-timings': { startFrame: () => 1, finishFrame() {}, logFrame() {}, span: (_id, _name, fn) => fn(), runWithFrame: (_id, fn) => fn() },
'../../native/active-display': { getActiveDisplay: () => null },
'../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'),
'../../ui/window-menu': { WindowMenu: class { paint() { return []; } isOpen() { return false; } resize() {} } },
'../../ui/window-menu': { WindowMenu: class { paint() { paints++; return []; } isOpen() { return false; } resize() {} } },
'../../ui/viewport': require('../.test-build/app/ui/viewport.js'),
'../../graphics/plane': { planesFingerprint: () => 'frame' },
'../../native/mapbox': {
isMapboxConfigured: () => true,
@@ -54,9 +57,9 @@ function fixture() {
console: { log() {}, warn() {}, error: error => errors.push(error) }, require: id => modules[id] ?? {},
});
const send = data => global.onmessage({ data });
send({ type: 'open-window', windowId: 'navigate:main', surfaceId: 'window:navigate:main', title: 'Navigate', viewport: { width: 576, height: 480 } });
send({ type: 'open-window', windowId: 'navigate:main', surfaceId: 'window:navigate:main', title: 'Navigate', viewport: bordered(576, 480) });
send({ type: 'foreground', windowId: 'navigate:main', foreground: true, focused: true });
return { ...exports.probe, send, timers, holds, maps, errors, tracker, requests,
return { ...exports.probe, send, timers, holds, maps, errors, tracker, requests, paints: () => paints,
input: type => send({ type: 'input', windowId: 'navigate:main', focused: true, frameId: 1, event: { type } }),
tick: () => { for (const callback of timers) callback(); },
expireFix: () => { for (const callback of timeouts) callback(); timeouts.clear(); },
@@ -114,8 +117,9 @@ test('front page map entry follows location without routing, supports zoom and r
h.fix(37.7); await flush();
assert.equal(h.state().phase, 'map');
assert.deepEqual(h.requests, []);
// The map fills the window down to the footer hint, which rests on the bottom padding.
assert.equal(h.maps.at(-1).width, 576);
assert.equal(h.maps.at(-1).height, 450);
assert.equal(h.maps.at(-1).height, 452);
assert.equal(h.maps.at(-1).routePath, undefined);
assert.equal(h.maps.at(-1).camera.latitude, 37.7);
assert.equal(h.maps.at(-1).camera.bearingDeg, 0);
@@ -147,9 +151,20 @@ test('map suspends fetching and compass while hidden and resizes to the viewport
assert.equal(h.holds.at(-1), false);
h.send({ type: 'screen', on: true }); await flush();
assert.equal(h.maps.at(-1).camera.latitude, 37.71);
h.send({ type: 'resize-window', windowId: 'navigate:main', viewport: { width: 540, height: 260 } }); await flush();
const resize = async viewport => { h.send({ type: 'resize-window', windowId: 'navigate:main', viewport }); await flush(); };
await resize(bordered(540, 260));
assert.equal(h.maps.at(-1).width, 540);
assert.equal(h.maps.at(-1).height, 230);
assert.equal(h.maps.at(-1).height, 232);
// With no border below, the footer hint moves down to the edge and the map follows it.
await resize(edged(540, 260, 'top', 'left'));
assert.equal(h.maps.at(-1).height, 240);
// A change to the other edges lays the window out again, but keeps the map it has.
const fetched = h.maps.length, painted = h.paints();
await resize(unbordered(540, 260));
assert.equal(h.maps.length, fetched);
assert.equal(h.paints(), painted + 1);
await resize(unbordered(540, 260));
assert.equal(h.paints(), painted + 1);
h.send({ type: 'close-window' });
assert.equal(h.tracker.running, false);
assert.equal(h.timers.size, 0);
+42 -4
View File
@@ -4,6 +4,7 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const alerts = require('../.test-build/app/apps/nightscout/nightscout-alerts.js');
const detector = require('../.test-build/app/apps/nightscout/missed-bolus-detector.js');
const now = 1_800_000_000_000;
@@ -53,6 +54,7 @@ class Image {
drawText(font, ...args) { this.draws.push(['text', ...args]); }
drawLine(...args) { this.draws.push(['line', ...args]); }
fillRect(...args) { this.draws.push(['rect', ...args]); }
drawRect(...args) { this.draws.push(['frame', ...args]); }
}
const font = { measureText: text => text.length * 6, lineHeight: 12, hasGlyph: () => true };
@@ -197,17 +199,22 @@ test('tray keeps every pixel row when a TTF font measures the reading fractional
}
});
test('main page highlights only the breached field and removes highlights on recovery', () => {
const f = fixture();
const page = load('app/apps/nightscout/nightscout.ts', {
/** nightscout.ts (the app window's page) over a fixture's bridge and settings. */
function loadMainPage(f) {
return load('app/apps/nightscout/nightscout.ts', {
...f.deps,
'../../graphics/textwrap': { truncateText: (font, text) => text },
'../../ui/gestures': {}, '../../ui/layers': {}, '../../ui/menu': {},
'../../ui/dashboard/settings-panel': {}, '../../ui/metrics': { lineStep: () => 16 },
'~/util/date-util': { formatAgeShortFromTimestamp: () => '1m', formatTimestamp: () => '12:00' },
}, { Date: { now: () => now } });
}
test('main page highlights only the breached field and removes highlights on recovery', () => {
const f = fixture();
const page = loadMainPage(f);
const layer = new page.NightscoutLayer();
const paint = () => layer.paint({ stack: { getBaseSize: () => ({ width: 576, height: 260 }) } });
const paint = () => layer.paint({ stack: { getBaseSize: () => bordered(576, 260) } });
for (const [field, value, label] of [['reservoirUnits', 10, '10U'], ['batteryVoltage', 1, '1.00V'], ['cageTimestampMs', now - 73 * 3_600_000, 'CAGE 1m'], ['loopTimestampMs', now - 16 * 60_000, 'Loop 1m']]) {
f.state[field] = value;
const image = paint();
@@ -219,6 +226,37 @@ test('main page highlights only the breached field and removes highlights on rec
}
});
test('main page puts its title, readout and graph at the padding suggested for each edge', () => {
const f = fixture();
Object.assign(f.state, { history: [{ timestampMs: now - 60_000, sgv: 120 }], basal: [], carbs: [], boluses: [] });
const layer = new (loadMainPage(f).NightscoutLayer)();
const paint = viewport => layer.paint({ stack: { getBaseSize: () => viewport } }).draws;
const texts = draws => draws.filter(d => d[0] === 'text');
const graph = draws => draws.find(d => d[0] === 'frame').slice(1, 5);
// A border on every edge: 8px in from each. The caption is the last line above the bottom padding.
const framed = paint(bordered(576, 260));
assert.deepEqual(texts(framed)[0].slice(1, 4), [8, 8, 'Nightscout']);
assert.deepEqual(texts(framed)[1].slice(1, 4), [8, 64, '100'], 'readout, centered between the title (to y=20) and the graph (from y=120)');
assert.deepEqual(graph(framed), [8, 120, 560, 114]);
assert.deepEqual(texts(framed).at(-1).slice(1, 3), [8, 240]);
// No borders: the page runs to the window's edges and the graph takes the room.
const bare = paint(unbordered(576, 260));
assert.deepEqual(texts(bare)[0].slice(1, 3), [0, 0]);
assert.deepEqual(graph(bare), [0, 112, 576, 130]);
assert.deepEqual(texts(bare).at(-1).slice(1, 3), [0, 248]);
// Each edge is padded on its own.
assert.deepEqual(graph(paint(edged(576, 260, 'top', 'left'))), [8, 120, 568, 122]);
assert.deepEqual(graph(paint(edged(576, 260, 'bottom', 'right'))), [0, 112, 568, 122]);
// A window too short for the graph and its caption gives the graph the caption's room, inside the image.
const short = paint(bordered(476, 155));
assert.deepEqual(graph(short), [8, 120, 460, 27]);
assert.ok(!texts(short).some(d => /glucose history/.test(d[3])));
});
test('bridge exposes numeric measurements and treats absent values as unknown', async () => {
let pump = { reservoir: '10.5', battery: { voltage: '1.15' } };
const module = load('app/native/nightscout-bridge.ts', {
+2 -1
View File
@@ -1,5 +1,6 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { bordered } = require('./helpers/viewport.cjs');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
@@ -133,7 +134,7 @@ function ui(fontSize = 12) {
dependencies['./menu'] = load('app/ui/menu.ts', requireModule);
const { SingleNotificationLayer } = load('app/ui/notifications.ts', requireModule);
const { NotificationFilterLayer } = load('app/ui/notification-filter.ts', requireModule);
const ctx = { stack: { getBaseSize: () => ({ width: 540, height: 224 }), isFocused: () => true, pop: () => closes++ } };
const ctx = { stack: { getBaseSize: () => bordered(540, 224), isFocused: () => true, pop: () => closes++ } };
const popup = new SingleNotificationLayer('key', { origin: 'new-notification-modal', onClose: () => closes++ });
const trayCloses = [];
const tray = new SingleNotificationLayer('key', { origin: 'notification-tray', onClose: (_ctx, gone) => trayCloses.push(gone) });
+38 -4
View File
@@ -1,6 +1,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
// Roboto's line heights at the onboarding sizes, and a fixed advance.
const FONTS = { title: 31, body: 24, detail: 19, hero: 52 };
@@ -53,7 +54,8 @@ test('the layout page fits four 40%-wide diagrams with captions on the immersive
const page = new LayoutPage();
assert.equal(page.immersive, true);
const image = recorder(640, 480);
page.paint(image, true);
// An immersive page's edges are the screen's: no padding.
page.paint(image, true, unbordered(640, 480).padding);
// Each diagram's outline spans the display's width at 40%.
const areas = image.calls.filter((call) => call.kind === 'outline' && call.w === 256);
assert.equal(areas.length, 4);
@@ -79,6 +81,16 @@ test('the layout page fits four 40%-wide diagrams with captions on the immersive
// Bottom, recommended, is the selected cell at first, filled while focused.
const box = image.calls.find((call) => call.kind === 'fill' && call.value === 15);
assert.ok(box.x <= areas[0].x && box.y <= areas[0].y && box.y + box.h >= bottom.y);
// With nothing bordering the page, its title sits 10px in (where list rows' text starts) and 2px down.
const title = text('Layout')[0];
assert.deepEqual([title.x, title.y], [10, 2]);
// Beside border lines the heading keeps their padding, and the grid stays centred.
const framed = recorder(640, 480);
page.paint(framed, true, bordered(640, 480).padding);
const framedTitle = framed.calls.find((call) => call.kind === 'text' && call.text === 'Layout');
assert.deepEqual([framedTitle.x, framedTitle.y], [18, 10]);
const framedAreas = framed.calls.filter((call) => call.kind === 'outline' && call.w === 256);
assert.deepEqual(framedAreas.map((area) => area.x), areas.map((area) => area.x));
});
test('the layout page starts on Bottom whatever is set, swipes in reading order, and a tap saves the choice', () => {
@@ -137,12 +149,24 @@ test('the text size page offers 12 to 18px, starts on the recommended 16px, and
assert.deepEqual(rows.filter((texts) => texts.length > 1).length, 1);
// The size column holds the note; the preview is paragraphs of text, no menu.
const image = recorder(640, 480);
page.paint(image, true);
page.paint(image, true, unbordered(640, 480).padding);
assert.ok(menu.box.width >= 10 + '16 px'.length * 8 + 8 + 'Recommended'.length * 8);
const preview = image.calls.filter((call) => call.kind === 'text' && call.x > menu.box.x + menu.box.width);
assert.equal(preview[0].text.startsWith('This is how text will look'), true);
assert.ok(preview.length > 3);
assert.equal(image.calls.some((call) => call.kind === 'text' && call.text === 'Timers'), false);
// Unpadded, the size list starts at the window's left edge and the preview's frame reaches its right and bottom edges.
const frame = image.calls.find((call) => call.kind === 'outline');
assert.equal(menu.box.x, 0);
assert.deepEqual([frame.x + frame.w, frame.y + frame.h], [640, 480]);
// The list scrolls, so it runs to the bottom edge whatever borders it, the edge's padding inside it.
assert.deepEqual([menu.box.y + menu.box.height, menu.box.padBottom], [480, 0]);
const framed = recorder(640, 480);
page.paint(framed, true, bordered(640, 480).padding);
const paddedFrame = framed.calls.find((call) => call.kind === 'outline');
assert.equal(menu.box.x, 8);
assert.deepEqual([paddedFrame.x + paddedFrame.w, paddedFrame.y + paddedFrame.h], [632, 472]);
assert.deepEqual([menu.box.y + menu.box.height, menu.box.padBottom], [480, 8]);
// A tap saves; coming back keeps the size chosen.
page.handleInput({ type: 'scroll-up' }, { next: () => {} });
page.handleInput({ type: 'click' }, { next: () => {} });
@@ -186,7 +210,7 @@ test('on a RayNeo iO the layout page recommends and starts on Left, and fits the
assert.equal(recommendedLayout(), 'left');
const page = new LayoutPage();
const image = recorder(540, 220);
page.paint(image, true);
page.paint(image, true, unbordered(540, 220).padding);
const captions = image.calls.filter((call) => call.kind === 'text').map((call) => call.text);
assert.ok(captions.includes('Left (Recommended)'));
assert.ok(captions.includes('Bottom'));
@@ -289,9 +313,19 @@ test('the display mode page offers Full Screen only where the layout allows it,
assert.equal(menu.selectedItem, 'fullscreen');
// The selected mode's description sits beside the list, within the window (a band's).
const image = recorder(576, 260);
page.paint(image, true);
page.paint(image, true, bordered(576, 260).padding);
const description = image.calls.filter((call) => call.kind === 'text' && call.x >= menu.box.x + menu.box.width);
assert.match(description.map((call) => call.text).join(' '), /Depth is turned off/);
// Beside border lines: the title at the UI-wide (18, 10), the list's rows from the padding, the list to the bottom edge.
const title = (calls) => calls.find((call) => call.kind === 'text' && call.text === 'Display mode');
assert.deepEqual([title(image.calls).x, title(image.calls).y], [18, 10]);
assert.deepEqual([menu.box.x, menu.box.y + menu.box.height, menu.box.padBottom], [8, 260, 8]);
assert.ok(description.every((call) => call.x + call.text.length * 8 <= 576 - 18 && call.y + FONTS.detail <= 260 - 8));
// With no border on the left or bottom, the page runs to those edges.
const open = recorder(576, 260);
page.paint(open, true, { top: 8, right: 8, bottom: 0, left: 0 });
assert.deepEqual([title(open.calls).x, title(open.calls).y], [10, 10]);
assert.deepEqual([menu.box.x, menu.box.y + menu.box.height, menu.box.padBottom], [0, 260, 0]);
let next = 0;
const nav = { next: () => next++ };
page.handleInput({ type: 'scroll-up' }, nav);
+29 -5
View File
@@ -15,6 +15,7 @@ function load(file, modules) {
}
const graphics = require('../.test-build/app/graphics/image.js');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
const metrics = require('../.test-build/app/ui/metrics.js');
const menuCore = require('../.test-build/app/ui/menu-core.js');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
@@ -34,8 +35,8 @@ const { SettingsPanelLayer } = load('app/ui/dashboard/settings-panel.ts', {
'../shell/shell': { shell: { yieldFocusToSidebar: () => yields++ } },
});
/** A panel over three sections; records which item callbacks fire. */
function panel() {
/** A panel over three sections, in a framed window unless given another; records which item callbacks fire. */
function panel(viewport = bordered(576, 260)) {
const selected = [];
const item = (label, extra = {}) => ({ label, onSelect: () => selected.push(label), ...extra });
const layer = new SettingsPanelLayer([
@@ -43,7 +44,7 @@ function panel() {
{ label: 'Voice', items: Array.from({ length: 20 }, (_, i) => item(`Voice ${i}`, { description: 'Help text for this option.' })) },
{ label: 'About', items: [], renderDetail: () => {} },
]);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 260 }), isFocused: () => true } };
const ctx = { stack: { getBaseSize: () => viewport, isFocused: () => true } };
const input = (type) => layer.handleInput({ type, timestampMs: 0 }, ctx);
return { layer, input, paint: () => layer.paint(ctx), selected };
}
@@ -104,7 +105,7 @@ test('the selected row stays clear of its description band', async () => {
await p.input('scroll-up');
const row = selections(p.paint())[1];
const overlay = new graphics.GrayImage(576, 260);
p.layer.paintDescriptionOverlay(overlay, { stack: { getBaseSize: () => ({ width: 576, height: 260 }) } });
p.layer.paintDescriptionOverlay(overlay, { stack: { getBaseSize: () => bordered(576, 260) } });
let bandTop = -1;
for (let y = 0; y < 260 && bandTop < 0; y++) if (overlay.getPixel(300, y) !== 0) bandTop = y;
assert.ok(bandTop > 0, 'the band is drawn');
@@ -118,7 +119,7 @@ test('a section\'s detail gives its rows the pane while focus is in them, where
// 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]]) {
for (const [size, keeps] of [[bordered(576, 260), true], [bordered(476, 192), false], [bordered(476, 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) }; };
@@ -133,3 +134,26 @@ test('a section\'s detail gives its rows the pane while focus is in them, where
assert.ok(row.y + row.source.height <= size.height - 8);
}
});
test('the columns keep the padding suggested for each window edge, and scroll right up to the top and bottom', async () => {
// Where the left column's first-row highlight (a retained selection) starts.
const first = (viewport) => { const row = selections(panel(viewport).paint())[0]; return [row.x, row.y]; };
assert.deepEqual(first(bordered(576, 260)), [8, 8], 'beside border lines, 8px in');
assert.deepEqual(first(unbordered(576, 260)), [0, 0], 'beside blank space, right at the edges');
// The right column ends at the right edge's padding.
for (const [viewport, right] of [[bordered(576, 260), 568], [unbordered(576, 260), 576]]) {
const p = panel(viewport);
await p.input('click');
const row = selections(p.paint())[1];
assert.equal(row.x + row.source.width, right);
}
// A long list scrolled to its middle is cut off at the window's own top
// and bottom edges, not at the padding: a row starts at y 0.
const p = panel(bordered(576, 260));
await p.input('scroll-down');
await p.input('click');
for (let i = 0; i < 10; i++) await p.input('scroll-down');
const image = p.paint().withDrawsBaked();
const lit = (y) => { for (let x = 180; x < 560; x++) if (image.getPixel(x, y) > 40) return true; return false; };
assert.ok([0, 1, 2, 3, 4, 5, 6, 7].some(lit), 'rows show in the top padding once scrolled');
});
+1 -1
View File
@@ -149,7 +149,7 @@ test('host applies activity only to its own open windows and cleans up on close'
'../../graphics/image': { GrayImage: Image },
'./chrome-layer': { windowIcon: (icon, letter, glyph, phase) => phase },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: () => ({ width: 576, height: 260 }) },
'./geometry': { appViewport: () => ({ width: 576, height: 260 }) },
'../../native/frame-timings': {},
'./worker-state': {},
'./shell': { shell: { registerWindow: w => shellWindows.set(w.windowId, w) } },
+30 -10
View File
@@ -1,30 +1,50 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { HUB_TITLE_X, layoutHubHeader } = require('../.test-build/app/apps/terminal/hub-header.js');
const { HUB_TITLE_INSET_X, layoutHubHeader } = require('../.test-build/app/apps/terminal/hub-header.js');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const font = size => ({ measureText: text => [...text].length * size, getGlyph: () => ({ dwidthX: size }) });
// Framed all round: the title 8px in plus its inset, and 2px below the top padding.
const TITLE_X = 8 + HUB_TITLE_INSET_X;
test('terminal short status stays inline; exact-fit status does not move the list', () => {
const f = font(7), title = 'Terminal', status = 'Connected.';
const width = HUB_TITLE_X + f.measureText(title) + 16 + f.measureText(status) + 12;
const header = layoutHubHeader(f, title, status, width, 18);
const width = TITLE_X + f.measureText(title) + 16 + f.measureText(status) + 8;
const header = layoutHubHeader(f, title, status, bordered(width, 260), 18);
assert.deepEqual([header.titleX, header.titleY], [TITLE_X, 10]);
assert.equal(header.y, 10); assert.equal(header.listTop, 34); assert.deepEqual(header.lines, [status]);
assert.equal(layoutHubHeader(f, title, status, width - 1, 18).y, 28);
assert.equal(layoutHubHeader(f, title, status, bordered(width - 1, 260), 18).y, 28);
});
test('terminal long error wraps in full-width block and moves menu below all lines at each font size', () => {
const status = 'Connection failed. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.';
for (const size of [5, 7, 12, 20]) for (const width of [320, 576, 640]) {
const f = font(size), step = size * 2;
const header = layoutHubHeader(f, 'Terminal - Connections', status, width, step);
assert.equal(header.x, HUB_TITLE_X); assert.equal(header.y, 10 + step);
const header = layoutHubHeader(f, 'Terminal - Connections', status, bordered(width, 260), step);
assert.equal(header.x, TITLE_X); assert.equal(header.y, 10 + step);
assert.equal(header.lines.join(' '), status);
assert.ok(header.lines.every(line => f.measureText(line) <= width - HUB_TITLE_X - 12));
assert.ok(header.lines.every(line => f.measureText(line) <= width - TITLE_X - 8));
assert.ok(header.listTop >= header.y + header.lines.length * step);
assert.equal(header.listTop, 16 + step * (1 + header.lines.length));
}
});
test('terminal explicit newlines and long unbroken messages remain complete', () => {
const h = layoutHubHeader(font(7), 'Terminal', 'First\nSecond', 640, 18);
assert.equal(h.x, HUB_TITLE_X); assert.deepEqual(h.lines, ['First', 'Second']);
const h = layoutHubHeader(font(7), 'Terminal', 'First\nSecond', bordered(640, 260), 18);
assert.equal(h.x, TITLE_X); assert.deepEqual(h.lines, ['First', 'Second']);
const word = 'x'.repeat(200);
const wrapped = layoutHubHeader(font(7), 'Terminal', word, 320, 18);
const wrapped = layoutHubHeader(font(7), 'Terminal', word, bordered(320, 260), 18);
assert.equal(wrapped.lines.join(''), word);
});
test('terminal header keeps the padding of just the edges a border runs along', () => {
const f = font(7), title = 'Terminal', status = 'Connected.';
// Nothing bordered: the title starts its inset from the left edge, at the top edge's offset.
const open = layoutHubHeader(f, title, status, unbordered(576, 260), 18);
assert.deepEqual([open.titleX, open.titleY, open.y, open.listTop], [HUB_TITLE_INSET_X, 2, 2, 26]);
// An inline status may run right up to an unbordered right edge, but stops 8px short of a bordered one.
const fit = HUB_TITLE_INSET_X + f.measureText(title) + 16 + f.measureText(status);
assert.equal(layoutHubHeader(f, title, status, unbordered(fit, 260), 18).lines.length, 1);
assert.equal(layoutHubHeader(f, title, status, unbordered(fit, 260), 18).y, 2);
assert.equal(layoutHubHeader(f, title, status, edged(fit, 260, 'right'), 18).y, 2 + 18);
// Each edge on its own.
const topLeft = layoutHubHeader(f, title, 'First\nSecond', edged(576, 260, 'top', 'left'), 18);
assert.deepEqual([topLeft.titleX, topLeft.titleY, topLeft.x, topLeft.y], [TITLE_X, 10, TITLE_X, 28]);
const bottom = layoutHubHeader(f, title, 'First\nSecond', edged(576, 260, 'bottom'), 18);
assert.deepEqual([bottom.titleX, bottom.titleY, bottom.listTop], [HUB_TITLE_INSET_X, 2, 8 + 18 * 3]);
});
+49 -9
View File
@@ -1,10 +1,12 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const { bordered, unbordered } = require('./helpers/viewport.cjs');
const HUB = 'terminal:hub';
const MIN = { width: 552, height: 260 };
const MAX = { width: 552, height: 452 };
// Framed windows: the shell's messages carry what each edge touches and its padding.
const MIN = bordered(552, 260);
const MAX = bordered(552, 452);
const font = { lineHeight: 12, measureText: (text) => text.length * 6, getGlyph: () => null };
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
@@ -15,9 +17,10 @@ function fakeImageModule() {
this.width = width;
this.height = height;
this.texts = [];
this.positions = [];
return new Proxy(this, { get: (target, key) => (key in target ? target[key] : () => {}) });
}
drawText(_font, _x, _y, text) { this.texts.push(text); }
drawText(_font, x, y, text) { this.texts.push(text); this.positions.push([text, x, y]); }
drawMenuSelection(row) { this.texts.push(...row.texts.map((text) => `[${text}]`)); }
}
return { GrayImage };
@@ -94,8 +97,8 @@ function terminal({ sessions = ['vim', 'top'], presets = '', bellWake = true } =
'../../graphics/image': image,
'../graphics/image': image,
'../../graphics/plane': {
planesFingerprint: (planes) => JSON.stringify([planes[0].width, planes[0].height, planes[0].texts]),
flattenPlanesWithDraws: (planes) => ({ image: { ...planes[0], width: planes[0].width, height: planes[0].height, texts: planes[0].texts, to8bppBuffer: () => ({ buffer: planes[0].texts }) }, draws: [] }),
planesFingerprint: (planes) => JSON.stringify([planes[0].width, planes[0].height, planes[0].texts, planes[0].positions]),
flattenPlanesWithDraws: (planes) => ({ image: { ...planes[0], width: planes[0].width, height: planes[0].height, texts: planes[0].texts, to8bppBuffer: () => ({ buffer: planes[0] }) }, draws: [] }),
},
'../../graphics/glyph-wire': { prepareFrameDraws: () => null },
'../../graphics/ui-fonts': {
@@ -109,7 +112,7 @@ function terminal({ sessions = ['vim', 'top'], presets = '', bellWake = true } =
},
'../../native/active-display': {
getActiveDisplay: () => ({
submitSurfaceFrame: (texts, surfaceId, _x, _y, width, height) => frames.push({ surfaceId, width, height, texts }),
submitSurfaceFrame: ({ texts, positions }, surfaceId, _x, _y, width, height) => frames.push({ surfaceId, width, height, texts, positions }),
}),
},
'../../ui/gestures': { GESTURE_DOUBLE_CLICK: 'double-tap' },
@@ -148,6 +151,8 @@ function terminal({ sessions = ['vim', 'top'], presets = '', bellWake = true } =
return {
clients, frames, replies, menus, send, input, openWindow, repliesOf,
lastFrame: () => frames[frames.length - 1],
// Where the last frame drew a line of text, as [x, y].
textAt: (text) => frames[frames.length - 1].positions.find((entry) => entry[0] === text).slice(1),
clearReplies: () => { replies.length = 0; },
openMenu: (windowId = HUB) => input('short-then-long-press', windowId),
menuLabels: () => Array.from(menus.find((menu) => menu.isOpen()).opened, (item) => item.label),
@@ -399,14 +404,49 @@ test('closing the window while it shows a session stops that session', () => {
test('a later resize of a session in place reconnects at the new grid, and the list then gets its own size', () => {
const t = hubShowingSession();
t.answerHeight({ width: 552, height: 400 });
t.answerHeight(bordered(552, 400));
assert.equal(t.clients[1].stopped, false);
assert.deepEqual(t.clients[1].viewport, [92, 33]);
t.input('double-click');
t.answerHeight({ width: 552, height: 240 });
t.answerHeight(bordered(552, 240));
assert.equal(t.lastFrame().height, 240);
});
test('the list lays out inside the padding of its window\'s bordered edges, and follows a change in them', async () => {
const t = terminal();
t.openWindow(HUB, MIN);
// The title lines up with the rows' text: 6px inside their boxes, which start at the left padding.
assert.deepEqual(t.textAt('Terminal'), [8 + 6, 8 + 2]);
assert.deepEqual(t.textAt('Connected.'), [8 + 6 + 'Terminal'.length * 6 + 16, 8 + 2]);
// The window menu's stack gets the whole viewport, for the pages it shows.
const plain = (value) => JSON.parse(JSON.stringify(value));
assert.deepEqual(plain(t.menus[0].options.size), plain(MIN));
// Same size, nothing bordering it any more (Border: None): a repaint with no padding.
const painted = t.frames.length;
t.send({ type: 'resize-window', windowId: HUB, viewport: unbordered(552, 260) });
await new Promise((resolve) => setTimeout(resolve, 80));
assert.equal(t.frames.length, painted + 1);
assert.deepEqual(t.textAt('Terminal'), [6, 2]);
assert.deepEqual(plain(t.menus[0].options.size), plain(unbordered(552, 260)));
});
test('a session keeps its connection and grid when only its window\'s edges change', async () => {
const t = hubShowingSession();
const painted = t.frames.length;
t.send({ type: 'resize-window', windowId: HUB, viewport: unbordered(552, 452) });
await new Promise((resolve) => setTimeout(resolve, 80));
assert.equal(t.clients[1].stopped, false);
assert.equal(t.clients[1].viewport, undefined, 'no new grid negotiated');
assert.equal(t.clients.length, 2);
assert.equal(t.frames.length, painted);
// Back in the list, the hub takes the padding the shell answers with.
t.input('double-click');
t.answerHeight(unbordered(552, 260));
assert.deepEqual(t.textAt('Terminal'), [6, 2]);
});
test('the shell host resizes the surface before answering with the new viewport', async () => {
const worker = { posted: [], postMessage(message) { this.posted.push(message); } };
const surfaces = [];
@@ -417,7 +457,7 @@ test('the shell host resizes the surface before answering with the new viewport'
'../../graphics/image': {},
'./chrome-layer': { windowIcon() {} },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: (mode) => (mode === 'max' ? MAX : MIN) },
'./geometry': { appViewport: (mode) => (mode === 'max' ? MAX : MIN) },
'../../native/frame-timings': {},
'./worker-state': {},
'./shell': { shell: {
+37 -1
View File
@@ -2,9 +2,12 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const load = loader();
const { TranscriptModel, TranscriptScroll, wrapTranscribeText } = load('app/apps/transcribe/transcript-model.ts');
const { TranscriptModel, TranscriptScroll, transcriptLayout, wrapTranscribeText } = load('app/apps/transcribe/transcript-model.ts');
const { SpeechPauseDetector } = load('app/native/speech-pause.ts');
const { TimedTranscript } = load('app/native/transcript-format.ts');
const { bordered, unbordered, edged } = require('./helpers/viewport.cjs');
const plain = value => JSON.parse(JSON.stringify(value));
function pcm(amplitude, ms = 50) {
const bytes = new Uint8Array(ms * 16 * 2);
@@ -82,6 +85,39 @@ test('short transcripts become scrollable without disabling automatic following'
assert.equal(s.layout(12, 10), 2);
});
test('the transcript lines up with the header inside the side padding and scrolls to the bottom edge', () => {
// 16px lines stepping 20, under a header that ends at y=38.
const framed = transcriptLayout(bordered(576, 260), 38, 16, 20);
assert.deepEqual(plain(framed), {
// In line with the header's title at the left padding; the right keeps the scrollbar's gutter.
textX: 8, textWidth: 576 - 8 - 8 - 8, pageLines: 10, drawnLines: 11,
scrollbar: { x: 576 - 8 - 2, y: 38, width: 2, height: 260 - 8 - 38 },
});
// Following the tail, the last line rests above the bottom padding; scrolled
// back, one more line fits above the window's edge itself.
const lineBottom = (firstLine, total) => 38 + (Math.min(total, firstLine + framed.drawnLines) - 1 - firstLine) * 20 + 16;
const s = new TranscriptScroll();
assert.equal(s.layout(40, framed.pageLines), 30);
assert.equal(lineBottom(30, 40), 234);
s.scroll(-3);
assert.equal(s.layout(40, framed.pageLines), 27);
assert.equal(lineBottom(27, 40), 254);
assert.ok(lineBottom(27, 40) > 260 - 8 && lineBottom(27, 40) <= 260);
// With nothing bordering the window, the column and the page gain the padding's room.
assert.deepEqual(plain(transcriptLayout(unbordered(576, 260), 38, 16, 20)), {
textX: 0, textWidth: 576 - 8, pageLines: 11, drawnLines: 11,
scrollbar: { x: 574, y: 38, width: 2, height: 222 },
});
const leftOnly = transcriptLayout(edged(576, 260, 'left'), 38, 16, 20);
assert.deepEqual([leftOnly.textX, leftOnly.textWidth, leftOnly.scrollbar.x], [8, 576 - 8 - 8, 574]);
// The scrollbar never stands over the text column.
for (const layout of [framed, leftOnly, transcriptLayout(bordered(476, 155), 38, 16, 20)]) {
assert.ok(layout.textX + layout.textWidth < layout.scrollbar.x);
assert.ok(layout.pageLines >= 1 && layout.drawnLines >= layout.pageLines);
}
});
test('pause detector uses 1.5 seconds of PCM, fires once per pause, and ignores leading silence', () => {
const d = new SpeechPauseDetector();
for (let i = 0; i < 60; i++) assert.equal(d.accept(pcm(0)), false);
+1
View File
@@ -26,6 +26,7 @@
"../app/graphics/plane.ts",
"../app/graphics/shell-scene.ts",
"../app/ui/metrics.ts",
"../app/ui/viewport.ts",
"../app/ui/menu-core.ts",
"../app/phone-ui/phone-gestures.ts",
"../app/native/java-direct-buffer.ts",
+1 -1
View File
@@ -11,7 +11,7 @@ function fixture() {
const load = loader({ global: {}, setTimeout: (fn, ms) => { timers.set(fn, ms); return fn; }, clearTimeout: fn => timers.delete(fn) }, {
'../../graphics/image': {}, './chrome-layer': { windowIcon() {} },
'../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } },
'./geometry': { appViewportSize: () => ({ width: 576, height: 288 }) },
'./geometry': { appViewport: () => ({ width: 576, height: 288 }) },
'../../native/frame-timings': {}, './worker-state': { publishWorkerState: (...args) => published.push(args) },
'./shell': { shell: { registerWindow: w => shellWindows.set(w.windowId, w), setTrayIcon() {},
focusWindow: id => focused.push(id), isWindowFocused: () => false } },