Apps are variable height; add vertical position setting

This commit is contained in:
James Babcock committed 2026-07-31 14:52:51 -07:00
1 parent 6d42f0e65e
commit 7d2a41bd56
14 files changed
+301 -109

No files matched your search

+39 -20
View File
@@ -8,7 +8,15 @@ import { renderIcon, renderIconWithGlyph, type IconName } from "../../graphics/i
import { batteryDisplayModeSetting, timeFormatSetting } from "../dashboard-settings";
import { Layer } from "../layers";
import { scrollToKeepSelectionVisible } from "../menu";
import { SHELL_OPAQUE_BLACK, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
import {
MIN_WINDOW_HEIGHT,
minWindowTop,
SHELL_OPAQUE_BLACK,
SIDEBAR_WIDTH,
TOP_BAR_HEIGHT,
windowTop,
type WindowHeightMode,
} from "./geometry";
const ICON_SIZE = 32;
const ICON_MARGIN_X = ((SIDEBAR_WIDTH - ICON_SIZE) / 2) | 0;
@@ -30,6 +38,8 @@ export type ShellChromeState = {
windows: ShellChromeWindow[];
selectedIndex: number;
focus: "sidebar" | "window";
/** Height mode of the foreground window; decides where its top bar sits. */
foregroundHeightMode: WindowHeightMode;
battery: { headset: number | null; headsetCharging: boolean | null };
/** App-provided tray images, drawn between notification icons and batteries. */
trayIcons: GrayImage[];
@@ -103,13 +113,18 @@ export class ShellChromeLayer implements Layer {
}
private drawSidebar(image: GrayImage, state: ShellChromeState): void {
image.fillRect(0, 0, SIDEBAR_WIDTH, G2_LENS_HEIGHT, SHELL_OPAQUE_BLACK);
// The sidebar always occupies the min-height window band at the preferred
// vertical position: it never moves when the foreground window's height
// changes, and it lines up exactly with a min-height window's chrome.
const bandTop = minWindowTop();
const bandBottom = bandTop + MIN_WINDOW_HEIGHT;
image.fillRect(0, bandTop, SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, SHELL_OPAQUE_BLACK);
// Scroll the icon list to keep the selection visible; chevrons mark
// windows off-screen above/below.
const listTop = TOP_BAR_HEIGHT + 10;
const listTop = bandTop + TOP_BAR_HEIGHT + 10;
const itemStride = ICON_SIZE + ICON_SPACING;
const listHeight = G2_LENS_HEIGHT - listTop - 10;
const listHeight = bandBottom - listTop - 10;
const visibleCount = Math.max(1, ((listHeight + ICON_SPACING) / itemStride) | 0);
const count = state.windows.length;
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
@@ -125,10 +140,10 @@ export class ShellChromeLayer implements Layer {
const selTabTop = selVisible ? listTop + (state.selectedIndex - this.scrollRow) * itemStride - 2 : 0;
const selTabBottom = selTabTop + ICON_SIZE + 4;
if (selVisible) {
image.drawLine(sep, 0, sep, selTabTop, BORDER_VALUE);
image.drawLine(sep, selTabBottom, sep, G2_LENS_HEIGHT - 1, BORDER_VALUE);
image.drawLine(sep, bandTop, sep, selTabTop, BORDER_VALUE);
image.drawLine(sep, selTabBottom, sep, bandBottom - 1, BORDER_VALUE);
} else {
image.drawLine(sep, 0, sep, G2_LENS_HEIGHT - 1, BORDER_VALUE);
image.drawLine(sep, bandTop, sep, bandBottom - 1, BORDER_VALUE);
}
for (let index = this.scrollRow; index < lastVisible; index++) {
@@ -147,27 +162,31 @@ export class ShellChromeLayer implements Layer {
}
if (this.scrollRow > 0) {
drawChevron(image, SIDEBAR_WIDTH / 2, TOP_BAR_HEIGHT + 6, -1);
drawChevron(image, SIDEBAR_WIDTH / 2, bandTop + TOP_BAR_HEIGHT + 6, -1);
}
if (lastVisible < count) {
drawChevron(image, SIDEBAR_WIDTH / 2, G2_LENS_HEIGHT - 6, 1);
drawChevron(image, SIDEBAR_WIDTH / 2, bandBottom - 6, 1);
}
}
private drawTopBar(image: GrayImage, state: ShellChromeState): void {
const font = getDefaultMediumFont();
image.fillRect(SIDEBAR_WIDTH, 0, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(SIDEBAR_WIDTH, TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, TOP_BAR_HEIGHT - 1, BORDER_VALUE);
// The bar sits at the top edge of the foreground window: the screen top
// for a max-height window, the min-height band otherwise. It moves when
// the foreground switches to a window of a different height.
const barTop = windowTop(state.foregroundHeightMode);
image.fillRect(SIDEBAR_WIDTH, barTop, G2_LENS_WIDTH - SIDEBAR_WIDTH, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(SIDEBAR_WIDTH, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
const now = new Date();
const clock = `${WEEKDAYS[now.getDay()]} ${now.getDate()} ${MONTHS[now.getMonth()]} ` +
formatClockTime(now);
const clockX = SIDEBAR_WIDTH + 10;
const textY = Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
image.drawText(font, clockX, textY, clock, 210);
const batteryLeft = this.drawTopBarBatteries(image, state);
const trayLeft = drawTrayIcons(image, state.trayIcons, batteryLeft);
const batteryLeft = this.drawTopBarBatteries(image, state, barTop);
const trayLeft = drawTrayIcons(image, state.trayIcons, batteryLeft, barTop);
const iconsX = clockX + font.measureText(clock) + 16;
const maxIcons = Math.max(0, ((trayLeft - 8 - iconsX) / (NOTIFICATION_ICON_SIZE + 4)) | 0);
@@ -176,7 +195,7 @@ export class ShellChromeLayer implements Layer {
if (stale) {
noteStaleDataUsed();
}
const iconY = ((TOP_BAR_HEIGHT - NOTIFICATION_ICON_SIZE) / 2) | 0;
const iconY = barTop + (((TOP_BAR_HEIGHT - NOTIFICATION_ICON_SIZE) / 2) | 0);
for (let index = 0; index < icons.length; index++) {
image.bitBlt(icons[index]!, iconsX + index * (NOTIFICATION_ICON_SIZE + 4), iconY, {
transparentZero: true,
@@ -190,7 +209,7 @@ export class ShellChromeLayer implements Layer {
* the top bar, following the dashboard card's icon/percentage setting.
* Returns the left edge of the battery block.
*/
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState): number {
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number): number {
const font = getDefaultSmallFont();
const percentageMode = batteryDisplayModeSetting.get() === "percentage";
type BatteryItem = { label: string; percent: number; charging: boolean };
@@ -206,7 +225,7 @@ export class ShellChromeLayer implements Layer {
const labelGap = 5;
const itemGap = 12;
const textY = Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
let x = G2_LENS_WIDTH - 8;
for (let index = items.length - 1; index >= 0; index--) {
const item = items[index]!;
@@ -226,7 +245,7 @@ export class ShellChromeLayer implements Layer {
}
} else {
const icon = drawBattery(item.percent, item.charging);
image.bitBlt(icon, valueX, Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), {
image.bitBlt(icon, valueX, barTop + Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), {
transparentZero: true,
});
}
@@ -240,12 +259,12 @@ export class ShellChromeLayer implements Layer {
* Draw app tray icons right-to-left, ending just left of the battery block;
* returns the left edge of the tray region.
*/
function drawTrayIcons(image: GrayImage, trayIcons: GrayImage[], rightEdge: number): number {
function drawTrayIcons(image: GrayImage, trayIcons: GrayImage[], rightEdge: number, barTop: number): number {
let x = rightEdge;
for (let index = trayIcons.length - 1; index >= 0; index--) {
const icon = trayIcons[index]!;
x -= icon.width + 10;
image.bitBlt(icon, x, Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), {
image.bitBlt(icon, x, barTop + Math.max(0, ((TOP_BAR_HEIGHT - icon.height) / 2) | 0), {
transparentZero: true,
});
}
+2 -2
View File
@@ -2,7 +2,7 @@ import { MenuLayer } from "../menu";
import { ScreenTestLayer } from "../apps/screen-test";
import { BuzzerDemoLayer } from "../apps/buzzer-demo";
import { AccelerometerDemoLayer } from "../apps/accelerometer-demo";
import { APP_VIEWPORT } from "./geometry";
import { appViewportSize } from "./geometry";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -42,7 +42,7 @@ export function createDebugTestsAppWindow(options: InProcessAppOptions): InProce
y: 8,
width: 272,
minHeight: 0,
maxHeight: APP_VIEWPORT.height - 16,
maxHeight: appViewportSize("min").height - 16,
},
);
return createInProcessWindow({
+60 -7
View File
@@ -1,4 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
import { verticalPositionSetting } from "../dashboard-settings";
/** Top bar: 24px notification icons plus a little padding. */
export const TOP_BAR_HEIGHT = 28;
@@ -12,10 +13,62 @@ export const SIDEBAR_WIDTH = 36;
*/
export const SHELL_OPAQUE_BLACK = 1;
/** Screen region belonging to the foreground app window (compile-time fixed). */
export const APP_VIEWPORT = {
x: SIDEBAR_WIDTH,
y: TOP_BAR_HEIGHT,
width: G2_LENS_WIDTH - SIDEBAR_WIDTH,
height: G2_LENS_HEIGHT - TOP_BAR_HEIGHT,
} as const;
/**
* Windows come in two heights. "min" covers the same 288px band the stock
* firmware uses, leaving most of the field of view clear; "max" uses the
* whole 480px screen (terminal views). Both include a top bar drawn by the
* shell at the window's top edge.
*/
export type WindowHeightMode = "min" | "max";
/** Total height (top bar + content) of a min-height window. */
export const MIN_WINDOW_HEIGHT = 288;
/** Farthest down a min-height window can start. */
export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT;
/**
* Top edge (y) of a min-height window, from the Display > Vertical position
* setting. The sidebar and shell overlays always align to this band, even
* while a max-height window is foreground.
*/
export function minWindowTop(): number {
switch (verticalPositionSetting.get()) {
case "top":
return 0;
case "upper":
return Math.round(MIN_WINDOW_MAX_TOP * 0.25);
case "lower":
return Math.round(MIN_WINDOW_MAX_TOP * 0.75);
case "bottom":
return MIN_WINDOW_MAX_TOP;
default:
return Math.round(MIN_WINDOW_MAX_TOP * 0.5);
}
}
/** Top edge (y) of a window's top bar; max-height windows pin to the screen top. */
export function windowTop(mode: WindowHeightMode): number {
return mode === "max" ? 0 : minWindowTop();
}
/** App-content viewport size for a height mode (independent of vertical position). */
export function appViewportSize(mode: WindowHeightMode): { width: number; height: number } {
return {
width: G2_LENS_WIDTH - SIDEBAR_WIDTH,
height: (mode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT) - TOP_BAR_HEIGHT,
};
}
/** Screen rect of a window's app-content viewport (below its top bar). */
export function appViewportRect(mode: WindowHeightMode): {
x: number;
y: number;
width: number;
height: number;
} {
return {
x: SIDEBAR_WIDTH,
y: windowTop(mode) + TOP_BAR_HEIGHT,
...appViewportSize(mode),
};
}
+6 -2
View File
@@ -6,7 +6,7 @@ import { type MenuItem } from "../menu";
import { WindowMenuLayer } from "../window-menu";
import { windowIcon } from "./chrome-layer";
import { type IconName } from "../../graphics/icons";
import { APP_VIEWPORT } from "./geometry";
import { appViewportSize, type WindowHeightMode } from "./geometry";
import { shell, type ShellWindow } from "./shell";
/**
@@ -24,6 +24,8 @@ export type InProcessWindowOptions = {
/** Lucide icon name for the sidebar indicator; falls back to iconLetter. */
icon?: IconName;
closeable: boolean;
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode;
/**
* App-specific entries for the window's long-press menu, listed ahead of
* the default Voice input / Close window entries. Called at open time, so
@@ -60,10 +62,11 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
console.error(`${options.windowId} render failed: ${error}`);
});
};
const heightMode = options.heightMode ?? "min";
const stack = new LayerStack(
options.baseLayer,
{ ...options.actions, requestRender },
{ width: APP_VIEWPORT.width, height: APP_VIEWPORT.height },
appViewportSize(heightMode),
() => shell.isWindowFocused(options.windowId),
);
@@ -124,6 +127,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
title: options.title,
surfaceId: `window:${options.windowId}`,
closeable: options.closeable,
heightMode,
close: () => {
closed = true;
// Fire onRemoved for any pushed layers so they release resources (e.g. a
+22 -14
View File
@@ -1,23 +1,30 @@
import { GrayImage } from "../../graphics/image";
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
import { APP_VIEWPORT, SHELL_OPAQUE_BLACK } from "./geometry";
import { appViewportRect, appViewportSize, SHELL_OPAQUE_BLACK } from "./geometry";
// The modal covers most of the app viewport, leaving a little of the
// foreground app visible around the edges.
// The modal covers most of the min-height app viewport, leaving a little of
// the foreground app visible around the edges. Its size is fixed (min-height
// windows have a fixed viewport size); its position follows the vertical
// position setting, so it is computed per paint.
const MODAL_MARGIN = 14;
const MODAL_PADDING = 4;
export const MODAL_RECT = {
x: APP_VIEWPORT.x + MODAL_MARGIN,
y: APP_VIEWPORT.y + MODAL_MARGIN,
width: APP_VIEWPORT.width - 2 * MODAL_MARGIN,
height: APP_VIEWPORT.height - 2 * MODAL_MARGIN,
} as const;
export const MODAL_INTERIOR = {
width: MODAL_RECT.width - 2 * MODAL_PADDING,
height: MODAL_RECT.height - 2 * MODAL_PADDING,
width: appViewportSize("min").width - 2 * MODAL_MARGIN - 2 * MODAL_PADDING,
height: appViewportSize("min").height - 2 * MODAL_MARGIN - 2 * MODAL_PADDING,
} as const;
/** Screen rect of the modal box, aligned to the min-height window band. */
export function modalRect(): { x: number; y: number; width: number; height: number } {
const viewport = appViewportRect("min");
return {
x: viewport.x + MODAL_MARGIN,
y: viewport.y + MODAL_MARGIN,
width: viewport.width - 2 * MODAL_MARGIN,
height: viewport.height - 2 * MODAL_MARGIN,
};
}
/**
* A shell overlay hosting an inner layer stack in a bordered box over the
* app viewport (used for new-notification popups). The inner stack paints at
@@ -37,9 +44,10 @@ export class ShellModalLayer implements Layer {
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
const inner = this.stack.paint();
image.fillRoundedRect(MODAL_RECT.x, MODAL_RECT.y, MODAL_RECT.width, MODAL_RECT.height, SHELL_OPAQUE_BLACK, 8);
image.drawRoundedRect(MODAL_RECT.x, MODAL_RECT.y, MODAL_RECT.width, MODAL_RECT.height, 110, 8);
image.bitBlt(inner, MODAL_RECT.x + MODAL_PADDING, MODAL_RECT.y + MODAL_PADDING, { transparentZero: true });
const rect = modalRect();
image.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK, 8);
image.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 110, 8);
image.bitBlt(inner, rect.x + MODAL_PADDING, rect.y + MODAL_PADDING, { transparentZero: true });
return image;
}
+17 -6
View File
@@ -24,7 +24,7 @@ import { ShellChromeLayer, type ShellChromeState, type ShellChromeWindow } from
import { ShellModalLayer } from "./modal-layer";
import { ToolDebugMenuLayer } from "./tool-debug-layer";
import { toolRegistry } from "../../assistant/tool-registry";
import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
import { minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT, type WindowHeightMode } from "./geometry";
/**
* The shell: owns the window registry, focus, screen on/off, and the shell
@@ -49,6 +49,12 @@ export type ShellWindow = {
surfaceId: string;
/** Whether close menu entries (app menu default, shell escape menu) apply (the launcher is pinned). */
closeable: boolean;
/**
* Window height: the standard 288px band ("min") or the full screen
* ("max", terminal views). Decides the surface rect and where the shell
* draws this window's top bar.
*/
heightMode: WindowHeightMode;
/** App-side cleanup when the shell closes the window (worker notification, surface removal). */
close?: () => void;
drawIcon: ShellChromeWindow["drawIcon"];
@@ -97,9 +103,11 @@ const LONG_PRESS_ESCAPE_MENU_MS = 4000;
/** Shell-surface overlay menu (the escape menu); closing it returns focus to the sidebar. */
class ShellOverlayMenuLayer extends MenuLayer {
constructor(items: MenuItem[], private readonly onClosed: () => void) {
// Aligned to the min-height window band (like the sidebar), wherever the
// vertical position setting currently puts it.
super(null, items, {
x: SIDEBAR_WIDTH + 8,
y: TOP_BAR_HEIGHT + 8,
y: minWindowTop() + TOP_BAR_HEIGHT + 8,
width: 272,
minHeight: 0,
});
@@ -135,13 +143,15 @@ class ShellAlertLayer implements Layer {
paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage {
const image = paintBelow();
const font = getDefaultSmallFont();
image.fillRoundedRect(ALERT_X, ALERT_Y, ALERT_W, ALERT_H, 1, 10);
image.drawRoundedRect(ALERT_X, ALERT_Y, ALERT_W, ALERT_H, 90, 10);
image.drawText(font, ALERT_X + 16, ALERT_Y + 12, "Assistant", 200);
// Positioned within the min-height window band, like the other shell overlays.
const alertY = minWindowTop() + ALERT_Y;
image.fillRoundedRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1, 10);
image.drawRoundedRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90, 10);
image.drawText(font, ALERT_X + 16, alertY + 12, "Assistant", 200);
image.drawTextWrapped({
font,
x: ALERT_X + 16,
y: ALERT_Y + 34,
y: alertY + 34,
width: ALERT_W - 32,
text: this.text,
value: 235,
@@ -911,6 +921,7 @@ class Shell {
})),
selectedIndex: this.selectedIndex,
focus: this.focus,
foregroundHeightMode: this.foregroundWindow()?.heightMode ?? "min",
battery: this.battery,
trayIcons: Array.from(this.trayIcons.keys())
.sort()
+16 -9
View File
@@ -1,11 +1,11 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/bdffont";
import { wrapText } from "../../graphics/textwrap";
import { clamp } from "../../util/numeric-util";
import type { ToolDebugEntry } from "../../assistant/tool-registry";
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "../layers";
import { MenuLayer, drawListScrollbar, type MenuItem } from "../menu";
import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
import { MIN_WINDOW_HEIGHT, minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
/**
* Shell-overlay debug dialog (escape menu > Debug): lists the voice assistant
@@ -15,10 +15,16 @@ import { SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
*/
const DIALOG_X = SIDEBAR_WIDTH + 8;
const DIALOG_Y = TOP_BAR_HEIGHT + 8;
const DIALOG_WIDTH = 420;
const DETAIL_WIDTH = G2_LENS_WIDTH - DIALOG_X - 8;
const DETAIL_HEIGHT = G2_LENS_HEIGHT - DIALOG_Y - 8;
// Shell overlays align to the min-height window band; the detail box fills
// the band below the top bar with an 8px margin on each side.
const DETAIL_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 16;
/** Dialog top edge, aligned to the min-height band's content area. */
function dialogY(): number {
return minWindowTop() + TOP_BAR_HEIGHT + 8;
}
const DETAIL_PADDING = 14;
const DETAIL_LINE_HEIGHT = 14;
@@ -26,7 +32,7 @@ export class ToolDebugMenuLayer extends MenuLayer {
constructor(appId: string | null, entries: ToolDebugEntry[], private readonly onClosed: () => void) {
super(appId ? `Assistant tools: ${appId}` : "Assistant tools", buildItems(appId, entries), {
x: DIALOG_X,
y: DIALOG_Y,
y: dialogY(),
width: DIALOG_WIDTH,
minHeight: 0,
});
@@ -72,8 +78,9 @@ class ToolDetailLayer implements Layer {
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
const font = getDefaultSmallFont();
image.fillRoundedRect(DIALOG_X, DIALOG_Y, DETAIL_WIDTH, DETAIL_HEIGHT, 1, 10);
image.drawRoundedRect(DIALOG_X, DIALOG_Y, DETAIL_WIDTH, DETAIL_HEIGHT, 72, 10);
const top = dialogY();
image.fillRoundedRect(DIALOG_X, top, DETAIL_WIDTH, DETAIL_HEIGHT, 1, 10);
image.drawRoundedRect(DIALOG_X, top, DETAIL_WIDTH, DETAIL_HEIGHT, 72, 10);
const textX = DIALOG_X + DETAIL_PADDING;
const textWidth = DETAIL_WIDTH - 2 * DETAIL_PADDING - 8;
@@ -84,14 +91,14 @@ class ToolDetailLayer implements Layer {
const lastVisibleRow = Math.min(lines.length, this.scrollRow + visibleRowCount);
for (let index = this.scrollRow; index < lastVisibleRow; index++) {
const line = lines[index]!;
const y = DIALOG_Y + DETAIL_PADDING + (index - this.scrollRow) * DETAIL_LINE_HEIGHT;
const y = top + DETAIL_PADDING + (index - this.scrollRow) * DETAIL_LINE_HEIGHT;
image.drawText(font, textX, y, line.text, line.value);
}
if (lines.length > visibleRowCount) {
drawListScrollbar(
image,
DIALOG_X + DETAIL_WIDTH - 7,
DIALOG_Y + DETAIL_PADDING,
top + DETAIL_PADDING,
DETAIL_HEIGHT - 2 * DETAIL_PADDING,
this.scrollRow,
visibleRowCount,
+11 -4
View File
@@ -2,6 +2,7 @@ import { GrayImage } from "../../graphics/image";
import { windowIcon } from "./chrome-layer";
import { type IconName } from "../../graphics/icons";
import { toolRegistry, type ToolResult, type ToolSpec } from "../../assistant/tool-registry";
import { appViewportSize, type WindowHeightMode } from "./geometry";
import { shell, type ShellWindow } from "./shell";
/**
@@ -46,6 +47,8 @@ export type WorkerAppReply =
icon?: IconName;
iconGlyph?: string;
focus?: boolean;
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode;
}
| { type: "set-title"; windowId: string; title: string }
| { type: "set-attention"; windowId: string; attention: boolean }
@@ -100,14 +103,15 @@ export type WorkerWindowSpec = {
iconGlyph?: string;
/** Foreground and focus the window once its surface exists. */
focus?: boolean;
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode;
};
export type WorkerAppHostOptions = {
appId: string;
worker: Worker;
viewport: { width: number; height: number };
/** Create/refresh a window surface on the compositor (no-op when disconnected). */
configureSurface: (surfaceId: string, visible: boolean) => Promise<void>;
configureSurface: (surfaceId: string, visible: boolean, heightMode: WindowHeightMode) => Promise<void>;
setSurfaceVisible: (surfaceId: string, visible: boolean) => void;
removeSurface: (surfaceId: string) => void;
requestShellRender: () => void;
@@ -174,6 +178,7 @@ export class WorkerAppHost {
icon: message.icon,
iconGlyph: message.iconGlyph,
focus: message.focus,
heightMode: message.heightMode,
});
break;
case "set-attention":
@@ -242,12 +247,13 @@ export class WorkerAppHost {
/** Open a window of this app and register it with the shell. */
openWindow(spec: WorkerWindowSpec): ShellWindow {
const surfaceId = `window:${spec.windowId}`;
const heightMode = spec.heightMode ?? "min";
this.openWindows.add(spec.windowId);
this.post({
type: "open-window",
windowId: spec.windowId,
surfaceId,
viewport: this.options.viewport,
viewport: appViewportSize(heightMode),
});
const window: ShellWindow = {
appId: this.options.appId,
@@ -255,6 +261,7 @@ export class WorkerAppHost {
title: spec.title,
surfaceId,
closeable: true,
heightMode,
close: () => {
this.openWindows.delete(spec.windowId);
// Withdraw this window's tools and fail any in-flight calls to it.
@@ -301,7 +308,7 @@ export class WorkerAppHost {
// Configure the surface before any foregrounding so the worker's first
// frame has somewhere to land.
void this.options
.configureSurface(surfaceId, false)
.configureSurface(surfaceId, false, heightMode)
.then(() => {
if (spec.focus) {
shell.focusWindow(spec.windowId);