forked from Blendman974/faceclaw
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
@@ -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