Adjust UI to account for user-configured variable font size

This commit is contained in:
James Babcock committed 2026-08-19 20:48:18 -07:00
1 parent 96842ceb23
commit eef9fbaab4
25 files changed
+350 -222

No files matched your search

+8 -8
View File
@@ -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);
}
}
+5 -4
View File
@@ -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);
+10 -9
View File
@@ -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);
}
+14 -13
View File
@@ -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);
}
+12 -10
View File
@@ -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,
);
+8 -7
View File
@@ -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;
}
+16 -11
View File
@@ -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> {
+10 -9
View File
@@ -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;
}
+22 -19
View File
@@ -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
View File
@@ -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);
+29 -20
View File
@@ -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;
}
+19 -16
View File
@@ -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,
+5 -3
View File
@@ -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);
}
+7 -4
View File
@@ -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);