UI refinement pass

Remove gesture-help bottom-bars from many places in the UI, adjust
layouts to be able to handle larger fonts, and other small UI fixes.
This commit is contained in:
James Babcock committed 2026-08-22 18:48:20 -07:00
1 parent dc18737dfc
commit 35e6977c6c
17 files changed
+394 -321

No files matched your search

+20 -10
View File
@@ -4,19 +4,24 @@ import { wrapText, truncateText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import { readUpcomingEvents, type CalendarEvent } from "../../native/calendar";
import { timeFormatSetting } from "../../ui/dashboard-settings";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
import { GESTURE_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;
// Title position, shared with the other list apps (terminal, notifications).
const TITLE_X = 18;
const TITLE_Y = 10;
const LIST_TOP = 38;
const ROW_X = 16;
const DAY_HEADER_HEIGHT = 16;
const ROW_GAP = 4;
const MAX_EVENTS = 50;
/** Height of the day header band above a row that starts a new day. */
function dayHeaderHeight(font: UiFont): number {
return font.lineHeight + 4;
}
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
@@ -43,26 +48,31 @@ export class CalendarLayer implements Layer {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Calendar", 220);
if (!hasCalendarPermission()) {
image.drawText(font, TITLE_X, TITLE_Y, "Calendar", 220);
this.paintPermissionPrompt(image, font, width, height);
return image;
}
const events = readUpcomingEvents(MAX_EVENTS);
if (!events.length) {
image.drawText(font, TITLE_X, TITLE_Y, "Calendar", 220);
image.drawText(font, 24, 72, "No upcoming events.", 190);
image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
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);
const listBottom = height;
const scrollY = scrollForSelected(rows, this.selectedIndex, listBottom - LIST_TOP);
// The title scrolls away with the list; row text is deferred glyphs
// (composited above raster fills), so a fixed title would show through
// rows scrolled over it.
if (TITLE_Y - scrollY + font.lineHeight > 0) {
image.drawText(font, TITLE_X, TITLE_Y - scrollY, "Calendar", 220);
}
let cursorY = LIST_TOP - scrollY;
for (let index = 0; index < rows.length; index++) {
const row = rows[index]!;
@@ -96,7 +106,7 @@ export class CalendarLayer implements Layer {
for (let index = 0; index < lines.length; index++) {
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);
image.drawText(font, 24, height - 36, `${GESTURE_CLICK} request`, 110);
}
}
@@ -119,7 +129,7 @@ function buildEventRows(font: UiFont, events: CalendarEvent[]): EventRow[] {
event,
dayHeader,
lines,
height: (dayHeader ? DAY_HEADER_HEIGHT : 0) + 6 + lines.length * lineStep(font),
height: (dayHeader ? dayHeaderHeight(font) : 0) + 6 + lines.length * lineStep(font),
});
}
return rows;
@@ -137,7 +147,7 @@ function drawEventRow(
let cursorY = y;
if (row.dayHeader) {
image.drawText(font, x, cursorY + 2, row.dayHeader, 150);
cursorY += DAY_HEADER_HEIGHT;
cursorY += dayHeaderHeight(font);
}
const bodyHeight = row.lines.length * lineStep(font) + 4;
if (selected) {
+52 -42
View File
@@ -1,7 +1,6 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { truncateText, wrapText } from "../../graphics/textwrap";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
import { drawSelectionHighlight } from "../../ui/menu";
import { TextViewerLayer } from "../files/text-viewer";
@@ -42,60 +41,71 @@ export class EvenHubStoreDetailLayer implements Layer {
const font = getDefaultSmallFont();
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 += 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 += 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 += step;
}
y += 4;
const metadata = [
`${formatCount(this.app.installCount)} installs · ${formatCount(this.app.likeCount)} likes`,
this.app.version ? `Version ${this.app.version}${this.app.fileSize ? ` · ${formatBytes(this.app.fileSize)}` : ""}` : "",
this.app.categories.length ? `Categories: ${this.app.categories.join(", ")}` : "",
this.app.firstPublishedAt ? `Published: ${formatDate(this.app.firstPublishedAt)}` : "",
].filter(Boolean);
for (const line of metadata) {
image.drawText(font, X, y, truncateText(font, line, textWidth), 125);
y += step;
}
const installed = getInstalledEvenHubApp(this.app.packageId);
const actions = ["About", "What's New", this.working ? "Installing..." : installed ? "Launch" : "Install"];
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 - step, y + 2), truncateText(font, this.status, textWidth), 180);
// Detail lines as (text, shade, extra gap below); built per candidate
// width so the layout choice below can measure before drawing.
const buildLines = (textWidth: number): { text: string; value: number; gapAfter: number }[] => {
const lines: { text: string; value: number; gapAfter: number }[] = [];
lines.push({ text: truncateText(font, this.app.name, textWidth), value: 235, gapAfter: 2 });
const creator = this.app.creatorName ? `by ${this.app.creatorName}` : this.app.packageId;
lines.push({ text: truncateText(font, creator, textWidth), value: 130, gapAfter: 6 });
const summary = this.app.tagline || this.app.description || "No description supplied.";
const summaryLines = wrapText(font, summary, textWidth).slice(0, 3);
for (const [index, line] of summaryLines.entries()) {
lines.push({ text: line, value: 205, gapAfter: index === summaryLines.length - 1 ? 4 : 0 });
}
const metadata = [
`${formatCount(this.app.installCount)} installs · ${formatCount(this.app.likeCount)} likes`,
this.app.version ? `Version ${this.app.version}${this.app.fileSize ? ` · ${formatBytes(this.app.fileSize)}` : ""}` : "",
this.app.categories.length ? `Categories: ${this.app.categories.join(", ")}` : "",
this.app.firstPublishedAt ? `Published: ${formatDate(this.app.firstPublishedAt)}` : "",
].filter(Boolean);
for (const line of metadata) {
lines.push({ text: truncateText(font, line, textWidth), value: 125, gapAfter: 0 });
}
if (installed && !this.status) {
lines.push({ text: `Installed version ${installed.version}`, value: 155, gapAfter: 0 });
}
if (this.status) {
lines.push({ text: truncateText(font, this.status, textWidth), value: 180, gapAfter: 0 });
}
return lines;
};
const linesHeight = (lines: { gapAfter: number }[]): number =>
lines.reduce((sum, line) => sum + step + line.gapAfter, 0);
// Stacked layout (details full-width, actions at the bottom) when it
// fits; otherwise the actions become a narrow top-right menu and the
// details flow down a left column beside it.
const stackedActionTop = height - 6 - actions.length * actionRowH;
const stacked = 8 + linesHeight(buildLines(width - X * 2)) + 6 <= stackedActionTop;
const menuW = 150;
const menuX = width - menuW - 12;
const textWidth = stacked ? width - X * 2 : menuX - X - 14;
let y = 8;
for (const line of buildLines(textWidth)) {
image.drawText(font, X, y, line.text, line.value);
y += step + line.gapAfter;
}
const actionX = stacked ? X : menuX;
const actionW = stacked ? textWidth : menuW;
const actionTop = stacked ? stackedActionTop : 8;
for (let index = 0; index < actions.length; index++) {
const actionY = actionTop + index * actionRowH;
const selected = index === this.selectedIndex;
if (selected) {
drawSelectionHighlight(image, X - 5, actionY, textWidth + 10, actionRowH - 1, ctx.stack.isFocused(), 8);
drawSelectionHighlight(image, actionX - 5, actionY, actionW + 10, actionRowH - 1, ctx.stack.isFocused(), 8);
}
image.drawText(font, X + 6, actionY + 5, actions[index]!, this.working && index === 2 ? 145 : selected ? 245 : 190);
const value = this.working && index === 2 ? 145 : selected ? 245 : 190;
image.drawText(font, actionX + 6, actionY + 5, truncateText(font, actions[index]!, actionW - 8), value);
}
image.drawText(
font,
X,
height - font.lineHeight - 4,
`${GESTURE_SCROLL} select ${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} back`,
105,
);
return image;
}
+15 -19
View File
@@ -1,8 +1,8 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { GrayImage, type UiFont } from "../../graphics/image";
import { truncateText, wrapText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
import { GESTURE_CLICK } from "../../ui/gestures";
import { type DashboardInputEvent, type Layer, type LayerActions, type LayerContext } from "../../ui/layers";
import {
drawListScrollbar,
@@ -25,10 +25,13 @@ import {
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
import { lineStep } from "../../ui/metrics";
const HEADER_HEIGHT = 34;
const FOOTER_HEIGHT = 22;
const LIST_X = 18;
/** Header: title line, then the status/subtitle line, then a small gap. */
function headerHeight(font: UiFont): number {
return 8 + lineStep(font) + font.lineHeight + 6;
}
export type EvenHubStoreLayerOptions = {
launchApp: (appId: string) => Promise<void> | void;
appendLog: (message: string) => void;
@@ -62,35 +65,30 @@ export class EvenHubStoreLayer implements Layer {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const headerH = headerHeight(font);
image.drawText(font, LIST_X, 8, "EvenHub", 220);
const subtitle = this.status || (this.total ? `${this.apps.length} of ${this.total} public apps` : "Public apps");
image.drawText(font, LIST_X, 22, truncateText(font, subtitle, width - LIST_X * 2), 125);
image.drawText(font, LIST_X, 8 + lineStep(font), truncateText(font, subtitle, width - LIST_X * 2), 125);
if (this.showingLogin) {
const message = this.loading
? "Signing in..."
: "Enter your Even account email and password in the phone app.";
for (const [index, line] of wrapText(font, message, width - LIST_X * 2).entries()) {
image.drawText(font, LIST_X, HEADER_HEIGHT + 22 + index * 15, line, 190);
image.drawText(font, LIST_X, headerH + 16 + index * lineStep(font), line, 190);
}
image.drawText(
font,
LIST_X,
height - 16,
truncateText(font, `${GESTURE_CLICK} edit credentials ${GESTURE_DOUBLE_CLICK} back`, width - LIST_X * 2),
105,
);
image.drawText(font, LIST_X, height - font.lineHeight - 4, `${GESTURE_CLICK} edit credentials`, 105);
return image;
}
if (this.apps.length === 0) {
const message = this.loading ? "Loading apps..." : this.status || "No apps returned.";
image.drawText(font, LIST_X, HEADER_HEIGHT + 28, truncateText(font, message, width - LIST_X * 2), 190);
image.drawText(font, LIST_X, headerH + 22, truncateText(font, message, width - LIST_X * 2), 190);
} else {
this.selectedIndex = clamp(this.selectedIndex, 0, this.apps.length - 1);
const rowH = Math.max(30, 2 * lineStep(font) + 4);
const visibleRows = Math.max(1, Math.floor((height - HEADER_HEIGHT - FOOTER_HEIGHT) / rowH));
const visibleRows = Math.max(1, Math.floor((height - headerH - 4) / rowH));
this.scrollRow = scrollToKeepSelectionVisible(
this.scrollRow,
this.selectedIndex,
@@ -100,7 +98,7 @@ 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) * rowH;
const y = headerH + (index - this.scrollRow) * rowH;
const selected = index === this.selectedIndex;
if (selected) {
drawSelectionHighlight(image, LIST_X - 6, y, width - LIST_X * 2 + 12, rowH - 2, ctx.stack.isFocused(), 5);
@@ -110,12 +108,10 @@ export class EvenHubStoreLayer implements Layer {
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 * rowH - 3, this.scrollRow, visibleRows, this.apps.length);
drawListScrollbar(image, width - 5, headerH, 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 - font.lineHeight - 4, truncateText(font, hint, width - LIST_X * 2), 105);
return image;
}
+13 -22
View File
@@ -3,9 +3,8 @@ import { truncateText, truncateLeft } from "../../graphics/textwrap";
import { GrayImage, type UiFont } from "../../graphics/image";
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 { iconGridMinRowHeight, tightRowHeight } from "../../ui/metrics";
import { ConfigSettingEnum } from "../../ui/dashboard-settings";
import { getStringSetting, setStringSetting } from "../../native/settings-store";
import {
@@ -20,14 +19,12 @@ import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/lay
const LIST_X = 20;
/** Header: title line + path line (34px at the 12px bitmap default). */
/** Header: one line holding both the title and the current path. */
function headerHeight(font: UiFont): number {
return 8 + lineStep(font) + font.lineHeight;
return 10 + font.lineHeight;
}
const GRID_COLS = 5;
const GRID_VISIBLE_ROWS = 3;
const GRID_BOTTOM_MARGIN = 20;
const ICON_SIZE = 44;
const LABEL_GAP = 2;
@@ -142,7 +139,8 @@ export class FileBrowserLayer implements Layer {
image.drawText(font, 20, 8, "Files", 220);
const pathLabel = this.location === null ? "Places" : this.location;
image.drawText(font, 20, 8 + lineStep(font), truncateLeft(font, pathLabel, width - 40), 130);
const pathX = 20 + font.measureText("Files") + 14;
image.drawText(font, pathX, 8, truncateLeft(font, pathLabel, width - pathX - 20), 130);
if (filesViewModeSetting.get() === "list") {
this.paintList(image, font, rows, ctx);
@@ -158,7 +156,7 @@ export class FileBrowserLayer implements Layer {
const rowH = tightRowHeight(font);
const headerH = headerHeight(font);
const listHeight = height - headerH - font.lineHeight - 10;
const listHeight = height - headerH - 4;
const visibleRows = Math.max(1, (listHeight / rowH) | 0);
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.listIndex, visibleRows, rows.length);
@@ -173,8 +171,6 @@ export class FileBrowserLayer implements Layer {
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 - font.lineHeight - 4, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110);
}
private paintIcons(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
@@ -184,12 +180,13 @@ export class FileBrowserLayer implements Layer {
this.selectedRow = clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1));
const gridTop = headerHeight(font);
const gridBottom = height - GRID_BOTTOM_MARGIN;
const rowH = Math.floor((gridBottom - gridTop) / GRID_VISIBLE_ROWS);
const gridBottom = height - 6;
const visibleRows = Math.max(1, Math.floor((gridBottom - gridTop) / iconGridMinRowHeight(font, ICON_SIZE, LABEL_GAP)));
const rowH = Math.floor((gridBottom - gridTop) / visibleRows);
const colW = width / GRID_COLS;
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, GRID_VISIBLE_ROWS, iconRows.length);
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, visibleRows, iconRows.length);
const lastVisible = Math.min(iconRows.length, this.scrollRow + GRID_VISIBLE_ROWS);
const lastVisible = Math.min(iconRows.length, this.scrollRow + visibleRows);
for (let rowIndex = this.scrollRow; rowIndex < lastVisible; rowIndex++) {
const row = iconRows[rowIndex]!;
const y = gridTop + (rowIndex - this.scrollRow) * rowH;
@@ -229,15 +226,9 @@ export class FileBrowserLayer implements Layer {
}
}
if (iconRows.length > GRID_VISIBLE_ROWS) {
drawListScrollbar(image, width - 5, gridTop, GRID_VISIBLE_ROWS * rowH - 4, this.scrollRow, GRID_VISIBLE_ROWS, iconRows.length);
if (iconRows.length > visibleRows) {
drawListScrollbar(image, width - 5, gridTop, visibleRows * rowH - 4, this.scrollRow, visibleRows, iconRows.length);
}
const hint =
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 - font.lineHeight - 4, hint, 110);
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
+11 -24
View File
@@ -5,13 +5,9 @@ import { GrayImage } from "../../graphics/image";
import { type Plane } from "../../graphics/plane";
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 { DashboardInputEvent, Layer, LayerActions, LayerContext } from "../../ui/layers";
import { drawSelectionHighlight, MenuLayer, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
import { iconGridMinRowHeight } from "../../ui/metrics";
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
import { onAnySettingChanged } from "../../ui/dashboard-settings";
import { createInProcessWindow } from "../../ui/shell/in-process-window";
@@ -49,17 +45,9 @@ export const LAUNCHER_WINDOW_ID = "launcher";
export const LAUNCHER_SURFACE_ID = "window:launcher";
const COLS = 5;
// Row height is sized so 3.5 rows fit the viewport: three full rows are
// always visible, and a fourth (half-clipped) row peeks in to signal that
// there are more apps to scroll to.
const VISIBLE_ROWS = 3.5;
const FULL_ROWS = Math.floor(VISIBLE_ROWS);
const GRID_TOP = 6;
const FOOTER_HEIGHT = 16;
const ICON_SIZE = 44;
const LABEL_GAP = 2;
/** Extra top inset for the folder-name header while inside a folder. */
const FOLDER_HEADER_HEIGHT = 16;
type LauncherMode = "row" | "item";
@@ -255,16 +243,22 @@ class LauncherGridLayer implements Layer {
Math.max(0, this.itemsInRow(entries.length, this.selectedRow) - 1),
);
const gridTop = this.currentFolder !== null ? GRID_TOP + FOLDER_HEADER_HEIGHT : GRID_TOP;
// The folder-name header band scales with the font.
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : GRID_TOP;
if (this.currentFolder !== null) {
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160);
}
const gridBottom = height - FOOTER_HEIGHT;
const rowH = (gridBottom - gridTop) / VISIBLE_ROWS;
const gridBottom = height - 4;
// Rows are exactly as tall as their content (icon + label + breathing
// room), so row height tracks the font instead of stretching to fill the
// viewport. Leftover space below the last full row shows the top of the
// next row when there are more apps to scroll to.
const rowH = iconGridMinRowHeight(font, ICON_SIZE, LABEL_GAP);
const fullRows = Math.max(1, Math.floor((gridBottom - gridTop) / rowH));
const colW = width / COLS;
// Scroll to keep the selected row among the fully-visible rows.
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, FULL_ROWS, rows);
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, fullRows, rows);
const rowY = (row: number) => gridTop + (row - this.scrollRow) * rowH;
@@ -309,13 +303,6 @@ class LauncherGridLayer implements Layer {
}
}
const selectedEntry = entries[this.selectedRow * COLS + this.selectedCol];
const pickVerb = selectedEntry?.kind === "folder" ? "open" : "launch";
const hint =
this.mode === "row"
? `${GESTURE_SCROLL} row ${GESTURE_CLICK} pick ${GESTURE_DOUBLE_CLICK} back`
: `${GESTURE_SCROLL} item ${GESTURE_CLICK} ${pickVerb} ${GESTURE_DOUBLE_CLICK} row`;
image.drawText(font, 8, height - 14, hint, 110);
return image;
}
+2 -1
View File
@@ -1,7 +1,7 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-bridge";
import { NightscoutLayer } from "./nightscout";
import { NightscoutLayer, nightscoutMenuItems } from "./nightscout";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -34,6 +34,7 @@ export function createNightscoutAppWindow(options: InProcessAppOptions): InProce
iconLetter: "Ns",
icon: "nightscout",
closeable: true,
menuItems: nightscoutMenuItems,
actions: options.actions,
baseLayer: new YieldAtRootLayer(new NightscoutLayer()),
submitFrame: options.submitFrame,
+91 -91
View File
@@ -1,5 +1,6 @@
import { getDefaultLargeFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage, imageFromAsciiArt, type UiFont } from "../../graphics/image";
import { GrayImage, type UiFont } from "../../graphics/image";
import { truncateText } from "../../graphics/textwrap";
import { DashboardInputEvent, Layer, LayerContext } from "../../ui/layers";
import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-bridge";
import {
@@ -9,10 +10,10 @@ import {
textSettingMenuItem,
} from "../../ui/dashboard-settings";
import { formatAgeShortFromTimestamp, formatTimestamp } from "~/util/date-util";
import { MenuLayer } from "../../ui/menu";
import { type MenuItem } from "../../ui/menu";
import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel";
import { lineStep } from "../../ui/metrics";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
const nightscoutLargeFont = getDefaultLargeFont();
const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
@@ -32,49 +33,44 @@ function drawDirectionIndicator(
return;
}
const art = directionAsciiArt(direction);
if (art) {
image.bitBlt(imageFromAsciiArt(art, shade), x, y + 1);
return;
}
if (direction) {
image.drawText(font, x, y, truncateLine(direction, 10), shade);
}
}
/**
* The trend as unicode arrows (U+2191..U+2198), drawn as ordinary text so
* they scale with the font. A bitmap face missing a diagonal falls back to
* the vertical arrow; a face with no arrows at all falls back to the raw
* direction text in drawDirectionIndicator.
*/
function directionGlyphLabel(font: UiFont, direction: string): string {
const pick = (...candidates: string[]): string => {
for (const candidate of candidates) {
if (font.hasGlyph(candidate.codePointAt(0)!)) return candidate;
}
return "";
};
switch (direction) {
case "DoubleUp":
return font.hasGlyph("↑".codePointAt(0)!) ? "↑↑" : "";
return pick("↑").repeat(2);
case "SingleUp":
return font.hasGlyph("↑".codePointAt(0)!) ? "↑" : "";
return pick("↑");
case "FortyFiveUp":
return font.hasGlyph("↗".codePointAt(0)!) ? "↗" : "";
return pick("↗", "↑");
case "Flat":
return font.hasGlyph("→".codePointAt(0)!) ? "→" : "";
return pick("→");
case "FortyFiveDown":
return font.hasGlyph("↘".codePointAt(0)!) ? "↘" : "";
return pick("↘", "↓");
case "SingleDown":
return font.hasGlyph("↓".codePointAt(0)!) ? "↓" : "";
return pick("↓");
case "DoubleDown":
return font.hasGlyph("↓".codePointAt(0)!) ? "↓↓" : "";
return pick("↓").repeat(2);
default:
return "";
}
}
function directionAsciiArt(direction: string): readonly string[] | undefined {
switch (direction) {
case "FortyFiveUp":
return [" ##", " ###", " # ##", "# ##", " ##"];
case "FortyFiveDown":
return [" ##", "# ##", " # ##", " ###", " ##"];
default:
return undefined;
}
}
function truncateLine(text: string, maxChars: number): string {
if (text.length <= maxChars) return text;
return `${text.slice(0, Math.max(0, maxChars - 3))}...`;
@@ -301,98 +297,102 @@ export class NightscoutLayer implements Layer {
const image = new GrayImage(width, height, 0);
const nightscout = nightscoutBridge.snapshot();
const nowMs = Date.now();
const footerY = height - 26;
const step = lineStep(font);
image.drawText(font, 22, 16, "Nightscout", 220);
if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) {
image.drawText(font, 22, 44, "Nightscout needs configuration.", 180);
image.drawText(font, 22, 62, `Set the site URL and API token in ${GESTURE_CLICK} menu > Settings.`, 140);
image.drawText(font, 22, footerY, `${GESTURE_CLICK} menu ${GESTURE_DOUBLE_CLICK} back`, 110);
image.drawText(font, 22, 44 + step, "Long-press for the menu, then pick Settings to set", 140);
image.drawText(font, 22, 44 + 2 * step, "the site URL and API token.", 140);
return image;
}
if (!nightscout.available || !nightscout.latest) {
image.drawText(font, 22, 44, "No Nightscout data available.", 180);
image.drawText(font, 22, 58, truncateLine(nightscout.status, 60), 140);
image.drawText(font, 22, footerY, `${GESTURE_CLICK} menu ${GESTURE_DOUBLE_CLICK} back`, 110);
image.drawText(font, 22, 44 + step, truncateLine(nightscout.status, 60), 140);
return image;
}
// Two-column header above the graph: title + current glucose on the
// left, the status lines bottom-aligned on the right.
const graphTop = 128;
const latest = nightscout.latest;
const glucoseText = `${latest.sgv}`;
const glucoseX = 22;
const glucoseWidth = nightscoutLargeFont.measureText(glucoseText);
image.drawText(nightscoutLargeFont, glucoseX, 28, glucoseText, 230);
// Glucose value vertically centered between the title and the graph.
const titleBottom = 16 + font.lineHeight;
const glucoseY = Math.round((titleBottom + graphTop - nightscoutLargeFont.lineHeight) / 2);
image.drawText(nightscoutLargeFont, glucoseX, glucoseY, glucoseText, 230);
if (isNightscoutPointStale(latest, nowMs)) {
drawNightscoutValueStrikeThrough(image, glucoseX, 40, glucoseWidth);
drawNightscoutValueStrikeThrough(image, glucoseX, glucoseY + (nightscoutLargeFont.lineHeight >> 1), glucoseWidth);
}
image.drawText(font, glucoseX + glucoseWidth + 8, 36, nightscout.units, 140);
const trendText = `Delta ${formatDelta(nightscout.delta)} Trend `;
image.drawText(font, 22, 62, trendText, 180);
drawDirectionIndicator(image, font, 22 + font.measureText(trendText), 62, nightscout.direction, 180);
image.drawText(
font,
22,
78,
`IOB ${nightscout.iob === null ? "--" : nightscout.iob.toFixed(2)} COB ${nightscout.cob === null ? "--" : formatWholeNumber(nightscout.cob)} Updated ${formatTimestamp(latest.timestampMs)}`,
160,
);
image.drawText(
font,
22,
94,
`CAGE ${formatAgeShortFromTimestamp(nightscout.cageTimestampMs, nowMs)} Loop ${nightscout.openapsStatusShort}`,
160,
);
image.drawText(font, 22, 110, `Pump ${truncateLine(nightscout.pumpStatus || "--", 56)}`, 150);
const graphHeight = Math.max(40, height - 128 - 48);
drawNightscoutGraph(image, { x: 22, y: 128, width: width - 44, height: graphHeight }, nightscout, nowMs, font);
image.drawText(font, 22, height - 42, "2-hour glucose history with basal / carbs / boluses", 130);
image.drawText(font, 22, footerY, `${GESTURE_CLICK} menu ${GESTURE_DOUBLE_CLICK} back`, 110);
image.drawText(font, glucoseX + glucoseWidth + 8, glucoseY + nightscoutLargeFont.lineHeight - font.lineHeight, nightscout.units, 140);
const statusX = 170;
const statusWidth = width - 22 - statusX;
const statusLines: { text: string; shade: number; direction?: string }[] = [
{ text: `Delta ${formatDelta(nightscout.delta)} Trend `, shade: 180, direction: nightscout.direction },
{
text: `IOB ${nightscout.iob === null ? "--" : nightscout.iob.toFixed(2)} COB ${nightscout.cob === null ? "--" : formatWholeNumber(nightscout.cob)} Updated ${formatTimestamp(latest.timestampMs)}`,
shade: 160,
},
{
text: `CAGE ${formatAgeShortFromTimestamp(nightscout.cageTimestampMs, nowMs)} Loop ${nightscout.openapsStatusShort}`,
shade: 160,
},
{ text: `Pump ${nightscout.pumpStatus || "--"}`, shade: 150 },
];
let statusY = graphTop - 8 - statusLines.length * step;
for (const line of statusLines) {
if (line.direction !== undefined) {
image.drawText(font, statusX, statusY, line.text, line.shade);
drawDirectionIndicator(image, font, statusX + font.measureText(line.text), statusY, line.direction, line.shade);
} else {
image.drawText(font, statusX, statusY, truncateText(font, line.text, statusWidth), line.shade);
}
statusY += step;
}
const captionY = height - font.lineHeight - 6;
const graphHeight = Math.max(40, captionY - 6 - graphTop);
drawNightscoutGraph(image, { x: 22, y: graphTop, width: width - 44, height: graphHeight }, nightscout, nowMs, font);
image.drawText(font, 22, captionY, "2-hour glucose history with basal / carbs / boluses", 130);
return image;
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
switch (event.type) {
case "click":
ctx.stack.push(createNightscoutMenu());
return;
case "double-click":
ctx.stack.pop();
return;
default:
return;
// The menu lives on the window's long-press menu (see nightscoutMenuItems);
// double-click at the app root is handled by the yield wrapper.
if (event.type === "double-click") {
ctx.stack.pop();
}
}
}
/** The app menu (opened with a click); MenuLayer self-closes on double-click. */
function createNightscoutMenu(): MenuLayer {
return new MenuLayer(
"Nightscout",
[
{
label: "Refresh",
onSelect: async (ctx) => {
ctx.stack.pop();
await nightscoutBridge.refreshNow();
},
/** App-specific entries for the window's long-press menu. */
export function nightscoutMenuItems(): MenuItem[] {
return [
{
label: "Refresh",
onSelect: async (ctx) => {
ctx.stack.pop();
await nightscoutBridge.refreshNow();
},
{
label: "Settings",
onSelect: (ctx) => {
// Pop the menu first so closing the settings modal lands back on
// the glucose view, not this menu.
ctx.stack.pop();
openSettingsSubMenu(ctx, "Nightscout settings", [
textSettingMenuItem(nightscoutSiteUrlSetting),
textSettingMenuItem(nightscoutApiTokenSetting),
]);
},
},
{
label: "Settings",
onSelect: (ctx) => {
// Pop the menu first so closing the settings modal lands back on
// the glucose view, not this menu.
ctx.stack.pop();
openSettingsSubMenu(ctx, "Nightscout settings", [
textSettingMenuItem(nightscoutSiteUrlSetting),
textSettingMenuItem(nightscoutApiTokenSetting),
]);
},
],
{ x: 8, y: 8, width: 200, minHeight: 0 },
);
},
];
}
function isNightscoutPointStale(point: NightscoutState["latest"], nowMs: number): boolean {
+4 -24
View File
@@ -17,13 +17,7 @@ import type { MenuItem } from "../../ui/menu";
import { defaultWindowMenuItems, WindowMenu } from "../../ui/window-menu";
import type { WorkerAppMessage, WorkerAppReply } from "../../ui/shell/worker-window";
import type { ToolResult, ToolSpec } from "../../assistant/tool-registry";
import {
GESTURE_CLICK,
GESTURE_DOUBLE_CLICK,
GESTURE_LONG_PRESS,
GESTURE_SCROLL,
gestureHints,
} from "../../ui/gestures";
import { GESTURE_CLICK } from "../../ui/gestures";
import { DocumentView } from "../../ui/document/document-view";
import { docNodePageLink, type DocNode } from "../../ui/document/document-model";
import {
@@ -51,8 +45,8 @@ import {
declare const global: any;
declare const com: any;
const HEADER_HEIGHT = 26;
const FOOTER_HEIGHT = 18;
const HEADER_HEIGHT = 30;
const BOTTOM_MARGIN = 6;
const DOC_MARGIN = 6;
/** Reload the shown page when it is foregrounded and older than this. */
const STALE_AFTER_MS = 60_000;
@@ -159,7 +153,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
menu: null,
view: new DocumentView(
message.viewport.width - DOC_MARGIN * 2,
message.viewport.height - HEADER_HEIGHT - FOOTER_HEIGHT,
message.viewport.height - HEADER_HEIGHT - BOTTOM_MARGIN,
),
lastSubmittedFingerprint: "",
};
@@ -549,20 +543,6 @@ function paintContent(win: RoamWindow): GrayImage {
} else {
win.view.paint(image, DOC_MARGIN, HEADER_HEIGHT, win.focused);
}
const footer = gestureHints([
[GESTURE_SCROLL, "move"],
[GESTURE_CLICK, "toggle/open"],
[GESTURE_DOUBLE_CLICK, backStack.length > 0 ? "back" : "leave"],
[GESTURE_LONG_PRESS, "menu"],
]);
image.drawText(
smallFont,
Math.max(DOC_MARGIN, Math.round((win.viewportWidth - smallFont.measureText(footer)) / 2)),
win.viewportHeight - FOOTER_HEIGHT + 3,
footer,
110,
);
return image;
}
+5
View File
@@ -2,6 +2,7 @@ import { type Plane } from "../../graphics/plane";
import { LayerActions } from "../../ui/layers";
import { EditTextSettingLayer } from "../../ui/dashboard-settings";
import { createSettingsPanelLayer } from "../../ui/dashboard/settings-menus";
import { SettingsDescriptionOverlayLayer } from "../../ui/dashboard/settings-panel";
import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-process-window";
import { type ShellWindow } from "../../ui/shell/shell";
@@ -54,6 +55,10 @@ export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAp
onClosed: options.onClosed,
});
const { window, stack, requestRender } = inProcess;
// The help-text band draws as its own plane so it can partially occlude
// list rows (a plane's raster covers lower planes' glyphs); it forwards
// input to the panel, so the stack behaves as if the panel were on top.
stack.push(new SettingsDescriptionOverlayLayer(panel));
return {
window,
inProcess,
+11 -10
View File
@@ -35,6 +35,7 @@ import { GrayImage, type UiFont } from "../../graphics/image";
import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane";
import { prepareFrameDraws } from "../../graphics/glyph-wire";
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
import { truncateText } from "../../graphics/textwrap";
import { TERMINAL_ICON_GLYPHS } from "../../graphics/icons";
import * as frameTimings from "../../native/frame-timings";
import { GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
@@ -1408,21 +1409,23 @@ function paintHub(window: HubWindow): GrayImage {
const font = chromeFont();
const step = lineStep(font);
// No border box: the shell chrome (top bar + sidebar) already frames the app.
image.drawText(font, 18, 10, window.mode === "connections" ? "Terminal - Connections" : "Terminal", 220);
const statusY = 16 + step;
image.drawText(font, 24, statusY, hubStatusLine(window), 170);
// Title and status share the top line.
const title = window.mode === "connections" ? "Terminal - Connections" : "Terminal";
image.drawText(font, 18, 10, title, 220);
const statusX = 18 + font.measureText(title) + 16;
image.drawText(font, statusX, 10, truncateText(font, hubStatusLine(window), Math.max(0, window.viewportWidth - statusX - 12)), 170);
let listTop = statusY + step + 8;
let listTop = 16 + step;
if (window.mode === "sessions" && controls.size === 0) {
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;
image.drawText(font, 24, listTop, "Add a g2mirror:// connection to get started, see:", 150);
image.drawText(font, 24, listTop + step, "https://github.com/jimrandomh/g2mirror", 190);
listTop += 2 * step + 6;
}
const items = hubItems(window);
clampHubSelection(window, items);
const hubRowH = listRowHeight(chromeFont());
const visibleRowCount = Math.max(1, ((window.viewportHeight - 30 - listTop) / hubRowH) | 0);
const visibleRowCount = Math.max(1, ((window.viewportHeight - 6 - 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++) {
@@ -1452,7 +1455,6 @@ function paintHub(window: HubWindow): GrayImage {
);
}
image.drawText(font, 24, window.viewportHeight - font.lineHeight - 12, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
@@ -1526,7 +1528,6 @@ function paintView(window: ViewWindow): GrayImage {
if (!window.receivedData) {
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;
}
+9
View File
@@ -38,6 +38,15 @@ export function createWeatherAppWindow(options: InProcessAppOptions): InProcessW
iconLetter: "W",
icon: "cloud-sun",
closeable: true,
menuItems: () => [
{
label: "Refresh",
onSelect: (ctx) => {
ctx.stack.pop();
requestUpdate();
},
},
],
actions: options.actions,
baseLayer: new YieldAtRootLayer(new WeatherLayer(() => weatherBridge.snapshot(), requestUpdate)),
submitFrame: options.submitFrame,
+44 -39
View File
@@ -3,10 +3,10 @@ import { GrayImage, type UiFont } from "../../graphics/image";
import { wrapText, truncateText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import { type ForecastPeriod, type WeatherState } from "../../native/weather";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
import { GESTURE_CLICK } from "../../ui/gestures";
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
import { drawSelectionHighlight, scrollToKeepSelectionVisible } from "../../ui/menu";
import { tightRowHeight } from "../../ui/metrics";
import { lineStep, tightRowHeight } from "../../ui/metrics";
const PAGE_X = 18;
const HEADER_Y = 8;
@@ -16,11 +16,8 @@ const FORECAST_HEADER_Y = 105;
const FORECAST_TOP = 124;
/** 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;
const FORECAST_PRECIP_X = 184;
const FORECAST_SUMMARY_X = 244;
/** Gap between forecast columns. */
const FORECAST_COL_GAP = 14;
/** Weather's current-conditions summary and scrollable 12-hour forecast. */
export class WeatherLayer implements Layer {
@@ -55,23 +52,16 @@ export class WeatherLayer implements Layer {
width,
height,
"Allow approximate location on your phone to get local weather.",
`${GESTURE_CLICK} request ${GESTURE_DOUBLE_CLICK} back`,
`${GESTURE_CLICK} request`,
);
return image;
}
if (weather.phase === "locating" || weather.phase === "loading") {
this.drawMessage(image, font, width, height, weather.status, `${GESTURE_DOUBLE_CLICK} back`);
this.drawMessage(image, font, width, height, weather.status);
return image;
}
if (weather.phase === "error") {
this.drawMessage(
image,
font,
width,
height,
weather.status,
`${GESTURE_CLICK} retry ${GESTURE_DOUBLE_CLICK} back`,
);
this.drawMessage(image, font, width, height, weather.status, `${GESTURE_CLICK} retry`);
return image;
}
@@ -83,7 +73,11 @@ export class WeatherLayer implements Layer {
handleInput(event: DashboardInputEvent): void {
const weather = this.state();
if (event.type === "click") {
this.requestUpdate();
// Refresh on the forecast view lives in the long-press menu; a tap
// only acts on the permission prompt and the error screen.
if (weather.phase === "permission-required" || weather.phase === "error") {
this.requestUpdate();
}
return;
}
if (!weather.forecast.length || weather.phase !== "ready") return;
@@ -102,23 +96,29 @@ export class WeatherLayer implements Layer {
const small = getDefaultSmallFont();
const temperature = current.temperatureF === null ? "--°" : `${Math.round(current.temperatureF)}°F`;
image.drawText(large, PAGE_X, CURRENT_TOP + 8, temperature, 245);
// Description / details / source stack compactly from just below the
// header line, so at large font sizes they stay clear of the forecast
// table instead of running into it.
let cy = 30;
image.drawText(
medium,
CURRENT_TEXT_X,
CURRENT_TOP + 5,
cy,
truncateText(medium, current.description || "Current conditions", width - CURRENT_TEXT_X - PAGE_X),
220,
);
cy += medium.lineHeight + 2;
const details: string[] = [];
if (current.humidityPercent !== null) details.push(`Humidity ${Math.round(current.humidityPercent)}%`);
if (current.windSpeedMph !== null) {
details.push(`Wind ${current.windDirection ? `${current.windDirection} ` : ""}${Math.round(current.windSpeedMph)} mph`);
}
image.drawText(small, CURRENT_TEXT_X, CURRENT_TOP + 35, details.join(" ") || "Current forecast", 170);
image.drawText(small, CURRENT_TEXT_X, cy, details.join(" ") || "Current forecast", 170);
cy += lineStep(small);
const source = current.observed ? "Observed" : "Forecast";
const age = current.timestampMs ? formatAge(Date.now() - current.timestampMs) : "";
image.drawText(small, CURRENT_TEXT_X, CURRENT_TOP + 54, `${source}${age ? ` ${age}` : ""}`, 105);
image.drawText(small, CURRENT_TEXT_X, cy, `${source}${age ? ` ${age}` : ""}`, 105);
image.drawLine(PAGE_X, FORECAST_HEADER_Y - 7, width - PAGE_X, FORECAST_HEADER_Y - 7, 40);
}
@@ -136,13 +136,24 @@ export class WeatherLayer implements Layer {
}
this.selectedIndex = clamp(this.selectedIndex, 0, forecast.length - 1);
const rowH = Math.max(FORECAST_MIN_ROW_HEIGHT, tightRowHeight(font) + 3);
const visibleRows = Math.max(1, Math.floor((height - FOOTER_HEIGHT - FORECAST_TOP) / rowH));
// The last row only needs its text line (not a full row pitch of
// clearance below), which usually fits one more row before the bottom.
const visibleRows = Math.max(1, 1 + Math.floor((height - FORECAST_TOP - (font.lineHeight + 4)) / rowH));
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedIndex, visibleRows, forecast.length);
// Columns are sized to the widest period name so names ("Wednesday
// Night") never truncate; the summary column absorbs what's left.
const nameWidth = Math.max(
font.measureText("Upcoming"),
...forecast.map((period) => font.measureText(period.name)),
);
const tempX = PAGE_X + nameWidth + FORECAST_COL_GAP;
const precipX = tempX + Math.max(font.measureText("Temp"), font.measureText("100°F")) + FORECAST_COL_GAP;
const summaryX = precipX + Math.max(font.measureText("Rain"), font.measureText("100%")) + FORECAST_COL_GAP;
image.drawText(font, PAGE_X, FORECAST_HEADER_Y, "Upcoming", 150);
image.drawText(font, FORECAST_TEMP_X, FORECAST_HEADER_Y, "Temp", 105);
image.drawText(font, FORECAST_PRECIP_X, FORECAST_HEADER_Y, "Rain", 105);
image.drawText(font, width - PAGE_X - font.measureText(`${this.selectedIndex + 1}/${forecast.length}`), FORECAST_HEADER_Y, `${this.selectedIndex + 1}/${forecast.length}`, 105);
image.drawText(font, tempX, FORECAST_HEADER_Y, "Temp", 105);
image.drawText(font, precipX, FORECAST_HEADER_Y, "Rain", 105);
const last = Math.min(forecast.length, this.scrollRow + visibleRows);
for (let index = this.scrollRow; index < last; index++) {
@@ -153,19 +164,11 @@ export class WeatherLayer implements Layer {
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);
image.drawText(font, FORECAST_TEMP_X, y + 2, period.temperatureF === null ? "--" : `${Math.round(period.temperatureF)}°F`, shade);
image.drawText(font, FORECAST_PRECIP_X, y + 2, period.precipitationPercent === null ? "--" : `${Math.round(period.precipitationPercent)}%`, selected ? 220 : 155);
image.drawText(font, FORECAST_SUMMARY_X, y + 2, truncateText(font, period.shortForecast, width - FORECAST_SUMMARY_X - PAGE_X), selected ? 220 : 165);
image.drawText(font, PAGE_X, y + 2, period.name, shade);
image.drawText(font, tempX, y + 2, period.temperatureF === null ? "--" : `${Math.round(period.temperatureF)}°F`, shade);
image.drawText(font, precipX, y + 2, period.precipitationPercent === null ? "--" : `${Math.round(period.precipitationPercent)}%`, selected ? 220 : 155);
image.drawText(font, summaryX, y + 2, truncateText(font, period.shortForecast, width - summaryX - PAGE_X), selected ? 220 : 165);
}
image.drawText(
font,
PAGE_X,
height - 15,
`${GESTURE_SCROLL} forecast ${GESTURE_CLICK} refresh ${GESTURE_DOUBLE_CLICK} back`,
105,
);
}
private drawMessage(
@@ -174,14 +177,16 @@ export class WeatherLayer implements Layer {
width: number,
height: number,
message: string,
footer: string,
footer?: string,
): void {
const lines = wrapText(font, message, width - 2 * (PAGE_X + 6));
const top = Math.max(52, Math.round((height - lines.length * 15) / 2) - 8);
for (let index = 0; index < lines.length; index++) {
image.drawText(font, PAGE_X + 6, top + index * 15, lines[index]!, 185);
}
image.drawText(font, PAGE_X, height - 20, footer, 110);
if (footer) {
image.drawText(font, PAGE_X, height - 20, footer, 110);
}
}
}
+16 -3
View File
@@ -6,6 +6,9 @@ const LOGO_PATH = "images/EvenRealitiesLogo.png";
let sourceLogo: GrayImage | null | undefined;
const scaledLogos = new Map<number, GrayImage>();
/** Fraction of the icon square left as padding on each side of the logo. */
const LOGO_PADDING_FRACTION = 0.1;
/** Render the bundled Even Realities logo at launcher/sidebar icon size. */
export function renderEvenRealitiesLogo(size: number): GrayImage | null {
const targetSize = Math.max(1, Math.round(size));
@@ -22,9 +25,19 @@ export function renderEvenRealitiesLogo(size: number): GrayImage | null {
}
if (!sourceLogo) return null;
const scaled = scaleToFit(sourceLogo, targetSize, targetSize);
scaledLogos.set(targetSize, scaled);
return scaled;
// The logo art fills its bitmap edge to edge, so give it a little padding
// within the icon square: scale to 80% and center.
const contentSize = Math.max(1, Math.round(targetSize * (1 - 2 * LOGO_PADDING_FRACTION)));
const scaled = scaleToFit(sourceLogo, contentSize, contentSize);
const icon = new GrayImage(targetSize, targetSize, 0);
icon.bitBlt(
scaled,
Math.round((targetSize - scaled.width) / 2),
Math.round((targetSize - scaled.height) / 2),
{ transparentZero: true },
);
scaledLogos.set(targetSize, icon);
return icon;
}
function scaleToFit(source: GrayImage, maxWidth: number, maxHeight: number): GrayImage {
+2 -2
View File
@@ -738,10 +738,10 @@ export function textSettingMenuItem<TId extends string = string>(
void ctx.actions.startTextSettingEdit(setting);
ctx.stack.push(new EditTextSettingLayer(setting));
},
render: ({ image, x, y }) => {
render: ({ image, x, y, width }) => {
// 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 + LIST_ROW_TEXT_INSET, `${setting.label}: ${truncateSetting(setting.displayValue())}`, 200);
drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width, setting.label, truncateSetting(setting.displayValue()));
}
};
}
+71 -27
View File
@@ -1,9 +1,8 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { GrayImage, type UiFont } from "../../graphics/image";
import { wrapText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../gestures";
import { DashboardInputEvent, Layer, LayerContext } from "../layers";
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "../layers";
import { drawSelectionHighlight, isMenuItemDisabled, MenuItem, MenuLayer, openModalMenu } from "../menu";
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../metrics";
import { shell } from "../shell/shell";
@@ -76,8 +75,7 @@ export class SettingsPanelLayer implements Layer {
const rowH = listRowHeight(font);
const top = PAD;
const hintY = height - font.lineHeight + 2;
const listBottom = hintY - 8; // leave a band for the gesture hint
const listBottom = height - PAD;
// Left column: section labels.
const leftRows = Math.max(1, ((listBottom - top) / rowH) | 0);
@@ -104,17 +102,16 @@ export class SettingsPanelLayer implements Layer {
rightTop = typeof used === "number" ? Math.min(top + used, listBottom) : listBottom;
}
if (rightItems.length && rightTop < listBottom) {
// Once focus is in the right column, the bottom of the pane shows the
// selected item's extended description (when it has one), with the row
// list shrunk to make room.
const selectedItem = this.focus === "right" ? rightItems[this.rightIndex] : undefined;
const descriptionLines = selectedItem?.description
? wrapText(font, selectedItem.description, rightW - 4).slice(0, MAX_DESCRIPTION_LINES)
: [];
const descriptionH = descriptionLines.length ? descriptionLines.length * lineStep(font) + 10 : 0;
const rightListBottom = listBottom - descriptionH;
const rightRows = Math.max(1, ((rightListBottom - rightTop) / rowH) | 0);
this.rightScroll = clampScroll(this.rightIndex, this.rightScroll, rightRows, rightItems.length);
// Once focus is in the right column, the selected item's extended
// description (when it has one) is drawn over the bottom of the pane by
// the companion SettingsDescriptionOverlayLayer. The row list keeps the
// full column height — rows the description band covers are drawn and
// partially occluded by the overlay's plane — but the scroll clamp uses
// the shrunk height so the selected row always stays clear of it.
const descriptionH = this.descriptionHeight(font, rightW);
const clampRows = Math.max(1, ((listBottom - descriptionH - rightTop) / rowH) | 0);
const rightRows = Math.max(1, ((listBottom - rightTop) / rowH) | 0);
this.rightScroll = clampScroll(this.rightIndex, this.rightScroll, clampRows, 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) * rowH;
@@ -141,22 +138,49 @@ export class SettingsPanelLayer implements Layer {
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 * lineStep(font), descriptionLines[i]!, 150);
}
}
}
const hint =
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, hintY, hint, 110);
return image;
}
/** The selected item's wrapped help text, or [] when none applies. */
private descriptionLines(font: UiFont, rightW: number): string[] {
if (this.focus !== "right") return [];
const items = this.section().items;
const item = items[clamp(this.rightIndex, 0, Math.max(0, items.length - 1))];
if (!item?.description) return [];
return wrapText(font, item.description, rightW - 4).slice(0, MAX_DESCRIPTION_LINES);
}
private descriptionHeight(font: UiFont, rightW: number): number {
const lines = this.descriptionLines(font, rightW);
return lines.length ? lines.length * lineStep(font) + 10 : 0;
}
/**
* Draw the selected item's help text band (separator + text on an opaque
* background) at the bottom of the right column. Called by the companion
* overlay layer with the overlay's own canvas: as a separate plane its
* raster covers the row list's glyphs, so it can partially occlude a row —
* which raster drawn into the panel's own image cannot do.
*/
paintDescriptionOverlay(image: GrayImage, ctx: LayerContext): void {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const listBottom = height - PAD;
const rightX = PAD + LEFT_W + 6 + 14;
const rightW = width - rightX - PAD;
const lines = this.descriptionLines(font, rightW);
if (!lines.length) return;
const top = listBottom - (lines.length * lineStep(font) + 10);
// 1 is opaque black in the plane model (0 is transparent).
image.fillRect(rightX - 2, top, rightW + 4, listBottom - top, 1);
image.drawLine(rightX, top, rightX + rightW, top, 40);
for (let i = 0; i < lines.length; i++) {
image.drawText(font, rightX + 4, top + 6 + i * lineStep(font), lines[i]!, 150);
}
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (this.focus === "left") {
switch (event.type) {
@@ -211,6 +235,26 @@ export class SettingsPanelLayer implements Layer {
}
}
/**
* Companion layer for SettingsPanelLayer, sitting permanently above it in the
* settings app's stack: paints the selected item's help text as its own plane
* (see paintDescriptionOverlay) and forwards all input to the panel. Pushed
* layers (modal menus, the text editor) stack above it as before.
*/
export class SettingsDescriptionOverlayLayer implements Layer {
constructor(private readonly panel: SettingsPanelLayer) {}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
this.panel.paintDescriptionOverlay(image, ctx);
return image;
}
handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
return this.panel.handleInput(event, ctx);
}
}
/**
* Open a third-level menu as a centered, bordered modal over the panel. Reuses
* MenuLayer (which draws the border and self-closes on double-click).
+17 -2
View File
@@ -19,9 +19,14 @@ export function listRowHeight(font: UiFont): number {
/** 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). */
/**
* Height of one row in dense lists (file browser, track lists). Grows at
* half the lineHeight's rate above the 12px anchor: TTF line heights carry
* internal leading that already reads as row spacing, so full-rate growth
* made large-font rows feel too tall.
*/
export function tightRowHeight(font: UiFont): number {
return font.lineHeight + 4;
return font.lineHeight + 4 - Math.floor(Math.max(0, font.lineHeight - 12) / 2);
}
/** Step between consecutive lines of body/paragraph text. */
@@ -33,3 +38,13 @@ export function lineStep(font: UiFont): number {
export function menuTitleHeight(font: UiFont): number {
return font.lineHeight + 4;
}
/**
* Minimum height of an icon-grid cell (icon, label line, breathing room).
* Grid views divide their available height into as many rows of at least
* this height as fit, so cells grow with the font instead of the label
* overflowing a fixed-height row.
*/
export function iconGridMinRowHeight(font: UiFont, iconSize: number, labelGap: number): number {
return iconSize + labelGap + font.lineHeight + 8;
}
+11 -5
View File
@@ -5,7 +5,6 @@ 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,
invokeNotificationAction,
@@ -20,6 +19,9 @@ import { type DashboardInputEvent, type Layer, type LayerContext, type PaintBelo
const PAGE_X = 12;
const PAGE_Y = 12;
// Title position, shared with the other list apps (terminal, calendar).
const TITLE_X = 18;
const TITLE_Y = 10;
const LIST_TOP = 38;
const CARD_X = 20;
const ICON_SIZE = 24;
@@ -79,10 +81,8 @@ export class NotificationsListLayer implements Layer {
buildNotificationCardLayout(font, notification, index === selectedIndex, cardTextWidth),
);
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notifications", 220);
image.drawText(font, width - 96, PAGE_Y + 9, `${selectedIndex + 1}/${notifications.length}`, 150);
if (!notifications.length) {
image.drawText(font, TITLE_X, TITLE_Y, "Notifications", 220);
const message = isNotificationListenerEnabled()
? "No current Android notifications."
: "Grant permission on your phone to view notifications on the glasses.";
@@ -90,13 +90,19 @@ export class NotificationsListLayer implements Layer {
for (let index = 0; index < messageLines.length; index++) {
image.drawText(font, 24, 72 + index * lineStep(font), messageLines[index]!, 190);
}
image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
return image;
}
const focused = ctx.stack.isFocused();
const listBottom = height;
const scrollY = scrollForSelected(layouts, selectedIndex, listBottom - LIST_TOP);
// The title scrolls away with the list. Card text is drawn as deferred
// glyphs (always composited above raster fills), so a fixed title would
// show through cards scrolled over it; moving it with the content keeps
// it above the first card instead.
if (TITLE_Y - scrollY + font.lineHeight > 0) {
image.drawText(font, TITLE_X, TITLE_Y - scrollY, "Notifications", 220);
}
let cursorY = LIST_TOP - scrollY;
for (let index = 0; index < layouts.length; index++) {
const layout = layouts[index]!;