Adapt layouts for Rayneo screen resolution

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

No files matched your search

+2
View File
@@ -258,6 +258,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
const layers = load('app/ui/layers.ts', {
'../graphics/image': images, '../graphics/plane': { dimPlanes: (planes) => planes },
'../native/frame-timings': timings, './gestures': gestures,
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
});
class Menu {
constructor(title, items) { this.title = title; this.items = items; this.selectedIndex = 0; }
@@ -285,6 +286,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../../native/notification-icons': {}, '../../native/notification-sources': {},
'../../assistant/tool-registry': {}, './geometry': {
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
screenWidth: () => 640, screenHeight: () => 480,
appViewportRect: () => ({ x: 64, y: 124, width: 576, height: 260 }),
},
});
+76 -3
View File
@@ -9,20 +9,21 @@ const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
function geometry() {
// The shell geometry over a G2's 640x480 screen, or `screen` (a RayNeo iO is 540x220).
function geometry(screen = { width: 640, height: 480 }) {
const settings = Object.fromEntries(Object.entries({
displayLayoutSetting: 'band-middle', navigateDisplayLayoutSetting: 'global', terminalDisplayLayoutSetting: 'default',
appSwitcherPositionSetting: 'left', uiDepthSetting: '0', statusBarPositionSetting: 'top',
statusBarVisibilitySetting: 'always', windowBorderSetting: true,
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
const context = { exports: {}, require: (name) => {
if (name === '../../graphics/image') return { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 };
if (name === '../../graphics/screen-size') return { screenWidth: () => screen.width, screenHeight: () => screen.height };
assert.equal(name, '../dashboard-settings');
return settings;
} };
vm.runInNewContext(js(read('app/ui/shell/geometry.ts')), context);
const rect = (mode, appId) => ({ ...context.exports.appViewportRect(mode, appId) });
return { ...context.exports, settings, rect };
return { ...context.exports, settings, screen, rect };
}
const LAYOUTS = ['band-top', 'band-high', 'band-middle', 'band-low', 'band-bottom', 'tall', 'fullscreen'];
@@ -263,6 +264,78 @@ test('an immersive app fills the panel without chrome rows, frame or depth, in a
}
});
test('on a RayNeo iO\'s 540x220 screen windows take every row under the bar, beside the strip or over the row', () => {
const g = geometry({ width: 540, height: 220 });
const panel = { x: 0, y: 0, width: 540, height: 220 };
// A band is the whole screen's height, so every band position is the same.
for (const layout of LAYOUTS) {
g.settings.displayLayoutSetting.value = layout;
g.settings.appSwitcherPositionSetting.value = 'left';
assert.equal(g.minWindowHeight(), 220);
assert.equal(g.minWindowTop(), 0);
for (const mode of ['min', 'medium', 'max']) assert.deepEqual(g.rect(mode), { x: 64, y: 28, width: 476, height: 192 }, layout);
assert.deepEqual({ ...g.switcherRect('min') }, { x: 0, y: 0, width: 64, height: 220 });
g.settings.appSwitcherPositionSetting.value = 'right';
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 476, height: 192 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 476, y: 0, width: 64, height: 220 });
}
assert.equal(g.isOnSwitcherEdge(500, 10, 'min'), true);
assert.equal(g.screenCenterInViewportX(), 270);
// A bottom row: the window centred above it, its sides room for the deepest shift.
g.settings.appSwitcherPositionSetting.value = 'bottom';
g.settings.displayLayoutSetting.value = 'band-middle';
assert.deepEqual(g.rect('min'), { x: 32, y: 28, width: 476, height: 156 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 184, width: 476, height: 36 });
g.settings.displayLayoutSetting.value = 'fullscreen';
assert.deepEqual(g.rect('min'), { x: 0, y: 28, width: 540, height: 156 });
// The phone mirror shows the whole screen, at its 27:11.
g.settings.displayLayoutSetting.value = 'band-middle';
for (const position of ['left', 'bottom', 'popup']) {
g.settings.appSwitcherPositionSetting.value = position;
assert.deepEqual({ ...g.phonePreviewRect({ ...g.usedScreenRect('min') }) }, panel, position);
}
// Every layout stays on the screen.
g.settings.uiDepthSetting.value = '62';
for (const switcher of ['left', 'right', 'bottom', 'popup']) {
g.settings.appSwitcherPositionSetting.value = switcher;
for (const statusBar of ['top', 'bottom']) {
g.settings.statusBarPositionSetting.value = statusBar;
for (const layout of LAYOUTS) {
g.settings.displayLayoutSetting.value = layout;
for (const mode of ['min', 'medium', 'max']) {
const rect = g.rect(mode), row = g.switcherRect(mode);
const where = `${switcher} ${statusBar} ${layout} ${mode}`;
assert.ok(rect.x >= 0 && rect.y >= 0 && rect.x + rect.width <= 540 && rect.y + rect.height <= 220, where);
assert.ok(row.y >= 0 && row.y + row.height <= 220, where);
if (g.windowFramed()) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 540, where);
}
}
}
}
// The G2's band is unchanged.
assert.equal(geometry().minWindowHeight(), 288);
});
test('on a RayNeo iO the chrome paints the screen\'s size, its strip and row within it', () => {
for (const position of ['left', 'right', 'bottom', 'popup']) {
const g = geometry({ width: 540, height: 220 });
g.settings.appSwitcherPositionSetting.value = position;
const { chrome, state } = chromeLayer(g, { windows: 3, notifications: 2, phoneBattery: 80 });
state.focus = 'sidebar';
const image = chrome.paint();
assert.deepEqual([image.width, image.height], [540, 220], position);
const parts = chrome.paintParts();
assert.ok(parts.length > 0, position);
for (const part of parts) {
assert.ok(part.x >= 0 && part.y >= 0 && part.x + part.image.width <= 540 && part.y + part.image.height <= 220,
`${position} part ${part.shellKey} at ${[part.x, part.y, part.image.width, part.image.height]}`);
}
// And it draws something there.
const lit = (x0, y0, w, h) => { for (let y = y0; y < y0 + h; y++) for (let x = x0; x < x0 + w; x++) if (image.pixels[y * 540 + x]) return true; return false; };
assert.ok(lit(0, 0, 540, 220), position);
}
});
test('the phone mirror zooms to the area the shell uses, centred at the panel\'s 4:3', () => {
const g = geometry();
const preview = (mode, appId) => {
+18 -1
View File
@@ -25,9 +25,10 @@ const fonts = { getDefaultSmallFont: () => font };
const layers = load('app/ui/layers.ts', {
'../graphics/image': graphics, '../graphics/plane': plane, './gestures': gestures,
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
});
const menu = load('app/ui/menu.ts', {
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap,
'../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'),
@@ -108,6 +109,22 @@ test('the thin bar fills upward in proportion to brightness in each viewport', (
}
});
test('in a short window (a RayNeo iO\'s) the bar shrinks so the dialog stays inside it', () => {
for (const viewport of [{ x: 64, y: 28, width: 476, height: 192 }, { x: 32, y: 1, width: 476, height: 155 }]) {
const f = fixture('100', viewport);
const image = f.stack.paint().at(-1).image;
// The dialog's border (110) and the full bar (255), all within the window.
let top = Infinity, bottom = -1, fill = 0;
for (let y = 0; y < image.height; y++) for (let x = 0; x < image.width; x++) {
const value = image.getPixel(x, y);
if (value === 110) { top = Math.min(top, y); bottom = Math.max(bottom, y); }
if (value === 255) fill++;
}
assert.ok(top >= viewport.y && bottom < viewport.y + viewport.height, `dialog ${top}..${bottom} in ${JSON.stringify(viewport)}`);
assert.ok(fill > 0 && fill < 12 * 100, 'a shorter bar, still drawn');
}
});
test('system menu hides brightness in Auto and opens its picker between Voice input and Debug', async () => {
const f = fixture('auto');
const { shell } = load('app/ui/shell/shell.ts', {
+14 -7
View File
@@ -65,16 +65,23 @@ test('Full Screen is offered only with a bottom or popup app switcher', () => {
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
});
test('a RayNeo iO pins the band to the top and the switcher to the right, leaving the stored choice alone', () => {
const store = new Map([['display.layout', 'band-middle'], ['display.appSwitcherPosition', 'bottom']]);
test('a RayNeo iO defaults the app switcher to the left, and keeps a chosen position and the band', () => {
const store = new Map();
const api = settingsFixture(store);
assert.equal(api.displayLayoutSetting.get(), 'band-middle');
assert.equal(api.appSwitcherPositionSetting.get(), 'bottom');
api.glassesTypeSetting.set('rayneo-io');
assert.equal(api.displayLayoutSetting.get(), 'band-top');
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
assert.equal(store.get('display.layout'), 'band-middle');
api.glassesTypeSetting.set('g2');
assert.equal(api.appSwitcherPositionSetting.get(), 'left');
assert.equal(api.displayLayoutSetting.get(), 'band-middle');
assert.equal(store.has('display.appSwitcherPosition'), false);
// A stored position is the user's, on either glasses.
api.appSwitcherPositionSetting.set('right');
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
api.glassesTypeSetting.set('g2');
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
store.delete('display.appSwitcherPosition');
assert.equal(api.appSwitcherPositionSetting.get(), 'bottom');
// An unknown stored value falls back to the glasses' default.
store.set('display.appSwitcherPosition', 'sideways');
api.glassesTypeSetting.set('rayneo-io');
assert.equal(api.appSwitcherPositionSetting.get(), 'left');
});
+88
View File
@@ -0,0 +1,88 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
function load(file, modules) {
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const context = { exports: {}, console, require(name) { assert.ok(name in modules, `${file}: ${name}`); return modules[name]; } };
vm.runInNewContext(ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, context);
return context.exports;
}
const build = (name) => require(`../.test-build/app/${name}.js`);
const graphics = build('graphics/image');
const metrics = build('ui/metrics');
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const bdf = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8'));
const font = bdf(14);
const textwrap = load('app/graphics/textwrap.ts', {});
const coreDeps = {
'../graphics/image': graphics, './menu-highlight-motion': build('ui/menu-highlight-motion'),
'../graphics/menu-scroll-list': build('graphics/menu-scroll-list'), './menu-scroll-motion': build('ui/menu-scroll-motion'),
'../graphics/draw-expression': build('graphics/draw-expression'),
};
const menuCore = load('app/ui/menu-core.ts', coreDeps);
const menu = load('app/ui/menu.ts', {
...coreDeps, './menu-animation-pref': build('ui/menu-animation-pref'), './animation-speed': build('ui/animation-speed'),
'../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'../graphics/screen-size': { screenWidth: () => 540, screenHeight: () => 220 },
'../graphics/textwrap': textwrap, '../graphics/ui-fonts': { getDefaultSmallFont: () => font },
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, './gestures': {}, './metrics': metrics, './menu-core': menuCore,
});
// The UI font picker on Roboto Light 20, drawn in Terminus (TTF rendering is native).
const preview = bdf(20);
const picker = load('app/ui/font-picker.ts', {
'../graphics/bdffont': { getFont: () => font }, '../graphics/image': graphics, '../graphics/textwrap': textwrap,
'../graphics/ttf-font': { TtfFont: { load: () => preview } },
'../graphics/installed-fonts': { listInstalledFonts: () => [{ path: '/fonts/Roboto-Light.ttf', fileName: 'Roboto-Light.ttf',
family: 'Roboto', style: 'Light', weightOrder: 300, monospace: false }] },
'../graphics/ui-fonts': { fontSelectionLabel: () => 'Roboto Light 20', getDefaultSmallFont: () => font, uiFontSizeAllowed: () => true,
getTerminalFontSelection: () => null, getUiFontSelection: () => ({ kind: 'ttf', file: 'Roboto-Light.ttf', size: 20 }),
setTerminalFontSelection() {}, setUiFontSelection() {} },
'./gestures': {}, './menu': menu, './menu-core': menuCore, './metrics': metrics,
});
function stackOf(size) {
const layers = [];
return { layers, ctx: { stack: { getBaseSize: () => size, isFocused: () => true, push: (layer) => layers.push(layer) } } };
}
const glyphRuns = (image, f) => image.draws.filter((d) => d.kind === 'glyph' && d.font === f);
test('the font picker previews under its rows where they fit, else beside them, on the window either way', () => {
// At 192 rows either fits, by the font's metrics: only the bounds are checked.
for (const [size, beside] of [[{ width: 576, height: 260 }, false], [{ width: 476, height: 192 }, null], [{ width: 476, height: 155 }, true]]) {
const { layers, ctx } = stackOf(size);
picker.uiFontPickerMenuItem().onSelect(ctx);
const image = layers[0].paint(ctx);
const sample = glyphRuns(image, preview);
// The rows' labels and values (255 selected, 200 not; the title is 220, the info line 110).
const rows = glyphRuns(image, font).filter((d) => d.value === 255 || d.value === 200);
assert.ok(sample.length > 20, `the sample is drawn at ${size.height}`);
for (const d of image.draws) {
if (d.kind !== 'glyph') continue;
assert.ok(d.x >= 0 && d.y >= 0 && d.x + d.glyph.bbxWidth <= size.width && d.y + d.font.lineHeight <= size.height,
`glyph at ${d.x},${d.y} outside ${size.width}x${size.height}`);
}
const rowsRight = Math.max(...rows.map((d) => d.x)), rowsBottom = Math.max(...rows.map((d) => d.y));
if (beside === true) assert.ok(Math.min(...sample.map((d) => d.x)) > rowsRight, 'the sample right of the rows');
if (beside === false) assert.ok(Math.min(...sample.map((d) => d.y)) > rowsBottom, 'the sample under the rows');
}
});
test('a modal menu in a short window (a RayNeo iO\'s) keeps narrow margins, so four choices all show', () => {
const items = ['Left', 'Right', 'Bottom', 'Popup'].map((label) => ({ label, onSelect() {} }));
for (const [size, margin] of [[{ width: 576, height: 260 }, 20], [{ width: 476, height: 155 }, 8]]) {
const { layers, ctx } = stackOf(size);
menu.openModalMenu(ctx, 'App switcher position', items, 0);
const { layout } = layers[0];
assert.ok(layout.y >= margin && layout.y + layout.maxHeight <= size.height - margin, `${size.height}: ${layout.y}+${layout.maxHeight}`);
// Title, body padding (8 above and below) and the four rows.
const natural = metrics.menuTitleHeight(font) + 2 * 8 + items.length * metrics.listRowHeight(font);
assert.equal(layout.maxHeight, natural, `${size.height}: every row fits`);
}
});
+1
View File
@@ -65,6 +65,7 @@ function loadIconGrid({ lastInputWasWatch = false } = {}) {
'./menu-animation-pref': build('ui/menu-animation-pref'),
'./animation-speed': build('ui/animation-speed'),
'../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
});
const grid = load('app/ui/icon-grid.ts', {
...common,
+29
View File
@@ -0,0 +1,29 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
const graphics = require('../.test-build/app/graphics/image.js');
// lock-screen.ts on a screen of the given size; the text is not drawn.
function lockScreen(width, height) {
const font = { lineHeight: 20, measureText: (text) => text.length * 10, drawText() {} };
const load = loader({}, {
'../graphics/image': graphics,
'../graphics/screen-size': { screenWidth: () => width, screenHeight: () => height },
'../graphics/ui-fonts': { getDefaultMediumFont: () => font },
'../graphics/textwrap': { wrapText: (_font, text) => [text] },
});
return load('app/g2/lock-screen.ts').createLockScreenImage();
}
// The lock surface is the screen's size, so its frame must be too.
test('the lock screen fills the paired glasses\' screen, its box centred on it', () => {
for (const [width, height] of [[640, 480], [540, 220]]) {
const image = lockScreen(width, height);
assert.deepEqual([image.width, image.height], [width, height]);
const lit = [];
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) if (image.pixels[y * width + x]) lit.push([x, y]);
const xs = lit.map(([x]) => x), ys = lit.map(([, y]) => y);
const box = [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)];
assert.deepEqual(box, [(width - 480) / 2, (height - 150) / 2, (width + 480) / 2 - 1, (height + 150) / 2 - 1], `${width}x${height}`);
}
});
+4 -4
View File
@@ -18,7 +18,7 @@ const menuCore=load('app/ui/menu-core.ts',{
'../graphics/image':graphics,'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
});
const {MenuLayer,TextPageLayer}=load('app/ui/menu.ts',{
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'../graphics/image':graphics,'../graphics/textwrap':{wrapText:(_font,text)=>text.split('\n')},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
'../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{},
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
@@ -50,7 +50,7 @@ test('later opaque planes add an occlusion to a replayed selection',()=>{
});
const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'./gestures':{},
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},'./gestures':{},
});
test('context menu surface and selected row both use +4 without changing the app screen',()=>{
const base=new graphics.GrayImage(100,90,96);
@@ -104,7 +104,7 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
'../../native/notification-icons':{},'../../native/notification-types':require('../.test-build/app/native/notification-types.js'),'../../native/phone-battery':{},'../../util/render-freshness':{},
'../../graphics/icons':{},'../dashboard-settings':{},'../clock-format':{},'../../graphics/bdffont':{},
'../layers':{LayerStack},'../menu':{scrollToKeepSelectionVisible:()=>0},'../metrics':{},
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24,
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowHeight:()=>280,screenWidth:()=>640,screenHeight:()=>480,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24,
SWITCHER_ROW_HEIGHT:36,switcherPosition:()=>'left',switcherRect:()=>({x:0,y:0,width:64,height:280})},
});
const state={selectedIndex:0,focus:'sidebar',windows:[0,1,2].map(n=>({attention:n===1,drawIcon:(image,x,y)=>image.fillRect(x,y,4,4,240)}))};
@@ -122,7 +122,7 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
test('shell modal carries its inner menu highlight animation instead of baking its first frame',async()=>{
const {ShellModalLayer}=load('app/ui/shell/modal-layer.ts',{
'../../graphics/image':graphics,'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},
'./gestures':{isDirectionalInput:()=>false},
}),
'./geometry':{appViewportSize:()=>({width:120,height:110}),appViewportRect:()=>({x:10,y:20,width:120,height:110}),SHELL_OPAQUE_BLACK:1},
+1 -1
View File
@@ -161,7 +161,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics': load('app/ui/metrics.ts'), './gestures': {},
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
};
deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]);
const menu = load('app/ui/menu.ts', (name) => deps[name]);
+1 -1
View File
@@ -87,7 +87,7 @@ function ui(fontSize = 12) {
'../util/render-freshness': { renderPassAllowsStaleData: () => false },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics': load('app/ui/metrics.ts'),
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'./gestures': {},
};
const requireModule = (name) => {
+53 -5
View File
@@ -11,19 +11,22 @@ function setting(value, values) {
writes: [], displayValue: (v) => v[0].toUpperCase() + v.slice(1) };
}
function harness() {
// The onboarding pages over G2 glasses (640x480), or a RayNeo iO's 540x220 screen.
function harness(glasses = 'g2') {
const screen = glasses === 'rayneo-io' ? { width: 540, height: 220 } : { width: 640, height: 480 };
const settings = {
glassesTypeSetting: setting(glasses, ['g2', 'rayneo-io']),
appSwitcherPositionSetting: setting('bottom', ['left', 'right', 'bottom', 'popup']),
statusBarPositionSetting: setting('bottom', ['top', 'bottom']),
uiDepthSetting: setting('48', ['-62', '-48', '-32', '-16', '0', '16', '32', '48', '62']),
};
const load = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../graphics/image': { G2_LENS_WIDTH: 640 },
'../../ui/dashboard-settings': settings,
'../../ui/shell/geometry': { MIN_WINDOW_HEIGHT: 288, SIDEBAR_WIDTH: 64, SWITCHER_ROW_HEIGHT: 36, TOP_BAR_HEIGHT: 28 },
'../../ui/shell/geometry': { MIN_WINDOW_HEIGHT: 288, SIDEBAR_WIDTH: 64, SWITCHER_ROW_HEIGHT: 36, TOP_BAR_HEIGHT: 28,
screenWidth: () => screen.width, screenHeight: () => screen.height },
});
return { settings, load };
return { settings, screen, load };
}
/** An image that records what is drawn, checking it all lands on the image. */
@@ -111,7 +114,7 @@ test('the text size page offers 12 to 18px, starts on the recommended 16px, and
'./onboarding-fonts': { onboardingFont: font },
'../../graphics/installed-fonts': { installedFontPath: (file) => `/fonts/${file}` },
'../../graphics/ttf-font': { TtfFont: { load: (path, size) => font(size === 12 ? 'title' : 'detail') } },
'../../graphics/ui-fonts': { fontSelectionLabel: () => 'Terminus', getDefaultSmallFont: () => font('detail'),
'../../graphics/ui-fonts': { defaultUiFontSize: () => 16, fontSelectionLabel: () => 'Terminus', getDefaultSmallFont: () => font('detail'),
getUiFontSelection: () => selection, setUiFontSelection: (value) => { selection = value; saved.push(value.size); },
uiFontSizeAllowed: (path, size) => size !== 13 },
'../../ui/font-picker': { FONT_SIZE_CHOICES: [8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 24] },
@@ -148,6 +151,51 @@ test('the text size page offers 12 to 18px, starts on the recommended 16px, and
assert.equal(menu.selectedItem, 15);
});
test('on a RayNeo iO the text size page recommends and starts on 14px, its default', () => {
const menu = { selected: null, items: [], setItems(items, index) { this.items = items; this.selected = index; },
get selectedItem() { return this.items[this.selected] ?? null; }, paint(image, box) { this.box = box; } };
let menuOptions;
const load = loader({}, {
'./onboarding-fonts': { onboardingFont: font },
'../../graphics/installed-fonts': { installedFontPath: (file) => `/fonts/${file}` },
'../../graphics/ttf-font': { TtfFont: { load: () => font('detail') } },
'../../graphics/ui-fonts': { defaultUiFontSize: () => 14, fontSelectionLabel: () => 'Terminus', getDefaultSmallFont: () => font('detail'),
getUiFontSelection: () => ({ kind: 'ttf', file: 'Roboto-Light.ttf', size: 14 }), setUiFontSelection: () => assert.fail('nothing to save'),
uiFontSizeAllowed: () => true },
'../../ui/font-picker': { FONT_SIZE_CHOICES: [8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 24] },
'../../ui/menu-core': { Menu: class { constructor(options) { menuOptions = options; return menu; } } },
'../../ui/metrics': { LIST_ROW_TEXT_INSET: 4, listRowHeight: (f) => f.lineHeight + 8 },
});
const { TextSizePage } = load('app/apps/onboarding/text-size-page.ts');
const page = new TextSizePage();
page.enter();
assert.equal(menu.selectedItem, 14);
const notes = menu.items.filter((size) => {
const row = recorder(200, 32);
menuOptions.draw({ image: row, item: size, x: 0, y: 0, width: 200, height: 32, selected: false });
return row.calls.some((call) => call.text === 'Recommended');
});
assert.deepEqual(notes, [14]);
// Taking the default leaves the size unset, so it keeps following the glasses.
page.handleInput({ type: 'click' }, { next: () => {} });
});
test('on a RayNeo iO the layout page recommends and starts on Left, and fits the 540x220 screen', () => {
const { load, settings } = harness('rayneo-io');
const { LayoutPage, recommendedLayout } = load('app/apps/onboarding/layout-page.ts');
assert.equal(recommendedLayout(), 'left');
const page = new LayoutPage();
const image = recorder(540, 220);
page.paint(image, true);
const captions = image.calls.filter((call) => call.kind === 'text').map((call) => call.text);
assert.ok(captions.includes('Left (Recommended)'));
assert.ok(captions.includes('Bottom'));
page.handleInput({ type: 'click' }, { next() {} });
assert.deepEqual(settings.appSwitcherPositionSetting.writes, ['left']);
// The G2 still recommends Bottom.
assert.equal(harness().load('app/apps/onboarding/layout-page.ts').recommendedLayout(), 'bottom');
});
test('the depth page follows layouts that have depth, sits in the layout, and applies depth as it scrolls', () => {
const { load, settings } = harness();
const menu = { selected: 0, items: [], select(index) { this.selected = index; },
+23 -1
View File
@@ -22,7 +22,7 @@ const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/te
const textwrap = load('app/graphics/textwrap.ts', {});
const fonts = { getDefaultSmallFont: () => font };
const menu = load('app/ui/menu.ts', {
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
'../graphics/image': graphics, '../graphics/textwrap': textwrap, '../graphics/ui-fonts': fonts,
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, './gestures': {},
'./metrics': metrics, './menu-core': menuCore,
@@ -111,3 +111,25 @@ test('the selected row stays clear of its description band', async () => {
assert.ok(row.y + row.source.height <= bandTop, `row ends at ${row.y + row.source.height}, band starts at ${bandTop}`);
assert.ok(row.y + row.source.height > bandTop - 30, 'the last item scrolled down to just above the band');
});
test('a section\'s detail gives its rows the pane while focus is in them, where the two don\'t fit (a RayNeo iO\'s window)', async () => {
const docs = ['README', 'License', 'Privacy policy', 'Acknowledgements'];
const detailDraws = [];
// About's blurb under its 72px logo: about 145px.
const about = { label: 'About', items: docs.map((label) => ({ label, onSelect() {} })),
renderDetail: ({ image, x, y }) => { detailDraws.push(image); image.fillRect(x, y, 72, 72, 90); return 145; } };
for (const [size, keeps] of [[{ width: 576, height: 260 }, true], [{ width: 476, height: 192 }, false], [{ width: 476, height: 155 }, false]]) {
const layer = new SettingsPanelLayer([about]);
const ctx = { stack: { getBaseSize: () => size, isFocused: () => true } };
const paint = () => { detailDraws.length = 0; const image = layer.paint(ctx); return { image, drawn: detailDraws.includes(image) }; };
// The preview (focus in the left column) always shows the detail.
assert.equal(paint().drawn, true, `preview at ${size.height}`);
await layer.handleInput({ type: 'click', timestampMs: 0 }, ctx);
const { image, drawn } = paint();
assert.equal(drawn, keeps, `focused at ${size.height}`);
const row = selections(image)[1];
if (keeps) assert.ok(row.y >= 8 + 145, 'the rows under the detail');
else assert.equal(row.y, 8, 'the first row at the top of the pane');
assert.ok(row.y + row.source.height <= size.height - 8);
}
});
+45
View File
@@ -0,0 +1,45 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
// ui-fonts.ts and screen-size.ts over an in-memory settings store, with each
// TTF "loaded" as its path and size.
function fixture(entries = []) {
const store = new Map(entries);
const listeners = [];
const load = loader({}, {
'../native/settings-store': {
getStringSetting: (key, fallback) => store.get(key) ?? fallback,
setStringSetting: (key, value) => { store.set(key, value); for (const listener of listeners) listener(key); },
onSettingsStoreChanged: (listener) => listeners.push(listener),
},
'./image': { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480, RAYNEO_IO_WIDTH: 540, RAYNEO_IO_HEIGHT: 220 },
'./bdffont': { getFont: (name) => ({ name }) },
'./ttf-font': { TtfFont: { load: (path, size) => ({ path, size, lineHeight: size + 4 }) } },
'./installed-fonts': { ensurePreinstalledFonts() {}, getInstalledFont: () => null, installedFontPath: (file) => `/fonts/${file}` },
});
return { fonts: load('app/graphics/ui-fonts.ts'), screen: load('app/graphics/screen-size.ts'), store, listeners };
}
test('the screen and the default UI font follow the paired glasses: 640x480 at 16px, or a RayNeo iO\'s 540x220 at 14px', () => {
const { fonts, screen, store, listeners } = fixture();
assert.deepEqual([screen.screenWidth(), screen.screenHeight(), screen.isRayNeoIoConfigured()], [640, 480, false]);
assert.equal(fonts.defaultUiFontSize(), 16);
assert.deepEqual({ ...fonts.getUiFontSelection() }, { kind: 'ttf', file: 'Roboto-Light.ttf', size: 16 });
assert.equal(fonts.getDefaultSmallFont().size, 16);
// Pairing a RayNeo iO: the cached fonts re-resolve at its size.
store.set(screen.GLASSES_TYPE_KEY, 'rayneo-io');
for (const listener of listeners) listener(screen.GLASSES_TYPE_KEY);
assert.deepEqual([screen.screenWidth(), screen.screenHeight(), screen.isRayNeoIoConfigured()], [540, 220, true]);
assert.equal(fonts.defaultUiFontSize(), 14);
assert.deepEqual({ ...fonts.getUiFontSelection() }, { kind: 'ttf', file: 'Roboto-Light.ttf', size: 14 });
assert.equal(fonts.getDefaultSmallFont().size, 14);
});
test('a chosen UI font keeps its size on either glasses', () => {
const { fonts, screen, store } = fixture([['deviceType', 'rayneo-io']]);
fonts.setUiFontSelection({ kind: 'ttf', file: 'Roboto-Light.ttf', size: 17 });
assert.equal(fonts.getUiFontSelection().size, 17);
store.set(screen.GLASSES_TYPE_KEY, 'g2');
assert.equal(fonts.getUiFontSelection().size, 17);
});