Adjust UI to account for user-configured variable font size
This commit is contained in:
1 parent
96842ceb23
commit
eef9fbaab4
25 files changed
+350
-222
No files matched your search
@@ -7,12 +7,12 @@ import { timeFormatSetting } from "../../ui/dashboard-settings";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
|
||||
import { hasCalendarPermission } from "../../g2/android-permissions";
|
||||
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
|
||||
const PAGE_X = 12;
|
||||
const PAGE_Y = 12;
|
||||
const LIST_TOP = 38;
|
||||
const ROW_X = 16;
|
||||
const LINE_HEIGHT = 14;
|
||||
const DAY_HEADER_HEIGHT = 16;
|
||||
const ROW_GAP = 4;
|
||||
const MAX_EVENTS = 50;
|
||||
@@ -57,7 +57,7 @@ export class CalendarLayer implements Layer {
|
||||
return image;
|
||||
}
|
||||
|
||||
const rows = buildEventRows(events);
|
||||
const rows = buildEventRows(font, events);
|
||||
this.selectedIndex = clamp(this.selectedIndex, 0, rows.length - 1);
|
||||
image.drawText(font, width - 96, PAGE_Y + 9, `${this.selectedIndex + 1}/${rows.length}`, 150);
|
||||
|
||||
@@ -81,7 +81,7 @@ export class CalendarLayer implements Layer {
|
||||
if (event.type === "click") this.requestPermission();
|
||||
return;
|
||||
}
|
||||
const rows = buildEventRows(readUpcomingEvents(MAX_EVENTS));
|
||||
const rows = buildEventRows(getDefaultSmallFont(), readUpcomingEvents(MAX_EVENTS));
|
||||
if (!rows.length) return;
|
||||
if (event.type === "scroll-up") {
|
||||
this.selectedIndex = Math.max(0, this.selectedIndex - 1);
|
||||
@@ -94,13 +94,13 @@ export class CalendarLayer implements Layer {
|
||||
const message = "Grant calendar permission on your phone to see your events on the glasses.";
|
||||
const lines = wrapText(font, message, width - 48);
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
image.drawText(font, 24, 72 + index * LINE_HEIGHT, lines[index]!, 190);
|
||||
image.drawText(font, 24, 72 + index * lineStep(font), lines[index]!, 190);
|
||||
}
|
||||
image.drawText(font, 24, height - 36, `${GESTURE_CLICK} request ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
}
|
||||
}
|
||||
|
||||
function buildEventRows(events: CalendarEvent[]): EventRow[] {
|
||||
function buildEventRows(font: UiFont, events: CalendarEvent[]): EventRow[] {
|
||||
const rows: EventRow[] = [];
|
||||
let previousDayKey = "";
|
||||
for (const event of events) {
|
||||
@@ -119,7 +119,7 @@ function buildEventRows(events: CalendarEvent[]): EventRow[] {
|
||||
event,
|
||||
dayHeader,
|
||||
lines,
|
||||
height: (dayHeader ? DAY_HEADER_HEIGHT : 0) + 6 + lines.length * LINE_HEIGHT,
|
||||
height: (dayHeader ? DAY_HEADER_HEIGHT : 0) + 6 + lines.length * lineStep(font),
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
@@ -139,7 +139,7 @@ function drawEventRow(
|
||||
image.drawText(font, x, cursorY + 2, row.dayHeader, 150);
|
||||
cursorY += DAY_HEADER_HEIGHT;
|
||||
}
|
||||
const bodyHeight = row.lines.length * LINE_HEIGHT + 4;
|
||||
const bodyHeight = row.lines.length * lineStep(font) + 4;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(x - 6, cursorY, width - 2 * (x - 6), bodyHeight, 15, 6);
|
||||
image.drawRoundedRect(x - 6, cursorY, width - 2 * (x - 6), bodyHeight, 90, 6);
|
||||
@@ -147,7 +147,7 @@ function drawEventRow(
|
||||
const maxTextWidth = width - 2 * x;
|
||||
for (let index = 0; index < row.lines.length; index++) {
|
||||
const value = index === 0 ? (selected ? 235 : 205) : 160;
|
||||
image.drawText(font, x, cursorY + 3 + index * LINE_HEIGHT, truncateText(font, row.lines[index]!, maxTextWidth), value);
|
||||
image.drawText(font, x, cursorY + 3 + index * lineStep(font), truncateText(font, row.lines[index]!, maxTextWidth), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { clamp } from "../../util/numeric-util";
|
||||
import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../../ui/layers";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
import { drawSelectionHighlight, scrollToKeepSelectionVisible } from "../../ui/menu";
|
||||
import { tightRowHeight } from "../../ui/metrics";
|
||||
import {
|
||||
buildSoundSequencePayload,
|
||||
CFW_SEQ_MAX,
|
||||
@@ -14,7 +15,6 @@ import {
|
||||
} from "../../ui/sound-effects";
|
||||
|
||||
const HEADER_HEIGHT = 30;
|
||||
const ROW_HEIGHT = 16;
|
||||
const LIST_X = 20;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
|
||||
@@ -42,16 +42,17 @@ export class BuzzerDemoLayer implements Layer {
|
||||
image.drawText(font, width - 24 - font.measureText(status), 8, status, 140);
|
||||
|
||||
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT;
|
||||
const visibleRows = Math.max(1, (listHeight / ROW_HEIGHT) | 0);
|
||||
const rowH = tightRowHeight(font);
|
||||
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedIndex, visibleRows, SOUND_EFFECTS.length);
|
||||
|
||||
const lastVisible = Math.min(SOUND_EFFECTS.length, this.scrollRow + visibleRows);
|
||||
for (let index = this.scrollRow; index < lastVisible; index++) {
|
||||
const effect = SOUND_EFFECTS[index]!;
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT;
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * rowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4);
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, rowH - 1, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
image.drawText(font, LIST_X, y + 1, effect.name, selected ? 255 : 200);
|
||||
image.drawText(font, LIST_X + 110, y + 1, effect.desc, selected ? 180 : 120);
|
||||
|
||||
@@ -3,14 +3,12 @@ import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawSelectionHighlight } from "../../ui/menu";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
|
||||
|
||||
const DIALOG_X = 8;
|
||||
const DIALOG_Y = 8;
|
||||
const DIALOG_WIDTH = 272;
|
||||
const PADDING = 10;
|
||||
const HEADER_STEP = 16;
|
||||
const SERVICE_STEP = 15;
|
||||
const ACTION_ROW_HEIGHT = 20;
|
||||
|
||||
const SERVICE_LABELS: Record<string, string> = {
|
||||
openai: "OpenAI",
|
||||
@@ -47,31 +45,34 @@ export class EvenHubApiKeyDialogLayer implements Layer {
|
||||
const textWidth = DIALOG_WIDTH - 2 * PADDING - 4;
|
||||
const left = DIALOG_X + PADDING + 2;
|
||||
|
||||
const bodyTop = PADDING + HEADER_STEP + 6 + this.services.length * SERVICE_STEP + 8;
|
||||
const height = Math.min(bodyTop + 2 * ACTION_ROW_HEIGHT + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
const headerStep = lineStep(font) + 2;
|
||||
const serviceStep = lineStep(font) + 1;
|
||||
const actionRowH = listRowHeight(font);
|
||||
const bodyTop = PADDING + headerStep + 6 + this.services.length * serviceStep + 8;
|
||||
const height = Math.min(bodyTop + 2 * actionRowH + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
|
||||
image.fillRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 1);
|
||||
image.drawRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 72);
|
||||
|
||||
let y = DIALOG_Y + PADDING;
|
||||
image.drawText(font, left, y, truncateText(font, `${this.appName} wants your keys:`, textWidth), 235);
|
||||
y += HEADER_STEP + 6;
|
||||
y += headerStep + 6;
|
||||
|
||||
for (const service of this.services) {
|
||||
const label = SERVICE_LABELS[service.id] ?? service.id;
|
||||
const text = service.configured ? label : `${label} (not set)`;
|
||||
image.drawText(font, left + 8, y, truncateText(font, text, textWidth - 8), service.configured ? 220 : 130);
|
||||
y += SERVICE_STEP;
|
||||
y += serviceStep;
|
||||
}
|
||||
y += 4;
|
||||
|
||||
const focused = ctx.stack.isFocused();
|
||||
const actions = ["Allow", "Deny"];
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const rowY = y + index * ACTION_ROW_HEIGHT;
|
||||
const rowY = y + index * actionRowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, ACTION_ROW_HEIGHT - 1, focused, 8);
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, actionRowH - 1, focused, 8);
|
||||
}
|
||||
image.drawText(font, DIALOG_X + 22, rowY + 3, actions[index]!, selected ? 255 : 200);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,13 @@ import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } f
|
||||
import { drawSelectionHighlight } from "../../ui/menu";
|
||||
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
||||
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
||||
import { lineStep, listRowHeight } from "../../ui/metrics";
|
||||
|
||||
const DIALOG_X = 8;
|
||||
const DIALOG_Y = 8;
|
||||
const DIALOG_WIDTH = 272;
|
||||
const PADDING = 10;
|
||||
const HEADER_STEP = 16;
|
||||
const PERM_LABEL_STEP = 15;
|
||||
const PERM_DETAIL_STEP = 13;
|
||||
const PERM_GAP = 4;
|
||||
const ACTION_ROW_HEIGHT = 20;
|
||||
|
||||
/**
|
||||
* Confirmation dialog listing the permissions an EvenHub app declares, shown
|
||||
@@ -42,13 +39,17 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
const textWidth = DIALOG_WIDTH - 2 * PADDING - 4;
|
||||
const left = DIALOG_X + PADDING + 2;
|
||||
|
||||
const headerStep = lineStep(font) + 2;
|
||||
const permLabelStep = lineStep(font) + 1;
|
||||
const permDetailStep = lineStep(font) - 1;
|
||||
const actionRowH = listRowHeight(font);
|
||||
const permsHeight = this.permissions.reduce(
|
||||
(sum, permission) => sum + PERM_LABEL_STEP + (permissionDetail(permission) ? PERM_DETAIL_STEP : 0) + PERM_GAP,
|
||||
(sum, permission) => sum + permLabelStep + (permissionDetail(permission) ? permDetailStep : 0) + PERM_GAP,
|
||||
0,
|
||||
);
|
||||
const emptyPermissionsHeight = this.permissions.length === 0 ? PERM_LABEL_STEP + PERM_GAP : 0;
|
||||
const bodyTop = PADDING + HEADER_STEP + 6 + permsHeight + emptyPermissionsHeight + 6;
|
||||
const height = Math.min(bodyTop + this.actions().length * ACTION_ROW_HEIGHT + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
const emptyPermissionsHeight = this.permissions.length === 0 ? permLabelStep + PERM_GAP : 0;
|
||||
const bodyTop = PADDING + headerStep + 6 + permsHeight + emptyPermissionsHeight + 6;
|
||||
const height = Math.min(bodyTop + this.actions().length * actionRowH + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
|
||||
// Fill 1 (transparent color key is 0), outline for the dialog edge.
|
||||
image.fillRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 1);
|
||||
@@ -57,7 +58,7 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
let y = DIALOG_Y + PADDING;
|
||||
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
||||
image.drawText(font, left, y, truncateText(font, heading, textWidth), 235);
|
||||
y += HEADER_STEP + 6;
|
||||
y += headerStep + 6;
|
||||
|
||||
if (this.permissions.length === 0) {
|
||||
image.drawText(font, left, y, "No special permissions requested.", 140);
|
||||
@@ -65,11 +66,11 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
}
|
||||
for (const permission of this.permissions) {
|
||||
image.drawText(font, left, y, truncateText(font, permissionLabel(permission.name), textWidth), 220);
|
||||
y += PERM_LABEL_STEP;
|
||||
y += permLabelStep;
|
||||
const detail = permissionDetail(permission);
|
||||
if (detail) {
|
||||
image.drawText(font, left + 8, y, truncateText(font, detail, textWidth - 8), 140);
|
||||
y += PERM_DETAIL_STEP;
|
||||
y += permDetailStep;
|
||||
}
|
||||
y += PERM_GAP;
|
||||
}
|
||||
@@ -78,10 +79,10 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
const focused = ctx.stack.isFocused();
|
||||
const actions = this.actions();
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const rowY = y + index * ACTION_ROW_HEIGHT;
|
||||
const rowY = y + index * actionRowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, ACTION_ROW_HEIGHT - 1, focused, 8);
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, actionRowH - 1, focused, 8);
|
||||
}
|
||||
image.drawText(font, DIALOG_X + 22, rowY + 3, actions[index]!, selected ? 255 : 200);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import {
|
||||
type EvenHubInstallIcon,
|
||||
} from "./installed-apps";
|
||||
import { EvenHubPermissionDialogLayer } from "./permission-dialog";
|
||||
import { lineStep, listRowHeight } from "../../ui/metrics";
|
||||
|
||||
const X = 18;
|
||||
const ACTION_HEIGHT = 24;
|
||||
|
||||
export type EvenHubStoreDetailOptions = {
|
||||
launchApp: (appId: string) => Promise<void> | void;
|
||||
@@ -43,18 +43,20 @@ export class EvenHubStoreDetailLayer implements Layer {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const textWidth = width - X * 2;
|
||||
const step = lineStep(font);
|
||||
const actionRowH = listRowHeight(font) + 4;
|
||||
let y = 8;
|
||||
|
||||
image.drawText(font, X, y, truncateText(font, this.app.name, textWidth), 235);
|
||||
y += 16;
|
||||
y += step + 2;
|
||||
const creator = this.app.creatorName ? `by ${this.app.creatorName}` : this.app.packageId;
|
||||
image.drawText(font, X, y, truncateText(font, creator, textWidth), 130);
|
||||
y += 20;
|
||||
y += step + 6;
|
||||
|
||||
const summary = this.app.tagline || this.app.description || "No description supplied.";
|
||||
for (const line of wrapText(font, summary, textWidth).slice(0, 3)) {
|
||||
image.drawText(font, X, y, line, 205);
|
||||
y += 14;
|
||||
y += step;
|
||||
}
|
||||
y += 4;
|
||||
|
||||
@@ -66,31 +68,31 @@ export class EvenHubStoreDetailLayer implements Layer {
|
||||
].filter(Boolean);
|
||||
for (const line of metadata) {
|
||||
image.drawText(font, X, y, truncateText(font, line, textWidth), 125);
|
||||
y += 14;
|
||||
y += step;
|
||||
}
|
||||
|
||||
const installed = getInstalledEvenHubApp(this.app.packageId);
|
||||
const actions = ["About", "What's New", this.working ? "Installing..." : installed ? "Launch" : "Install"];
|
||||
const actionTop = height - 22 - actions.length * ACTION_HEIGHT;
|
||||
const actionTop = height - font.lineHeight - 10 - actions.length * actionRowH;
|
||||
if (installed && !this.status) {
|
||||
image.drawText(font, X, y + 2, `Installed version ${installed.version}`, 155);
|
||||
}
|
||||
if (this.status) {
|
||||
image.drawText(font, X, Math.min(actionTop - 14, y + 2), truncateText(font, this.status, textWidth), 180);
|
||||
image.drawText(font, X, Math.min(actionTop - step, y + 2), truncateText(font, this.status, textWidth), 180);
|
||||
}
|
||||
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const actionY = actionTop + index * ACTION_HEIGHT;
|
||||
const actionY = actionTop + index * actionRowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, X - 5, actionY, textWidth + 10, ACTION_HEIGHT - 1, ctx.stack.isFocused(), 8);
|
||||
drawSelectionHighlight(image, X - 5, actionY, textWidth + 10, actionRowH - 1, ctx.stack.isFocused(), 8);
|
||||
}
|
||||
image.drawText(font, X + 6, actionY + 5, actions[index]!, this.working && index === 2 ? 145 : selected ? 245 : 190);
|
||||
}
|
||||
image.drawText(
|
||||
font,
|
||||
X,
|
||||
height - 16,
|
||||
height - font.lineHeight - 4,
|
||||
`${GESTURE_SCROLL} select ${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} back`,
|
||||
105,
|
||||
);
|
||||
|
||||
@@ -23,10 +23,10 @@ import {
|
||||
evenHubPasswordSetting,
|
||||
} from "./credentials";
|
||||
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
|
||||
const HEADER_HEIGHT = 34;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
const ROW_HEIGHT = 30;
|
||||
const LIST_X = 18;
|
||||
|
||||
export type EvenHubStoreLayerOptions = {
|
||||
@@ -89,7 +89,8 @@ export class EvenHubStoreLayer implements Layer {
|
||||
image.drawText(font, LIST_X, HEADER_HEIGHT + 28, truncateText(font, message, width - LIST_X * 2), 190);
|
||||
} else {
|
||||
this.selectedIndex = clamp(this.selectedIndex, 0, this.apps.length - 1);
|
||||
const visibleRows = Math.max(1, Math.floor((height - HEADER_HEIGHT - FOOTER_HEIGHT) / ROW_HEIGHT));
|
||||
const rowH = Math.max(30, 2 * lineStep(font) + 4);
|
||||
const visibleRows = Math.max(1, Math.floor((height - HEADER_HEIGHT - FOOTER_HEIGHT) / rowH));
|
||||
this.scrollRow = scrollToKeepSelectionVisible(
|
||||
this.scrollRow,
|
||||
this.selectedIndex,
|
||||
@@ -99,22 +100,22 @@ export class EvenHubStoreLayer implements Layer {
|
||||
const last = Math.min(this.apps.length, this.scrollRow + visibleRows);
|
||||
for (let index = this.scrollRow; index < last; index++) {
|
||||
const app = this.apps[index]!;
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT;
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * rowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, LIST_X - 6, y, width - LIST_X * 2 + 12, ROW_HEIGHT - 2, ctx.stack.isFocused(), 5);
|
||||
drawSelectionHighlight(image, LIST_X - 6, y, width - LIST_X * 2 + 12, rowH - 2, ctx.stack.isFocused(), 5);
|
||||
}
|
||||
image.drawText(font, LIST_X, y + 2, truncateText(font, app.name, width - LIST_X * 2), 215);
|
||||
const detail = app.tagline || `${app.creatorName} · ${formatCount(app.installCount)} installs`;
|
||||
image.drawText(font, LIST_X, y + 16, truncateText(font, detail, width - LIST_X * 2), 115);
|
||||
image.drawText(font, LIST_X, y + 2 + lineStep(font), truncateText(font, detail, width - LIST_X * 2), 115);
|
||||
}
|
||||
if (this.apps.length > visibleRows) {
|
||||
drawListScrollbar(image, width - 5, HEADER_HEIGHT, visibleRows * ROW_HEIGHT - 3, this.scrollRow, visibleRows, this.apps.length);
|
||||
drawListScrollbar(image, width - 5, HEADER_HEIGHT, visibleRows * rowH - 3, this.scrollRow, visibleRows, this.apps.length);
|
||||
}
|
||||
}
|
||||
|
||||
const hint = `${GESTURE_SCROLL} select ${GESTURE_CLICK} details ${GESTURE_DOUBLE_CLICK} back`;
|
||||
image.drawText(font, LIST_X, height - 16, truncateText(font, hint, width - LIST_X * 2), 105);
|
||||
image.drawText(font, LIST_X, height - font.lineHeight - 4, truncateText(font, hint, width - LIST_X * 2), 105);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { renderIcon, type IconName } from "../../graphics/icons";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
|
||||
import { lineStep, tightRowHeight } from "../../ui/metrics";
|
||||
import { ConfigSettingEnum } from "../../ui/dashboard-settings";
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
import {
|
||||
@@ -17,10 +18,12 @@ import {
|
||||
} from "../../native/file-access";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
|
||||
const HEADER_HEIGHT = 34;
|
||||
const ROW_HEIGHT = 16;
|
||||
const LIST_X = 20;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
|
||||
/** Header: title line + path line (34px at the 12px bitmap default). */
|
||||
function headerHeight(font: UiFont): number {
|
||||
return 8 + lineStep(font) + font.lineHeight;
|
||||
}
|
||||
|
||||
const GRID_COLS = 5;
|
||||
const GRID_VISIBLE_ROWS = 3;
|
||||
@@ -139,7 +142,7 @@ export class FileBrowserLayer implements Layer {
|
||||
|
||||
image.drawText(font, 20, 8, "Files", 220);
|
||||
const pathLabel = this.location === null ? "Places" : this.location;
|
||||
image.drawText(font, 20, 22, truncateLeft(font, pathLabel, width - 40), 130);
|
||||
image.drawText(font, 20, 8 + lineStep(font), truncateLeft(font, pathLabel, width - 40), 130);
|
||||
|
||||
if (filesViewModeSetting.get() === "list") {
|
||||
this.paintList(image, font, rows, ctx);
|
||||
@@ -153,23 +156,25 @@ export class FileBrowserLayer implements Layer {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
this.listIndex = clamp(this.listIndex, 0, Math.max(0, rows.length - 1));
|
||||
|
||||
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT;
|
||||
const visibleRows = Math.max(1, (listHeight / ROW_HEIGHT) | 0);
|
||||
const rowH = tightRowHeight(font);
|
||||
const headerH = headerHeight(font);
|
||||
const listHeight = height - headerH - font.lineHeight - 10;
|
||||
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.listIndex, visibleRows, rows.length);
|
||||
|
||||
const lastVisible = Math.min(rows.length, this.scrollRow + visibleRows);
|
||||
for (let index = this.scrollRow; index < lastVisible; index++) {
|
||||
const row = rows[index]!;
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT;
|
||||
const y = headerH + (index - this.scrollRow) * rowH;
|
||||
const selected = index === this.listIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4);
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, rowH - 1, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
const value = itemValue(row, selected);
|
||||
image.drawText(font, LIST_X, y + 1, truncateText(font, row.label, width - 2 * LIST_X), value);
|
||||
}
|
||||
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
}
|
||||
|
||||
private paintIcons(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
@@ -178,7 +183,7 @@ export class FileBrowserLayer implements Layer {
|
||||
const iconRows = buildIconRows(rows);
|
||||
this.selectedRow = clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1));
|
||||
|
||||
const gridTop = HEADER_HEIGHT;
|
||||
const gridTop = headerHeight(font);
|
||||
const gridBottom = height - GRID_BOTTOM_MARGIN;
|
||||
const rowH = Math.floor((gridBottom - gridTop) / GRID_VISIBLE_ROWS);
|
||||
const colW = width / GRID_COLS;
|
||||
@@ -232,7 +237,7 @@ export class FileBrowserLayer implements Layer {
|
||||
this.iconMode === "row"
|
||||
? `${GESTURE_SCROLL} row ${GESTURE_CLICK} pick ${GESTURE_DOUBLE_CLICK} up / back`
|
||||
: `${GESTURE_SCROLL} item ${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} row`;
|
||||
image.drawText(font, 20, height - 16, hint, 110);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, hint, 110);
|
||||
}
|
||||
|
||||
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
||||
|
||||
@@ -5,13 +5,12 @@ import type { DirectoryEntry } from "../../native/file-access";
|
||||
import { GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawSelectionHighlight } from "../../ui/menu";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
|
||||
|
||||
const DIALOG_X = 8;
|
||||
const DIALOG_Y = 8;
|
||||
const DIALOG_WIDTH = 272;
|
||||
const PADDING = 10;
|
||||
const INFO_LINE_STEP = 14;
|
||||
const ACTION_ROW_HEIGHT = 20;
|
||||
const MAX_NAME_LINES = 3;
|
||||
|
||||
export type FileInfoAction = {
|
||||
@@ -38,14 +37,16 @@ export class FileInfoDialogLayer implements Layer {
|
||||
const { height: viewportHeight } = ctx.stack.getBaseSize();
|
||||
const image = paintBelow();
|
||||
|
||||
const step = lineStep(font);
|
||||
const rowH = listRowHeight(font);
|
||||
const textWidth = DIALOG_WIDTH - 2 * PADDING - 4;
|
||||
const nameLines = wrapText(font, this.entry.name, textWidth, { breakLongWords: true }).slice(0, MAX_NAME_LINES);
|
||||
const infoLines = [
|
||||
`Size: ${formatSize(this.entry.sizeBytes)}`,
|
||||
`Modified: ${formatDate(this.entry.modifiedMs)}`,
|
||||
];
|
||||
const bodyTop = PADDING + (nameLines.length + infoLines.length) * INFO_LINE_STEP + 6;
|
||||
const bodyHeight = this.actions.length ? this.actions.length * ACTION_ROW_HEIGHT : INFO_LINE_STEP;
|
||||
const bodyTop = PADDING + (nameLines.length + infoLines.length) * step + 6;
|
||||
const bodyHeight = this.actions.length ? this.actions.length * rowH : step;
|
||||
const height = Math.min(bodyTop + bodyHeight + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
|
||||
// Fill 1, not 0: identical after 4bpp quantization, but 0 is the
|
||||
@@ -56,11 +57,11 @@ export class FileInfoDialogLayer implements Layer {
|
||||
let y = DIALOG_Y + PADDING;
|
||||
for (const line of nameLines) {
|
||||
image.drawText(font, DIALOG_X + PADDING + 2, y, line, 230);
|
||||
y += INFO_LINE_STEP;
|
||||
y += step;
|
||||
}
|
||||
for (const line of infoLines) {
|
||||
image.drawText(font, DIALOG_X + PADDING + 2, y, line, 150);
|
||||
y += INFO_LINE_STEP;
|
||||
y += step;
|
||||
}
|
||||
y += 6;
|
||||
|
||||
@@ -70,12 +71,12 @@ export class FileInfoDialogLayer implements Layer {
|
||||
}
|
||||
const focused = ctx.stack.isFocused();
|
||||
for (let index = 0; index < this.actions.length; index++) {
|
||||
const rowY = y + index * ACTION_ROW_HEIGHT;
|
||||
const rowY = y + index * rowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, ACTION_ROW_HEIGHT - 1, focused, 8);
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, rowH - 1, focused, 8);
|
||||
}
|
||||
image.drawText(font, DIALOG_X + 22, rowY + 3, this.actions[index]!.label, selected ? 255 : 200);
|
||||
image.drawText(font, DIALOG_X + 22, rowY + LIST_ROW_TEXT_INSET, this.actions[index]!.label, selected ? 255 : 200);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
drawSubmenuIndicator,
|
||||
scrollToKeepSelectionVisible,
|
||||
} from "../../ui/menu";
|
||||
import { lineStep, tightRowHeight } from "../../ui/metrics";
|
||||
import {
|
||||
mediaBrowserBridge,
|
||||
type MediaBrowseItem,
|
||||
@@ -16,10 +17,11 @@ import {
|
||||
} from "../../native/media-browser";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
|
||||
const HEADER_HEIGHT = 34;
|
||||
const ROW_HEIGHT = 16;
|
||||
/** Header: title line + path line (34px at the 12px bitmap default). */
|
||||
function headerHeight(font: UiFont): number {
|
||||
return 8 + lineStep(font) + font.lineHeight;
|
||||
}
|
||||
const LIST_X = 20;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
|
||||
export type MediaBrowseOptions = {
|
||||
app: MediaBrowserApp;
|
||||
@@ -67,49 +69,50 @@ export class MediaBrowseLayer implements Layer {
|
||||
image.drawText(font, 20, 8, `Library: ${this.options.app.appName}`, 220);
|
||||
|
||||
if (this.phase === "connecting" || this.phase === "idle") {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, `Starting ${this.options.app.appName}...`, 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, `Starting ${this.options.app.appName}...`, 150);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
if (this.phase === "failed") {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, "Could not connect:", 180);
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 24, truncateRight(font, this.connectError, width - 48), 140);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, "Could not connect:", 180);
|
||||
image.drawText(font, 24, headerHeight(font) + 8 + lineStep(font), truncateRight(font, this.connectError, width - 48), 140);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
const level = this.currentLevel();
|
||||
const path = this.levels.map((entry) => entry.title).join(" / ");
|
||||
image.drawText(font, 20, 22, truncateLeft(font, path, width - 40), 130);
|
||||
image.drawText(font, 20, 8 + lineStep(font), truncateLeft(font, path, width - 40), 130);
|
||||
|
||||
if (!level || level.items === null) {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, level?.error ? level.error : "Loading...", level?.error ? 140 : 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, level?.error ? level.error : "Loading...", level?.error ? 140 : 150);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
const items = level.items;
|
||||
if (!items.length) {
|
||||
image.drawText(font, 24, HEADER_HEIGHT + 8, "(empty)", 120);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
image.drawText(font, 24, headerHeight(font) + 8, "(empty)", 120);
|
||||
image.drawText(font, 20, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
level.selectedIndex = clamp(level.selectedIndex, 0, items.length - 1);
|
||||
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT;
|
||||
const visibleRows = Math.max(1, (listHeight / ROW_HEIGHT) | 0);
|
||||
const listHeight = height - headerHeight(font) - font.lineHeight - 10;
|
||||
const rowH = tightRowHeight(font);
|
||||
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
|
||||
level.scrollRow = scrollToKeepSelectionVisible(level.scrollRow, level.selectedIndex, visibleRows, items.length);
|
||||
|
||||
const rowWidth = width - 2 * LIST_X;
|
||||
const lastVisible = Math.min(items.length, level.scrollRow + visibleRows);
|
||||
for (let index = level.scrollRow; index < lastVisible; index++) {
|
||||
const item = items[index]!;
|
||||
const y = HEADER_HEIGHT + (index - level.scrollRow) * ROW_HEIGHT;
|
||||
const y = headerHeight(font) + (index - level.scrollRow) * rowH;
|
||||
const selected = index === level.selectedIndex;
|
||||
const highlightX = LIST_X - 6;
|
||||
const highlightY = y - 1;
|
||||
const highlightWidth = rowWidth + 12;
|
||||
const highlightHeight = ROW_HEIGHT - 1;
|
||||
const highlightHeight = rowH - 1;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, highlightX, highlightY, highlightWidth, highlightHeight, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
@@ -131,8 +134,8 @@ export class MediaBrowseLayer implements Layer {
|
||||
drawListScrollbar(
|
||||
image,
|
||||
width - 12,
|
||||
HEADER_HEIGHT,
|
||||
visibleRows * ROW_HEIGHT - 4,
|
||||
headerHeight(font),
|
||||
visibleRows * rowH - 4,
|
||||
level.scrollRow,
|
||||
visibleRows,
|
||||
items.length,
|
||||
|
||||
+17
-15
@@ -10,6 +10,7 @@ import {
|
||||
GESTURE_SCROLL_UP,
|
||||
} from "../../ui/gestures";
|
||||
import { MenuLayer, drawSelectionHighlight, drawSubmenuIndicator } from "../../ui/menu";
|
||||
import { lineStep, tightRowHeight } from "../../ui/metrics";
|
||||
import {
|
||||
mediaControllerBridge,
|
||||
type MediaControllerState,
|
||||
@@ -33,7 +34,6 @@ const ART_X = 22;
|
||||
const ART_Y = 8;
|
||||
const META_X = ART_X + ART_SIZE + 14;
|
||||
const LIST_TOP = 120;
|
||||
const ROW_HEIGHT = 16;
|
||||
const ACTION_X = 22;
|
||||
const ACTION_WIDTH = 154;
|
||||
const COLUMN_DIVIDER_X = 190;
|
||||
@@ -81,7 +81,7 @@ class MusicAppLayer implements Layer {
|
||||
width - 48,
|
||||
);
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
image.drawText(font, 24, 16 + index * 14, lines[index]!, 180);
|
||||
image.drawText(font, 24, 16 + index * lineStep(font), lines[index]!, 180);
|
||||
}
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open settings ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
@@ -90,11 +90,11 @@ class MusicAppLayer implements Layer {
|
||||
if (!media.available) {
|
||||
image.drawText(font, 24, 16, "No active media session.", 180);
|
||||
if (mediaBrowserBridge.listBrowsableApps().length) {
|
||||
image.drawText(font, 24, 34, "Click to browse a music app's library,", 150);
|
||||
image.drawText(font, 24, 48, "or start playback on the phone.", 150);
|
||||
image.drawText(font, 24, 22 + lineStep(font), "Click to browse a music app's library,", 150);
|
||||
image.drawText(font, 24, 22 + 2 * lineStep(font), "or start playback on the phone.", 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} browse ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
} else {
|
||||
image.drawText(font, 24, 34, "Start playback in another app on the phone.", 150);
|
||||
image.drawText(font, 24, 22 + lineStep(font), "Start playback in another app on the phone.", 150);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
}
|
||||
return image;
|
||||
@@ -103,22 +103,24 @@ class MusicAppLayer implements Layer {
|
||||
this.drawArt(image, media);
|
||||
|
||||
const metaWidth = width - META_X - 24;
|
||||
const metaStep = lineStep(font) + 1;
|
||||
const titleLines = wrapText(font, media.title || "Unknown title", metaWidth).slice(0, 2);
|
||||
for (let index = 0; index < titleLines.length; index++) {
|
||||
image.drawText(font, META_X, ART_Y + 2 + index * 15, titleLines[index]!, 230);
|
||||
image.drawText(font, META_X, ART_Y + 2 + index * metaStep, titleLines[index]!, 230);
|
||||
}
|
||||
image.drawText(font, META_X, ART_Y + 36, media.artist || "Unknown artist", 180);
|
||||
image.drawText(font, META_X, ART_Y + 6 + 2 * metaStep, media.artist || "Unknown artist", 180);
|
||||
if (media.album) {
|
||||
image.drawText(font, META_X, ART_Y + 52, truncateText(font, media.album, metaWidth), 150);
|
||||
image.drawText(font, META_X, ART_Y + 6 + 3 * metaStep, truncateText(font, media.album, metaWidth), 150);
|
||||
}
|
||||
image.drawText(font, META_X, ART_Y + 68, truncateText(font, media.appName || media.packageName, metaWidth), 110);
|
||||
image.drawText(font, META_X, ART_Y + 6 + 4 * metaStep, truncateText(font, media.appName || media.packageName, metaWidth), 110);
|
||||
this.drawProgress(image, media, metaWidth);
|
||||
|
||||
const queue = mediaControllerBridge.getQueue();
|
||||
const actions = this.buildActions(media, queue);
|
||||
this.reconcileSelection(actions, queue);
|
||||
const listHeight = height - LIST_TOP - FOOTER_HEIGHT;
|
||||
const visibleRows = Math.max(1, (listHeight / ROW_HEIGHT) | 0);
|
||||
const rowH = tightRowHeight(font);
|
||||
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
|
||||
if (this.selectedQueueIndex < this.queueScrollRow) {
|
||||
this.queueScrollRow = this.selectedQueueIndex;
|
||||
} else if (this.selectedQueueIndex >= this.queueScrollRow + visibleRows) {
|
||||
@@ -128,12 +130,12 @@ class MusicAppLayer implements Layer {
|
||||
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const action = actions[index]!;
|
||||
const y = LIST_TOP + index * ROW_HEIGHT;
|
||||
const y = LIST_TOP + index * rowH;
|
||||
const selected = index === this.selectedActionIndex;
|
||||
const highlightX = ACTION_X - 6;
|
||||
const highlightY = y - 1;
|
||||
const highlightWidth = ACTION_WIDTH + 8;
|
||||
const highlightHeight = ROW_HEIGHT - 1;
|
||||
const highlightHeight = rowH - 1;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(
|
||||
image,
|
||||
@@ -160,7 +162,7 @@ class MusicAppLayer implements Layer {
|
||||
const lastVisible = Math.min(queue.length, this.queueScrollRow + visibleRows);
|
||||
for (let index = this.queueScrollRow; index < lastVisible; index++) {
|
||||
const item = queue[index]!;
|
||||
const y = LIST_TOP + (index - this.queueScrollRow) * ROW_HEIGHT;
|
||||
const y = LIST_TOP + (index - this.queueScrollRow) * rowH;
|
||||
const selected = index === this.selectedQueueIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(
|
||||
@@ -168,7 +170,7 @@ class MusicAppLayer implements Layer {
|
||||
QUEUE_X - 6,
|
||||
y - 1,
|
||||
queueWidth + 8,
|
||||
ROW_HEIGHT - 1,
|
||||
rowH - 1,
|
||||
ctx.stack.isFocused() && this.focusColumn === "playlist",
|
||||
4,
|
||||
);
|
||||
@@ -177,7 +179,7 @@ class MusicAppLayer implements Layer {
|
||||
image.drawText(font, QUEUE_X, y + 1, truncateText(font, label, queueWidth - 4), selected ? 255 : 200);
|
||||
}
|
||||
if (queue.length > visibleRows) {
|
||||
const trackHeight = visibleRows * ROW_HEIGHT - 4;
|
||||
const trackHeight = visibleRows * rowH - 4;
|
||||
const trackX = width - 12;
|
||||
image.fillRect(trackX, LIST_TOP, 3, trackHeight, 30);
|
||||
const thumbHeight = Math.max(8, (trackHeight * visibleRows / queue.length) | 0);
|
||||
|
||||
@@ -69,6 +69,7 @@ import {
|
||||
scrollToKeepSelectionVisible,
|
||||
type MenuItem,
|
||||
} from "../../ui/menu";
|
||||
import { lineStep, listRowHeight } from "../../ui/metrics";
|
||||
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu";
|
||||
import { appViewportSize } from "../../ui/shell/geometry";
|
||||
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
|
||||
@@ -97,7 +98,6 @@ function viewGrid(): { cols: number; rows: number } {
|
||||
};
|
||||
}
|
||||
const DEVICE_NAME = "Faceclaw G2";
|
||||
const HUB_ROW_HEIGHT = 20;
|
||||
const RENDER_COALESCE_MS = 33;
|
||||
const HISTORY_PAGE = 200;
|
||||
// Auto-reconnect backoff: doubles per failed attempt, resets on success.
|
||||
@@ -1402,24 +1402,28 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
return paintAddConnection(window);
|
||||
}
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
const font = chromeFont();
|
||||
const step = lineStep(font);
|
||||
// No border box: the shell chrome (top bar + sidebar) already frames the app.
|
||||
image.drawText(chromeFont(), 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
|
||||
image.drawText(chromeFont(), 24, 30, hubStatusLine(window), 170);
|
||||
image.drawText(font, 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
|
||||
const statusY = 16 + step;
|
||||
image.drawText(font, 24, statusY, hubStatusLine(window), 170);
|
||||
|
||||
let listTop = 52;
|
||||
let listTop = statusY + step + 8;
|
||||
if (window.mode === "sessions" && controls.size === 0) {
|
||||
image.drawText(chromeFont(), 24, 46, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(chromeFont(), 24, 60, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
listTop += 28;
|
||||
image.drawText(font, 24, statusY + step + 2, "Add a g2mirror:// connection to get started, see:", 150);
|
||||
image.drawText(font, 24, statusY + 2 * step + 2, "https://github.com/jimrandomh/g2mirror", 190);
|
||||
listTop += 2 * step;
|
||||
}
|
||||
|
||||
const items = hubItems(window);
|
||||
clampHubSelection(window, items);
|
||||
const visibleRowCount = Math.max(1, ((window.viewportHeight - 30 - listTop) / HUB_ROW_HEIGHT) | 0);
|
||||
const hubRowH = listRowHeight(chromeFont());
|
||||
const visibleRowCount = Math.max(1, ((window.viewportHeight - 30 - listTop) / hubRowH) | 0);
|
||||
window.scrollRow = scrollToKeepSelectionVisible(window.scrollRow, window.selectedIndex, visibleRowCount, items.length);
|
||||
const lastVisibleRow = Math.min(items.length, window.scrollRow + visibleRowCount);
|
||||
for (let index = window.scrollRow; index < lastVisibleRow; index++) {
|
||||
const y = listTop + (index - window.scrollRow) * HUB_ROW_HEIGHT;
|
||||
const y = listTop + (index - window.scrollRow) * hubRowH;
|
||||
const item = items[index]!;
|
||||
if (item.heading) {
|
||||
image.drawText(chromeFont(), 20, y + 2, item.label, 140);
|
||||
@@ -1429,7 +1433,7 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
if (selected) {
|
||||
// Match the shell convention: fill only when this window has focus, so
|
||||
// an outline-only selection signals the sidebar owns input.
|
||||
drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, HUB_ROW_HEIGHT - 1, window.focused, 8);
|
||||
drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, hubRowH - 1, window.focused, 8);
|
||||
}
|
||||
image.drawText(chromeFont(), 32, y + 2, item.label, selected ? 255 : 200);
|
||||
}
|
||||
@@ -1438,28 +1442,32 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
image,
|
||||
window.viewportWidth - 10,
|
||||
listTop,
|
||||
visibleRowCount * HUB_ROW_HEIGHT - 4,
|
||||
visibleRowCount * hubRowH - 4,
|
||||
window.scrollRow,
|
||||
visibleRowCount,
|
||||
items.length,
|
||||
);
|
||||
}
|
||||
|
||||
image.drawText(chromeFont(), 24, window.viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, 24, window.viewportHeight - font.lineHeight - 12, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
function paintAddConnection(window: HubWindow): GrayImage {
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
image.drawText(chromeFont(), 18, 10, "Add connection", 220);
|
||||
image.drawText(chromeFont(), 24, 34, "Type the g2mirror://token@host string in the", 170);
|
||||
image.drawText(chromeFont(), 24, 48, "phone app (or use voice input from the menu).", 170);
|
||||
const font = chromeFont();
|
||||
const step = lineStep(font);
|
||||
image.drawText(font, 18, 10, "Add connection", 220);
|
||||
const instructionsY = 20 + step;
|
||||
image.drawText(font, 24, instructionsY, "Type the g2mirror://token@host string in the", 170);
|
||||
image.drawText(font, 24, instructionsY + step, "phone app (or use voice input from the menu).", 170);
|
||||
const draftY = instructionsY + 3 * step;
|
||||
const draft = terminalNewConnectionSetting.get();
|
||||
image.drawText(chromeFont(), 24, 76, truncateLabel(draft || "(empty)", 52), 220);
|
||||
image.drawText(font, 24, draftY, truncateLabel(draft || "(empty)", 52), 220);
|
||||
if (window.addError) {
|
||||
image.drawText(chromeFont(), 24, 96, window.addError, 150);
|
||||
image.drawText(font, 24, draftY + step + 6, window.addError, 150);
|
||||
}
|
||||
image.drawText(chromeFont(), 24, window.viewportHeight - 24, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
|
||||
image.drawText(font, 24, window.viewportHeight - font.lineHeight - 12, `click save ${GESTURE_DOUBLE_CLICK} cancel`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -1513,8 +1521,9 @@ function drawGridRow(
|
||||
function paintView(window: ViewWindow): GrayImage {
|
||||
const image = new GrayImage(window.viewportWidth, window.viewportHeight, 0);
|
||||
if (!window.receivedData) {
|
||||
image.drawText(chromeFont(), 24, 110, window.status, 170);
|
||||
image.drawText(chromeFont(), 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
const font = chromeFont();
|
||||
image.drawText(font, 24, 110, window.status, 170);
|
||||
image.drawText(font, 24, 116 + lineStep(font), `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* durable expiry path; worker timeouts keep the live UI prompt.
|
||||
*/
|
||||
import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { type UiFont, GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getFont } from "../../graphics/bdffont";
|
||||
@@ -36,7 +36,10 @@ const FOOTER_HEIGHT = 34;
|
||||
|
||||
const largeFont = getFont("terminus32");
|
||||
const mediumFont = getFont("terminus24");
|
||||
const smallFont = getDefaultSmallFont();
|
||||
// Resolved per use so a font-setting change applies without a worker restart.
|
||||
function smallFont(): UiFont {
|
||||
return getDefaultSmallFont();
|
||||
}
|
||||
|
||||
type TimerView = "stopwatch" | "timers" | "editor";
|
||||
|
||||
@@ -529,7 +532,7 @@ function paintStopwatch(image: GrayImage, window: TimerWindow): void {
|
||||
image.drawText(largeFont, timeX, 66, timeLabel, 245);
|
||||
|
||||
const state = stopwatchRunningSinceMs === null ? (elapsed > 0 ? "Paused" : "Ready") : "Running";
|
||||
drawCenteredText(image, smallFont, 112, state, 145);
|
||||
drawCenteredText(image, smallFont(), 112, state, 145);
|
||||
|
||||
const labels = [stopwatchRunningSinceMs === null ? "Start" : "Pause", "Reset", `Timers (${timers.length})`];
|
||||
drawButtonRow(image, labels, window.stopwatchAction, 154);
|
||||
@@ -552,7 +555,7 @@ function paintTimers(image: GrayImage, window: TimerWindow): void {
|
||||
image.fillRoundedRect(18, y, image.width - 36, TIMER_ROW_HEIGHT - 4, 34, 5);
|
||||
image.drawRect(18, y, image.width - 36, TIMER_ROW_HEIGHT - 4, 105);
|
||||
}
|
||||
image.drawText(index >= 2 ? mediumFont : smallFont, 32, y + (index >= 2 ? 2 : 7), items[index]!, selected ? 245 : 180);
|
||||
image.drawText(index >= 2 ? mediumFont : smallFont(), 32, y + (index >= 2 ? 2 : 7), items[index]!, selected ? 245 : 180);
|
||||
}
|
||||
|
||||
const selectedTimer = window.timerSelection >= 2 ? timers[window.timerSelection - 2] : null;
|
||||
@@ -561,7 +564,7 @@ function paintTimers(image: GrayImage, window: TimerWindow): void {
|
||||
}
|
||||
|
||||
function paintEditor(image: GrayImage, window: TimerWindow): void {
|
||||
image.drawText(smallFont, 24, 14, "New timer", 190);
|
||||
image.drawText(smallFont(), 24, 14, "New timer", 190);
|
||||
const fields = [pad2(window.editorHours), pad2(window.editorMinutes), pad2(window.editorSeconds)];
|
||||
const labels = ["hours", "minutes", "seconds"];
|
||||
const fieldWidth = 118;
|
||||
@@ -576,7 +579,7 @@ function paintEditor(image: GrayImage, window: TimerWindow): void {
|
||||
image.drawRect(x, 57, fieldWidth, 68, 120);
|
||||
}
|
||||
drawCenteredIn(image, largeFont, x, fieldWidth, 65, fields[index]!, window.editorField === index ? 250 : 180);
|
||||
drawCenteredIn(image, smallFont, x, fieldWidth, 105, labels[index]!, 125);
|
||||
drawCenteredIn(image, smallFont(), x, fieldWidth, 105, labels[index]!, 125);
|
||||
if (index < 2) image.drawText(mediumFont, x + fieldWidth + 5, 71, ":", 130);
|
||||
}
|
||||
|
||||
@@ -587,8 +590,8 @@ function paintEditor(image: GrayImage, window: TimerWindow): void {
|
||||
image.fillRoundedRect(buttonX, 151, buttonWidth, 38, 40, 6);
|
||||
image.drawRect(buttonX, 151, buttonWidth, 38, 120);
|
||||
}
|
||||
drawCenteredIn(image, smallFont, buttonX, buttonWidth, 162, "Start timer", startSelected ? 250 : 175);
|
||||
if (window.editorMessage) drawCenteredText(image, smallFont, 202, window.editorMessage, 190);
|
||||
drawCenteredIn(image, smallFont(), buttonX, buttonWidth, 162, "Start timer", startSelected ? 250 : 175);
|
||||
if (window.editorMessage) drawCenteredText(image, smallFont(), 202, window.editorMessage, 190);
|
||||
drawFooter(image, `${GESTURE_SCROLL} adjust ${GESTURE_CLICK} next ${GESTURE_DOUBLE_CLICK} cancel`);
|
||||
}
|
||||
|
||||
@@ -596,11 +599,11 @@ function drawTabs(image: GrayImage, active: "stopwatch" | "timers"): void {
|
||||
const stopwatch = "Stopwatch";
|
||||
const timerLabel = `Timers (${timers.length})`;
|
||||
const left = 24;
|
||||
const dividerX = left + smallFont.measureText(stopwatch) + 18;
|
||||
image.drawText(smallFont, left, 15, stopwatch, active === "stopwatch" ? 245 : 105);
|
||||
const dividerX = left + smallFont().measureText(stopwatch) + 18;
|
||||
image.drawText(smallFont(), left, 15, stopwatch, active === "stopwatch" ? 245 : 105);
|
||||
image.drawLine(left, 35, dividerX - 12, 35, active === "stopwatch" ? 200 : 30);
|
||||
image.drawText(smallFont, dividerX, 15, timerLabel, active === "timers" ? 245 : 105);
|
||||
image.drawLine(dividerX, 35, dividerX + smallFont.measureText(timerLabel), 35, active === "timers" ? 200 : 30);
|
||||
image.drawText(smallFont(), dividerX, 15, timerLabel, active === "timers" ? 245 : 105);
|
||||
image.drawLine(dividerX, 35, dividerX + smallFont().measureText(timerLabel), 35, active === "timers" ? 200 : 30);
|
||||
}
|
||||
|
||||
function drawButtonRow(image: GrayImage, labels: string[], selected: number, y: number): void {
|
||||
@@ -613,22 +616,22 @@ function drawButtonRow(image: GrayImage, labels: string[], selected: number, y:
|
||||
image.fillRoundedRect(x, y, width, 40, 38, 6);
|
||||
image.drawRect(x, y, width, 40, 115);
|
||||
}
|
||||
drawCenteredIn(image, smallFont, x, width, y + 12, labels[index]!, index === selected ? 245 : 155);
|
||||
drawCenteredIn(image, smallFont(), x, width, y + 12, labels[index]!, index === selected ? 245 : 155);
|
||||
}
|
||||
}
|
||||
|
||||
function drawFooter(image: GrayImage, text: string): void {
|
||||
image.drawLine(16, image.height - FOOTER_HEIGHT, image.width - 16, image.height - FOOTER_HEIGHT, 35);
|
||||
drawCenteredText(image, smallFont, image.height - 22, text, 115);
|
||||
drawCenteredText(image, smallFont(), image.height - 22, text, 115);
|
||||
}
|
||||
|
||||
function drawCenteredText(image: GrayImage, font: typeof smallFont, y: number, text: string, value: number): void {
|
||||
function drawCenteredText(image: GrayImage, font: UiFont, y: number, text: string, value: number): void {
|
||||
image.drawText(font, Math.round((image.width - font.measureText(text)) / 2), y, text, value);
|
||||
}
|
||||
|
||||
function drawCenteredIn(
|
||||
image: GrayImage,
|
||||
font: typeof smallFont,
|
||||
font: UiFont,
|
||||
x: number,
|
||||
width: number,
|
||||
y: number,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
import { writeTextToDownloads } from "../../native/file-access";
|
||||
import { voiceControlBridge, type VoiceTranscriptEvent } from "../../native/voice-control";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
@@ -41,12 +42,13 @@ export class TranscribeLayer implements Layer {
|
||||
image.drawText(font, 24, 20, "Transcribe", 200);
|
||||
image.drawText(font, 24, 40, this.saveNotice || this.status, 110);
|
||||
|
||||
const step = lineStep(font) + 2;
|
||||
const bodyTop = 62;
|
||||
const footerY = height - 18;
|
||||
const bodyLines = Math.max(1, Math.floor((footerY - bodyTop) / 16));
|
||||
const footerY = height - font.lineHeight - 6;
|
||||
const bodyLines = Math.max(1, Math.floor((footerY - bodyTop) / step));
|
||||
const firstLine = Math.max(0, wrapped.length - bodyLines);
|
||||
for (let index = firstLine; index < wrapped.length; index++) {
|
||||
const y = bodyTop + (index - firstLine) * 16;
|
||||
const y = bodyTop + (index - firstLine) * step;
|
||||
image.drawText(font, 32, y, wrapped[index]!, 230);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { type ForecastPeriod, type WeatherState } from "../../native/weather";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { drawSelectionHighlight, scrollToKeepSelectionVisible } from "../../ui/menu";
|
||||
import { tightRowHeight } from "../../ui/metrics";
|
||||
|
||||
const PAGE_X = 18;
|
||||
const HEADER_Y = 8;
|
||||
@@ -13,7 +14,8 @@ const CURRENT_TOP = 34;
|
||||
const CURRENT_TEXT_X = 112;
|
||||
const FORECAST_HEADER_Y = 105;
|
||||
const FORECAST_TOP = 124;
|
||||
const FORECAST_ROW_HEIGHT = 23;
|
||||
/** Forecast rows hold a 20px icon; grow with the font past that. */
|
||||
const FORECAST_MIN_ROW_HEIGHT = 23;
|
||||
const FOOTER_HEIGHT = 18;
|
||||
const FORECAST_NAME_WIDTH = 92;
|
||||
const FORECAST_TEMP_X = 126;
|
||||
@@ -133,7 +135,8 @@ export class WeatherLayer implements Layer {
|
||||
return;
|
||||
}
|
||||
this.selectedIndex = clamp(this.selectedIndex, 0, forecast.length - 1);
|
||||
const visibleRows = Math.max(1, Math.floor((height - FOOTER_HEIGHT - FORECAST_TOP) / FORECAST_ROW_HEIGHT));
|
||||
const rowH = Math.max(FORECAST_MIN_ROW_HEIGHT, tightRowHeight(font) + 3);
|
||||
const visibleRows = Math.max(1, Math.floor((height - FOOTER_HEIGHT - FORECAST_TOP) / rowH));
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedIndex, visibleRows, forecast.length);
|
||||
|
||||
image.drawText(font, PAGE_X, FORECAST_HEADER_Y, "Upcoming", 150);
|
||||
@@ -144,10 +147,10 @@ export class WeatherLayer implements Layer {
|
||||
const last = Math.min(forecast.length, this.scrollRow + visibleRows);
|
||||
for (let index = this.scrollRow; index < last; index++) {
|
||||
const period = forecast[index]!;
|
||||
const y = FORECAST_TOP + (index - this.scrollRow) * FORECAST_ROW_HEIGHT;
|
||||
const y = FORECAST_TOP + (index - this.scrollRow) * rowH;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, PAGE_X - 7, y - 2, width - 2 * (PAGE_X - 7), FORECAST_ROW_HEIGHT - 2, ctx.stack.isFocused(), 5);
|
||||
drawSelectionHighlight(image, PAGE_X - 7, y - 2, width - 2 * (PAGE_X - 7), rowH - 2, ctx.stack.isFocused(), 5);
|
||||
}
|
||||
const shade = selected ? 245 : 190;
|
||||
image.drawText(font, PAGE_X, y + 2, truncateText(font, period.name, FORECAST_NAME_WIDTH), shade);
|
||||
|
||||
@@ -31,6 +31,25 @@ const LARGE_MIN_LINE_HEIGHT = 26;
|
||||
/** How far size can grow hunting a line-height floor before giving up. */
|
||||
const MAX_SIZE_GROWTH = 48;
|
||||
|
||||
/**
|
||||
* Guaranteed line-height range of getDefaultSmallFont, which UI layouts may
|
||||
* rely on (getDefaultMediumFont's range follows: 16..29). The font picker
|
||||
* disables sizes outside it, and resolution falls back to the bitmap face if
|
||||
* a stored selection somehow lands outside (e.g. the font file changed).
|
||||
*/
|
||||
export const SMALL_FONT_MIN_LINE_HEIGHT = 12;
|
||||
export const SMALL_FONT_MAX_LINE_HEIGHT = 21;
|
||||
|
||||
/** Whether a small-font selection at this path+size satisfies the UI bound. */
|
||||
export function uiFontSizeAllowed(path: string, size: number): boolean {
|
||||
const font = TtfFont.load(path, size);
|
||||
return (
|
||||
font !== null &&
|
||||
font.lineHeight >= SMALL_FONT_MIN_LINE_HEIGHT &&
|
||||
font.lineHeight <= SMALL_FONT_MAX_LINE_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
export function parseFontSelection(raw: string): UiFontSelection | null {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(raw);
|
||||
@@ -123,7 +142,11 @@ function resolveRole(role: "small" | "medium" | "large"): UiFont {
|
||||
if (cached) return cached;
|
||||
const selection = getUiFontSelection();
|
||||
let font: UiFont | null = null;
|
||||
if (selection.kind === "ttf") {
|
||||
// Enforce the guaranteed small-font range even against a stale or
|
||||
// hand-edited selection: an out-of-range selection falls back to bitmap for
|
||||
// every role (medium/large derive from small, so their documented ranges
|
||||
// follow and the roles never mix faces).
|
||||
if (selection.kind === "ttf" && uiFontSizeAllowed(installedFontPath(selection.file), selection.size)) {
|
||||
font =
|
||||
role === "small"
|
||||
? resolveTtf(selection)
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from "~/assistant/models";
|
||||
import { isLocalModelReady } from "../native/llama";
|
||||
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, openModalMenu } from "./menu";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep } from "./metrics";
|
||||
import { DashboardInputEvent, Layer, type LayerContext } from "./layers";
|
||||
import { GrayImage } from "~/graphics/image";
|
||||
|
||||
@@ -678,7 +679,7 @@ export function enumSettingMenuItem<TValue extends string, TId extends string =
|
||||
image.drawText(
|
||||
getDefaultSmallFont(),
|
||||
x,
|
||||
y + 3,
|
||||
y + LIST_ROW_TEXT_INSET,
|
||||
`${setting.displayValue(value)}${selected}`,
|
||||
disabled ? 70 : 200,
|
||||
);
|
||||
@@ -723,7 +724,7 @@ export function textSettingMenuItem<TId extends string = string>(
|
||||
render: ({ image, x, y }) => {
|
||||
// displayValue honors the setting's formatValue, so secrets (API keys,
|
||||
// tokens) can mask themselves instead of rendering in the clear.
|
||||
image.drawText(getDefaultSmallFont(), x, y + 3, `${setting.label}: ${truncateSetting(setting.displayValue())}`, 200);
|
||||
image.drawText(getDefaultSmallFont(), x, y + LIST_ROW_TEXT_INSET, `${setting.label}: ${truncateSetting(setting.displayValue())}`, 200);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -742,13 +743,15 @@ export class EditTextSettingLayer implements Layer {
|
||||
// viewport in the settings app).
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const step = lineStep(font);
|
||||
image.drawText(font, 22, 16, this.setting.glassesEditTitle, 220);
|
||||
const messageTop = 24 + 2 * font.lineHeight;
|
||||
const message = wrapText(font, "Look at the phone app to type a value.", width - 48);
|
||||
for (let index = 0; index < message.length; index++) {
|
||||
image.drawText(font, 22, 52 + index * 14, message[index]!, 200);
|
||||
image.drawText(font, 22, messageTop + index * step, message[index]!, 200);
|
||||
}
|
||||
image.drawText(font, 22, 110, truncateSetting(this.setting.get(), 52), 220);
|
||||
image.drawText(font, 22, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, 22, messageTop + (message.length + 2) * step, truncateSetting(this.setting.get(), 52), 220);
|
||||
image.drawText(font, 22, height - 24 - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../gestures";
|
||||
import { DashboardInputEvent, Layer, LayerContext } from "../layers";
|
||||
import { drawSelectionHighlight, isMenuItemDisabled, MenuItem, MenuLayer, openModalMenu } from "../menu";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../metrics";
|
||||
import { shell } from "../shell/shell";
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,6 @@ export type SettingsSection = {
|
||||
};
|
||||
|
||||
const PAD = 8;
|
||||
const ROW_H = 20;
|
||||
const LEFT_W = 150;
|
||||
const MAX_DESCRIPTION_LINES = 3;
|
||||
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
|
||||
@@ -74,19 +74,21 @@ export class SettingsPanelLayer implements Layer {
|
||||
const rightItems = section.items;
|
||||
this.rightIndex = clamp(this.rightIndex, 0, Math.max(0, rightItems.length - 1));
|
||||
|
||||
const rowH = listRowHeight(font);
|
||||
const top = PAD;
|
||||
const listBottom = height - PAD - 12; // leave a row for the gesture hint
|
||||
const hintY = height - font.lineHeight + 2;
|
||||
const listBottom = hintY - 8; // leave a band for the gesture hint
|
||||
|
||||
// Left column: section labels.
|
||||
const leftRows = Math.max(1, ((listBottom - top) / ROW_H) | 0);
|
||||
const leftRows = Math.max(1, ((listBottom - top) / rowH) | 0);
|
||||
this.leftScroll = clampScroll(this.leftIndex, this.leftScroll, leftRows, this.sections.length);
|
||||
for (let i = this.leftScroll; i < Math.min(this.sections.length, this.leftScroll + leftRows); i++) {
|
||||
const rowY = top + (i - this.leftScroll) * ROW_H;
|
||||
const rowY = top + (i - this.leftScroll) * rowH;
|
||||
const selected = i === this.leftIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, PAD - 2, rowY, LEFT_W, ROW_H - 2, appFocused && this.focus === "left", 6);
|
||||
drawSelectionHighlight(image, PAD - 2, rowY, LEFT_W, rowH - 2, appFocused && this.focus === "left", 6);
|
||||
}
|
||||
image.drawText(font, PAD + 8, rowY + 4, this.sections[i]!.label, selected ? 255 : 200);
|
||||
image.drawText(font, PAD + 8, rowY + LIST_ROW_TEXT_INSET, this.sections[i]!.label, selected ? 255 : 200);
|
||||
}
|
||||
|
||||
// Column divider (a light rule, not a full border).
|
||||
@@ -109,19 +111,19 @@ export class SettingsPanelLayer implements Layer {
|
||||
const descriptionLines = selectedItem?.description
|
||||
? wrapText(font, selectedItem.description, rightW - 4).slice(0, MAX_DESCRIPTION_LINES)
|
||||
: [];
|
||||
const descriptionH = descriptionLines.length ? descriptionLines.length * font.lineHeight + 10 : 0;
|
||||
const descriptionH = descriptionLines.length ? descriptionLines.length * lineStep(font) + 10 : 0;
|
||||
const rightListBottom = listBottom - descriptionH;
|
||||
const rightRows = Math.max(1, ((rightListBottom - rightTop) / ROW_H) | 0);
|
||||
const rightRows = Math.max(1, ((rightListBottom - rightTop) / rowH) | 0);
|
||||
this.rightScroll = clampScroll(this.rightIndex, this.rightScroll, rightRows, rightItems.length);
|
||||
for (let i = this.rightScroll; i < Math.min(rightItems.length, this.rightScroll + rightRows); i++) {
|
||||
const item = rightItems[i]!;
|
||||
const rowY = rightTop + (i - this.rightScroll) * ROW_H;
|
||||
const rowY = rightTop + (i - this.rightScroll) * rowH;
|
||||
// A selection only appears once focus is in the right column; before
|
||||
// that the pane is a preview of what tapping would open.
|
||||
const selected = this.focus === "right" && i === this.rightIndex;
|
||||
const disabled = isMenuItemDisabled(item);
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, rightX - 2, rowY, rightW + 2, ROW_H - 2, appFocused, 6);
|
||||
drawSelectionHighlight(image, rightX - 2, rowY, rightW + 2, rowH - 2, appFocused, 6);
|
||||
}
|
||||
if (item.render) {
|
||||
item.render({
|
||||
@@ -129,20 +131,20 @@ export class SettingsPanelLayer implements Layer {
|
||||
x: rightX + 8,
|
||||
y: rowY,
|
||||
width: rightW - 16,
|
||||
height: ROW_H - 3,
|
||||
height: rowH - 3,
|
||||
selected,
|
||||
disabled,
|
||||
text: item.label,
|
||||
ctx,
|
||||
});
|
||||
} else {
|
||||
image.drawText(font, rightX + 8, rowY + 4, item.label, disabled ? 70 : selected ? 255 : 200);
|
||||
image.drawText(font, rightX + 8, rowY + LIST_ROW_TEXT_INSET, item.label, disabled ? 70 : selected ? 255 : 200);
|
||||
}
|
||||
}
|
||||
if (descriptionLines.length) {
|
||||
image.drawLine(rightX, rightListBottom, rightX + rightW, rightListBottom, 40);
|
||||
for (let i = 0; i < descriptionLines.length; i++) {
|
||||
image.drawText(font, rightX + 4, rightListBottom + 6 + i * font.lineHeight, descriptionLines[i]!, 150);
|
||||
image.drawText(font, rightX + 4, rightListBottom + 6 + i * lineStep(font), descriptionLines[i]!, 150);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,7 +153,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
this.focus === "left"
|
||||
? `${GESTURE_SCROLL} section ${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} exit`
|
||||
: `${GESTURE_SCROLL} item ${GESTURE_CLICK} select ${GESTURE_DOUBLE_CLICK} back`;
|
||||
image.drawText(font, PAD, height - 10, hint, 110);
|
||||
image.drawText(font, PAD, hintY, hint, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
+34
-10
@@ -14,6 +14,7 @@ import { listInstalledFonts, type InstalledFont } from "../graphics/installed-fo
|
||||
import {
|
||||
fontSelectionLabel,
|
||||
getDefaultSmallFont,
|
||||
uiFontSizeAllowed,
|
||||
getTerminalFontSelection,
|
||||
getUiFontSelection,
|
||||
setTerminalFontSelection,
|
||||
@@ -23,6 +24,7 @@ import {
|
||||
} from "../graphics/ui-fonts";
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
import { drawRightValueMenuItem, drawSelectionHighlight, openModalMenu, type MenuItem } from "./menu";
|
||||
import { LIST_ROW_TEXT_INSET, listRowHeight } from "./metrics";
|
||||
import type { DashboardInputEvent, Layer, LayerContext } from "./layers";
|
||||
|
||||
const SIZE_CHOICES = [12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28] as const;
|
||||
@@ -33,6 +35,11 @@ type FontPickerOptions = {
|
||||
title: string;
|
||||
/** Only offer faces where every style is monospace (terminal picker). */
|
||||
monospaceOnly: boolean;
|
||||
/** When set, sizes where this returns false are disabled (and drafts are
|
||||
* clamped to an allowed size on face/weight changes). The UI-font picker
|
||||
* uses it to keep getDefaultSmallFont's line height within its guaranteed
|
||||
* 12..21px range; the terminal picker has no such bound. */
|
||||
sizeAllowed?: (path: string, size: number) => boolean;
|
||||
/** Bitmap faces offered ahead of the installed TTF families. */
|
||||
bitmapFaces: readonly { face: BitmapFace; label: string }[];
|
||||
get(): UiFontSelection;
|
||||
@@ -66,7 +73,7 @@ export class FontPickerLayer implements Layer {
|
||||
if (selection.kind === "ttf") {
|
||||
for (const family of this.families) {
|
||||
const font = family.fonts.find((f) => f.fileName === selection.file);
|
||||
if (font) return { kind: "ttf", family, font, size: selection.size };
|
||||
if (font) return { kind: "ttf", family, font, size: this.clampSize(font, selection.size) };
|
||||
}
|
||||
}
|
||||
const face =
|
||||
@@ -102,24 +109,24 @@ export class FontPickerLayer implements Layer {
|
||||
|
||||
const rowX = 22;
|
||||
const rowWidth = width - 2 * rowX;
|
||||
const rowHeight = 22;
|
||||
const rowsTop = 40;
|
||||
const rowHeight = listRowHeight(font);
|
||||
const rowsTop = 24 + font.lineHeight;
|
||||
for (let index = 0; index < ROWS.length; index++) {
|
||||
const row = ROWS[index]!;
|
||||
const y = rowsTop + index * rowHeight;
|
||||
const disabled = this.rowDisabled(row);
|
||||
if (index === this.selectedRow) {
|
||||
drawSelectionHighlight(image, rowX - 10, y - 2, rowWidth + 20, rowHeight - 2, focused, 8);
|
||||
drawSelectionHighlight(image, rowX - 10, y, rowWidth + 20, rowHeight - 2, focused, 8);
|
||||
}
|
||||
if (row === "save") {
|
||||
image.drawText(font, rowX, y + 3, "Save", index === this.selectedRow ? 255 : 200);
|
||||
image.drawText(font, rowX, y + LIST_ROW_TEXT_INSET, "Save", index === this.selectedRow ? 255 : 200);
|
||||
continue;
|
||||
}
|
||||
const label = row === "face" ? "Font" : row === "weight" ? "Weight" : "Size";
|
||||
const value = this.rowValue(row);
|
||||
if (disabled) {
|
||||
image.drawText(font, rowX, y + 3, label, 70);
|
||||
image.drawText(font, rowX + rowWidth - font.measureText(value) - 2, y + 3, value, 70);
|
||||
image.drawText(font, rowX, y + LIST_ROW_TEXT_INSET, label, 70);
|
||||
image.drawText(font, rowX + rowWidth - font.measureText(value) - 2, y + LIST_ROW_TEXT_INSET, value, 70);
|
||||
} else {
|
||||
drawRightValueMenuItem(image, font, rowX, y, rowWidth, label, value);
|
||||
}
|
||||
@@ -135,7 +142,7 @@ export class FontPickerLayer implements Layer {
|
||||
const info = `Line height: ${preview.lineHeight}px`;
|
||||
image.drawText(font, rowX - 4, previewTop + 8 + preview.lineHeight + 6, info, 110);
|
||||
|
||||
image.drawText(font, rowX - 4, height - 30, `scroll select click change ${GESTURE_DOUBLE_CLICK} cancel`, 90);
|
||||
image.drawText(font, rowX - 4, height - font.lineHeight - 8, `scroll select click change ${GESTURE_DOUBLE_CLICK} cancel`, 90);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -222,7 +229,22 @@ export class FontPickerLayer implements Layer {
|
||||
font = candidate;
|
||||
}
|
||||
}
|
||||
this.draft = { kind: "ttf", family, font, size };
|
||||
this.draft = { kind: "ttf", family, font, size: this.clampSize(font, size) };
|
||||
}
|
||||
|
||||
/**
|
||||
* The nearest allowed size for this face (line-height bounds differ by
|
||||
* face, so a face/weight change can invalidate the carried-over size).
|
||||
*/
|
||||
private clampSize(font: InstalledFont, size: number): number {
|
||||
const allowed = this.options.sizeAllowed;
|
||||
if (!allowed || allowed(font.path, size)) return size;
|
||||
let best = -1;
|
||||
for (const candidate of SIZE_CHOICES) {
|
||||
if (!allowed(font.path, candidate)) continue;
|
||||
if (best < 0 || Math.abs(candidate - size) < Math.abs(best - size)) best = candidate;
|
||||
}
|
||||
return best > 0 ? best : size;
|
||||
}
|
||||
|
||||
private openWeightMenu(ctx: LayerContext): void {
|
||||
@@ -231,7 +253,7 @@ export class FontPickerLayer implements Layer {
|
||||
const items = draft.family.fonts.map((font): MenuItem => ({
|
||||
label: font.style || "Regular",
|
||||
onSelect: (innerCtx) => {
|
||||
this.draft = { ...draft, font };
|
||||
this.draft = { ...draft, font, size: this.clampSize(font, draft.size) };
|
||||
innerCtx.stack.pop();
|
||||
},
|
||||
}));
|
||||
@@ -243,6 +265,7 @@ export class FontPickerLayer implements Layer {
|
||||
const draft = this.draft;
|
||||
const items = SIZE_CHOICES.map((size): MenuItem => ({
|
||||
label: String(size),
|
||||
disabled: () => this.options.sizeAllowed !== undefined && !this.options.sizeAllowed(draft.font.path, size),
|
||||
onSelect: (innerCtx) => {
|
||||
this.draft = { ...draft, size };
|
||||
innerCtx.stack.pop();
|
||||
@@ -275,6 +298,7 @@ export function uiFontPickerMenuItem(): MenuItem {
|
||||
"Typeface for UI text on the glasses: a bitmap Terminus variant or any installed TTF face at a chosen weight and size. Install more fonts from the Files app.",
|
||||
title: "UI font",
|
||||
monospaceOnly: false,
|
||||
sizeAllowed: uiFontSizeAllowed,
|
||||
bitmapFaces: [
|
||||
{ face: "terminus", label: "Terminus" },
|
||||
{ face: "terminusv", label: "TerminusV" },
|
||||
|
||||
+22
-21
@@ -5,18 +5,14 @@ import { clamp } from "../util/numeric-util";
|
||||
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers";
|
||||
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight, menuTitleHeight } from "./metrics";
|
||||
const DEFAULT_MENU_X = 8;
|
||||
const DEFAULT_MENU_Y = 8;
|
||||
const DEFAULT_MENU_WIDTH = 272;
|
||||
// Menus grow with their item count, from half the screen (matching the old
|
||||
// fixed quarter-screen-era look) up to the full screen, then scroll.
|
||||
const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y;
|
||||
const MENU_TITLE_HEIGHT = 16;
|
||||
const MENU_ROW_HEIGHT = 20;
|
||||
const MENU_BODY_PADDING = 8;
|
||||
const MENU_HIGHLIGHT_Y_OFFSET = 0;
|
||||
const MENU_TOGGLE_SWITCH_Y_OFFSET = 1;
|
||||
const MENU_HIGHLIGHT_HEIGHT = MENU_ROW_HEIGHT - 1;
|
||||
const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15;
|
||||
const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45;
|
||||
|
||||
@@ -147,8 +143,9 @@ export function drawToggleMenuItem(
|
||||
const switchWidth = 34;
|
||||
const switchHeight = 16;
|
||||
const switchX = x + width - switchWidth - 2;
|
||||
const switchY = y + MENU_TOGGLE_SWITCH_Y_OFFSET;
|
||||
image.drawText(font, x, y + 3, label, 200);
|
||||
// Center the switch on the row's line box (legacy y+1 at the 12px default).
|
||||
const switchY = y + Math.max(1, Math.round((listRowHeight(font) - 2 - switchHeight) / 2));
|
||||
image.drawText(font, x, y + LIST_ROW_TEXT_INSET, label, 200);
|
||||
const offFill = selected ? 1 : 18;
|
||||
image.fillRoundedRect(switchX, switchY, switchWidth, switchHeight, enabled ? 70 : offFill, 8);
|
||||
image.drawRoundedRect(switchX, switchY, switchWidth, switchHeight, enabled ? 130 : 55, 8);
|
||||
@@ -166,9 +163,9 @@ export function drawRightValueMenuItem(
|
||||
label: string,
|
||||
value: string,
|
||||
): void {
|
||||
image.drawText(font, x, y + 3, label, 200);
|
||||
image.drawText(font, x, y + LIST_ROW_TEXT_INSET, label, 200);
|
||||
const valueX = x + width - font.measureText(value) - 2;
|
||||
image.drawText(font, valueX, y + 3, value, 220);
|
||||
image.drawText(font, valueX, y + LIST_ROW_TEXT_INSET, value, 220);
|
||||
}
|
||||
|
||||
export class MenuLayer implements Layer {
|
||||
@@ -194,9 +191,10 @@ export class MenuLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const rowHeight = listRowHeight(font);
|
||||
const image = paintBelow();
|
||||
const { x, y, width } = this.layout;
|
||||
const chromeTop = (this.title ? MENU_TITLE_HEIGHT : 0) + MENU_BODY_PADDING;
|
||||
const chromeTop = (this.title ? menuTitleHeight(font) : 0) + MENU_BODY_PADDING;
|
||||
const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT;
|
||||
// Cap to the surface being painted on: a window's stack image may be much
|
||||
// shorter than the full screen (min-height windows).
|
||||
@@ -204,9 +202,9 @@ export class MenuLayer implements Layer {
|
||||
this.layout.maxHeight ?? image.height - y - DEFAULT_MENU_Y,
|
||||
image.height - y,
|
||||
);
|
||||
const contentHeight = chromeTop + this.items.length * MENU_ROW_HEIGHT + MENU_BODY_PADDING;
|
||||
const contentHeight = chromeTop + this.items.length * rowHeight + MENU_BODY_PADDING;
|
||||
const height = clamp(contentHeight, Math.min(minHeight, maxHeight), maxHeight);
|
||||
const visibleRowCount = Math.max(1, ((height - chromeTop - MENU_BODY_PADDING) / MENU_ROW_HEIGHT) | 0);
|
||||
const visibleRowCount = Math.max(1, ((height - chromeTop - MENU_BODY_PADDING) / rowHeight) | 0);
|
||||
this.scrollRow = scrollToKeepSelectionVisible(
|
||||
this.scrollRow,
|
||||
this.selectedIndex,
|
||||
@@ -229,16 +227,16 @@ export class MenuLayer implements Layer {
|
||||
const lastVisibleRow = Math.min(this.items.length, this.scrollRow + visibleRowCount);
|
||||
for (let index = this.scrollRow; index < lastVisibleRow; index++) {
|
||||
const item = this.items[index]!;
|
||||
const rowY = bodyY + (index - this.scrollRow) * MENU_ROW_HEIGHT;
|
||||
const rowY = bodyY + (index - this.scrollRow) * rowHeight;
|
||||
const selected = index === this.selectedIndex;
|
||||
const disabled = isMenuItemDisabled(item);
|
||||
if (selected) {
|
||||
drawSelectionHighlight(
|
||||
image,
|
||||
x + 12,
|
||||
rowY + MENU_HIGHLIGHT_Y_OFFSET,
|
||||
rowY,
|
||||
width - 24,
|
||||
MENU_HIGHLIGHT_HEIGHT,
|
||||
rowHeight - 1,
|
||||
focused,
|
||||
8,
|
||||
);
|
||||
@@ -249,14 +247,14 @@ export class MenuLayer implements Layer {
|
||||
x: x + 22,
|
||||
y: rowY,
|
||||
width: width - 44,
|
||||
height: MENU_ROW_HEIGHT - 3,
|
||||
height: rowHeight - 3,
|
||||
selected,
|
||||
disabled,
|
||||
text: item.label,
|
||||
ctx,
|
||||
});
|
||||
} else {
|
||||
image.drawText(font, x + 22, rowY + 3, item.label, disabled ? 70 : selected ? 255 : 200);
|
||||
image.drawText(font, x + 22, rowY + LIST_ROW_TEXT_INSET, item.label, disabled ? 70 : selected ? 255 : 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +263,7 @@ export class MenuLayer implements Layer {
|
||||
image,
|
||||
x + width - 7,
|
||||
bodyY,
|
||||
visibleRowCount * MENU_ROW_HEIGHT - 4,
|
||||
visibleRowCount * rowHeight - 4,
|
||||
this.scrollRow,
|
||||
visibleRowCount,
|
||||
this.items.length,
|
||||
@@ -311,8 +309,9 @@ export function openModalMenu(
|
||||
initialSelectedIndex = 0,
|
||||
): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const font = getDefaultSmallFont();
|
||||
const menuWidth = Math.min(320, width - 40);
|
||||
const naturalHeight = MENU_TITLE_HEIGHT + 2 * MENU_BODY_PADDING + items.length * MENU_ROW_HEIGHT;
|
||||
const naturalHeight = menuTitleHeight(font) + 2 * MENU_BODY_PADDING + items.length * listRowHeight(font);
|
||||
const menuHeight = Math.min(naturalHeight, height - 40);
|
||||
const layout: MenuLayout = {
|
||||
x: ((width - menuWidth) / 2) | 0,
|
||||
@@ -341,10 +340,12 @@ export class TextPageLayer implements Layer {
|
||||
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
|
||||
|
||||
const wrapped = wrapText(font, this.body, G2_LENS_WIDTH - 60);
|
||||
const step = lineStep(font);
|
||||
const bodyTop = 28 + font.lineHeight;
|
||||
const footerY = G2_LENS_HEIGHT - 48;
|
||||
const maxBodyLines = Math.max(0, Math.floor((footerY - 50) / 14));
|
||||
const maxBodyLines = Math.max(0, Math.floor((footerY - bodyTop - 8) / step));
|
||||
for (let index = 0; index < Math.min(wrapped.length, maxBodyLines); index++) {
|
||||
image.drawText(font, 24, 42 + index * 14, wrapped[index]!, 190);
|
||||
image.drawText(font, 24, bodyTop + index * step, wrapped[index]!, 190);
|
||||
}
|
||||
image.drawText(font, 24, footerY, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Font-derived layout metrics for list-style UIs, so row spacing, selection
|
||||
* highlights, and text line steps track the user's font size instead of
|
||||
* assuming the 12px bitmap default. The font picker guarantees
|
||||
* getDefaultSmallFont's lineHeight is 12..21px (and getDefaultMediumFont's
|
||||
* 16..29px — see ui-fonts.ts), so layouts driven by these helpers have
|
||||
* bounded growth.
|
||||
*
|
||||
* The formulas reproduce the pre-TTF constants exactly at the 12px default:
|
||||
* listRowHeight 20, tightRowHeight 16, lineStep 14, menuTitleHeight 16.
|
||||
*/
|
||||
import type { UiFont } from "../graphics/image";
|
||||
|
||||
/** Height of one selectable list/menu row (line box + breathing room). */
|
||||
export function listRowHeight(font: UiFont): number {
|
||||
return font.lineHeight + 8;
|
||||
}
|
||||
|
||||
/** Vertical inset of a listRowHeight row's text within the row. */
|
||||
export const LIST_ROW_TEXT_INSET = 4;
|
||||
|
||||
/** Height of one row in dense lists (file browser, track lists). */
|
||||
export function tightRowHeight(font: UiFont): number {
|
||||
return font.lineHeight + 4;
|
||||
}
|
||||
|
||||
/** Step between consecutive lines of body/paragraph text. */
|
||||
export function lineStep(font: UiFont): number {
|
||||
return font.lineHeight + 2;
|
||||
}
|
||||
|
||||
/** Height of a menu/panel title band above a list. */
|
||||
export function menuTitleHeight(font: UiFont): number {
|
||||
return font.lineHeight + 4;
|
||||
}
|
||||
+12
-9
@@ -4,6 +4,7 @@ import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||
import { truncateText } from "../graphics/textwrap";
|
||||
import { GrayImage, type UiFont } from "../graphics/image";
|
||||
import { wrapText } from "../graphics/textwrap";
|
||||
import { lineStep, listRowHeight } from "./metrics";
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
import {
|
||||
dismissNotification,
|
||||
@@ -24,7 +25,6 @@ const CARD_X = 20;
|
||||
const ICON_SIZE = 24;
|
||||
const ICON_TEXT_GAP = 8;
|
||||
const CARD_TEXT_X = 10 + ICON_SIZE + ICON_TEXT_GAP;
|
||||
const LINE_HEIGHT = 14;
|
||||
const CARD_GAP = 6;
|
||||
const MAX_NOTIFICATIONS = 50;
|
||||
// Right-hand action menu of the detail view.
|
||||
@@ -88,7 +88,7 @@ export class NotificationsListLayer implements Layer {
|
||||
: "Grant permission on your phone to view notifications on the glasses.";
|
||||
const messageLines = wrapText(font, message, width - 48);
|
||||
for (let index = 0; index < messageLines.length; index++) {
|
||||
image.drawText(font, 24, 72 + index * LINE_HEIGHT, messageLines[index]!, 190);
|
||||
image.drawText(font, 24, 72 + index * lineStep(font), messageLines[index]!, 190);
|
||||
}
|
||||
image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
@@ -267,7 +267,7 @@ function buildNotificationCardLayout(
|
||||
return {
|
||||
notification,
|
||||
lines,
|
||||
height: Math.max(42, 12 + lines.length * LINE_HEIGHT),
|
||||
height: Math.max(ICON_SIZE + 18, 12 + lines.length * lineStep(font)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ function drawNotificationCard(
|
||||
}
|
||||
for (let index = 0; index < layout.lines.length; index++) {
|
||||
const value = index === 0 ? 140 : selected ? 235 : 185;
|
||||
image.drawText(font, x + CARD_TEXT_X, y + 7 + index * LINE_HEIGHT, layout.lines[index]!, value);
|
||||
image.drawText(font, x + CARD_TEXT_X, y + 7 + index * lineStep(font), layout.lines[index]!, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,10 +343,12 @@ function drawDetailContent(
|
||||
lines.push(...wrapText(font, meta, contentWidth));
|
||||
}
|
||||
|
||||
const maxLines = Math.max(1, ((height - 64 - 14) / LINE_HEIGHT) | 0);
|
||||
const step = lineStep(font);
|
||||
const bodyTop = 48 + font.lineHeight + 4;
|
||||
const maxLines = Math.max(1, ((height - bodyTop - step) / step) | 0);
|
||||
for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
|
||||
const line = lines[index]!;
|
||||
image.drawText(font, contentX, 64 + index * LINE_HEIGHT, line, index === 0 ? 230 : 190);
|
||||
image.drawText(font, contentX, bodyTop + index * step, line, index === 0 ? 230 : 190);
|
||||
}
|
||||
if (lines.length > maxLines) {
|
||||
image.drawText(font, contentX, height - 24, "...", 140);
|
||||
@@ -356,12 +358,13 @@ function drawDetailContent(
|
||||
function drawDetailMenu(image: GrayImage, font: UiFont, menu: DetailMenuItem[], selectedIndex: number, width: number): void {
|
||||
const menuX = width - DETAIL_MENU_WIDTH - 24;
|
||||
const menuY = 24;
|
||||
const rowH = listRowHeight(font);
|
||||
for (let index = 0; index < menu.length; index++) {
|
||||
const y = menuY + index * 22;
|
||||
const y = menuY + index * (rowH + 2);
|
||||
const selected = index === selectedIndex;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, 19, 18, 6);
|
||||
image.drawRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, 19, 60, 6);
|
||||
image.fillRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, rowH - 1, 18, 6);
|
||||
image.drawRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, rowH - 1, 60, 6);
|
||||
}
|
||||
const label = truncateText(font, menu[index]!.label, DETAIL_MENU_WIDTH - 12);
|
||||
image.drawText(font, menuX, y + 2, label, selected ? 255 : 185);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { type BdfFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GESTURE_DOUBLE_CLICK } from "../gestures";
|
||||
import { drawSelectionHighlight } from "../menu";
|
||||
import { listRowHeight } from "../metrics";
|
||||
import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../layers";
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
|
||||
@@ -14,7 +15,6 @@ const DIALOG_W = G2_LENS_WIDTH - 80;
|
||||
const DIALOG_MARGIN_Y = 24;
|
||||
const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y;
|
||||
const TEXT_MAX_WIDTH = DIALOG_W - 32;
|
||||
const MENU_ROW_H = 20;
|
||||
const MENU_ROWS = 2;
|
||||
|
||||
/** Dialog top edge; band-relative, so computed per paint. */
|
||||
@@ -89,6 +89,7 @@ export class AssistantLayer implements Layer {
|
||||
|
||||
paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const menuRowH = listRowHeight(font);
|
||||
const image = paintBelow();
|
||||
const top = dialogY();
|
||||
|
||||
@@ -105,7 +106,7 @@ export class AssistantLayer implements Layer {
|
||||
}
|
||||
|
||||
const inMenu = this.phase !== "thinking";
|
||||
const textBottom = inMenu ? top + DIALOG_H - MENU_ROWS * MENU_ROW_H - 8 : top + DIALOG_H - 8;
|
||||
const textBottom = inMenu ? top + DIALOG_H - MENU_ROWS * menuRowH - 8 : top + DIALOG_H - 8;
|
||||
const textTop = top + 56;
|
||||
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
|
||||
|
||||
@@ -118,12 +119,12 @@ export class AssistantLayer implements Layer {
|
||||
|
||||
if (inMenu) {
|
||||
const rows = ["Follow-up", "Done"];
|
||||
const menuTop = top + DIALOG_H - MENU_ROWS * MENU_ROW_H - 2;
|
||||
const menuTop = top + DIALOG_H - MENU_ROWS * menuRowH - 2;
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const rowY = menuTop + i * MENU_ROW_H;
|
||||
const rowY = menuTop + i * menuRowH;
|
||||
const selected = i === this.menuIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, left - 4, rowY - 2, DIALOG_W - 24, MENU_ROW_H - 2, true, 6);
|
||||
drawSelectionHighlight(image, left - 4, rowY - 2, DIALOG_W - 24, menuRowH - 2, true, 6);
|
||||
}
|
||||
image.drawText(font, left + 4, rowY + 2, rows[i]!, selected ? 255 : 200);
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ class ShellAlertLayer implements Layer {
|
||||
image.drawTextWrapped({
|
||||
font,
|
||||
x: ALERT_X + 16,
|
||||
y: alertY + 34,
|
||||
y: alertY + 18 + font.lineHeight + 4,
|
||||
width: ALERT_W - 32,
|
||||
text: this.text,
|
||||
value: 235,
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { ToolDebugEntry } from "../../assistant/tool-registry";
|
||||
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "../layers";
|
||||
import { MenuLayer, drawListScrollbar, type MenuItem } from "../menu";
|
||||
import { MIN_WINDOW_HEIGHT, minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
|
||||
import { lineStep } from "../metrics";
|
||||
|
||||
/**
|
||||
* Shell-overlay debug dialog (escape menu > Debug): lists the voice assistant
|
||||
@@ -26,7 +27,6 @@ function dialogY(): number {
|
||||
return minWindowTop() + TOP_BAR_HEIGHT + 8;
|
||||
}
|
||||
const DETAIL_PADDING = 14;
|
||||
const DETAIL_LINE_HEIGHT = 14;
|
||||
|
||||
export class ToolDebugMenuLayer extends MenuLayer {
|
||||
constructor(appId: string | null, entries: ToolDebugEntry[], private readonly onClosed: () => void) {
|
||||
@@ -85,13 +85,14 @@ class ToolDetailLayer implements Layer {
|
||||
const textX = DIALOG_X + DETAIL_PADDING;
|
||||
const textWidth = DETAIL_WIDTH - 2 * DETAIL_PADDING - 8;
|
||||
const lines = this.buildLines(textWidth);
|
||||
const visibleRowCount = Math.max(1, ((DETAIL_HEIGHT - 2 * DETAIL_PADDING) / DETAIL_LINE_HEIGHT) | 0);
|
||||
const detailLineH = lineStep(font);
|
||||
const visibleRowCount = Math.max(1, ((DETAIL_HEIGHT - 2 * DETAIL_PADDING) / detailLineH) | 0);
|
||||
this.scrollRow = clamp(this.scrollRow, 0, Math.max(0, lines.length - visibleRowCount));
|
||||
|
||||
const lastVisibleRow = Math.min(lines.length, this.scrollRow + visibleRowCount);
|
||||
for (let index = this.scrollRow; index < lastVisibleRow; index++) {
|
||||
const line = lines[index]!;
|
||||
const y = top + DETAIL_PADDING + (index - this.scrollRow) * DETAIL_LINE_HEIGHT;
|
||||
const y = top + DETAIL_PADDING + (index - this.scrollRow) * detailLineH;
|
||||
image.drawText(font, textX, y, line.text, line.value);
|
||||
}
|
||||
if (lines.length > visibleRowCount) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { refineDictation, type AnthropicStreamHandle } from "../../native/anthro
|
||||
import { anthropicApiKeySetting } from "../dashboard-settings";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, gestureHints } from "../gestures";
|
||||
import { drawSelectionHighlight } from "../menu";
|
||||
import { listRowHeight } from "../metrics";
|
||||
import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../layers";
|
||||
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
|
||||
|
||||
@@ -22,7 +23,6 @@ const TEXT_MAX_WIDTH = DIALOG_W - 32;
|
||||
function dialogY(): number {
|
||||
return minWindowTop() + DIALOG_MARGIN_Y;
|
||||
}
|
||||
const MENU_ROW_H = 20;
|
||||
// After the mic stops, the provider's final transcript can trail in (cloud
|
||||
// commit round-trip); wait this long for it before refining with what we have.
|
||||
const FOLLOWUP_FINALIZE_TIMEOUT_MS = 1200;
|
||||
@@ -229,6 +229,7 @@ export class VoiceInputLayer implements Layer {
|
||||
|
||||
paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const menuRowH = listRowHeight(font);
|
||||
const image = paintBelow();
|
||||
const top = dialogY();
|
||||
|
||||
@@ -244,7 +245,7 @@ export class VoiceInputLayer implements Layer {
|
||||
const inMenu = this.phase === "menu";
|
||||
const rows = inMenu ? this.menuRows() : [];
|
||||
// Reserve space for the actual number of rows this menu has.
|
||||
const textBottom = inMenu ? top + DIALOG_H - rows.length * MENU_ROW_H - 8 : top + DIALOG_H - 8;
|
||||
const textBottom = inMenu ? top + DIALOG_H - rows.length * menuRowH - 8 : top + DIALOG_H - 8;
|
||||
const textTop = top + 56;
|
||||
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
|
||||
|
||||
@@ -256,12 +257,12 @@ export class VoiceInputLayer implements Layer {
|
||||
}
|
||||
|
||||
if (inMenu) {
|
||||
const menuTop = top + DIALOG_H - rows.length * MENU_ROW_H - 2;
|
||||
const menuTop = top + DIALOG_H - rows.length * menuRowH - 2;
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const rowY = menuTop + i * MENU_ROW_H;
|
||||
const rowY = menuTop + i * menuRowH;
|
||||
const selected = i === this.menuIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, left - 4, rowY - 2, DIALOG_W - 24, MENU_ROW_H - 2, true, 6);
|
||||
drawSelectionHighlight(image, left - 4, rowY - 2, DIALOG_W - 24, menuRowH - 2, true, 6);
|
||||
}
|
||||
const row = rows[i]!;
|
||||
image.drawText(font, left + 4, rowY + 2, row.label, row.dim ? 90 : selected ? 255 : 200);
|
||||
|
||||
Reference in new issue
Block a user