forked from Blendman974/faceclaw
Adapt layouts for Rayneo screen resolution
This commit is contained in:
1 parent
4d101eefe1
commit
dee60bbcd2
34 files changed
+721
-202
No files matched your search
@@ -8,7 +8,11 @@ import { appViewportRect, SHELL_OPAQUE_BLACK } from "./geometry";
|
||||
|
||||
const DIALOG_WIDTH = 272;
|
||||
const BAR_WIDTH = 12;
|
||||
/** The bar's height where the window has room (the G2's); it shrinks to fit a shorter one, down to MIN_BAR_HEIGHT. */
|
||||
const BAR_HEIGHT = 100;
|
||||
const MIN_BAR_HEIGHT = 24;
|
||||
/** Clear space kept above and below the dialog in the window. */
|
||||
const MARGIN_Y = 4;
|
||||
|
||||
/** Manual brightness changes apply immediately so the wearer can judge the level. */
|
||||
export class BrightnessPickerLayer implements Layer {
|
||||
@@ -22,7 +26,9 @@ export class BrightnessPickerLayer implements Layer {
|
||||
const image = paintBelow();
|
||||
const font = getDefaultSmallFont();
|
||||
const viewport = appViewportRect("min");
|
||||
const height = BAR_HEIGHT + 3 * font.lineHeight + 56;
|
||||
const chrome = 3 * font.lineHeight + 56;
|
||||
const barHeight = clamp(viewport.height - 2 * MARGIN_Y - chrome, MIN_BAR_HEIGHT, BAR_HEIGHT);
|
||||
const height = barHeight + chrome;
|
||||
const left = viewport.x + Math.round((viewport.width - DIALOG_WIDTH) / 2);
|
||||
const top = viewport.y + Math.round((viewport.height - height) / 2);
|
||||
image.fillRect(left, top, DIALOG_WIDTH, height, SHELL_OPAQUE_BLACK);
|
||||
@@ -35,14 +41,14 @@ export class BrightnessPickerLayer implements Layer {
|
||||
const barX = left + Math.round((DIALOG_WIDTH - BAR_WIDTH) / 2);
|
||||
const barY = top + font.lineHeight + 24;
|
||||
const level = brightnessSettingToLevel(brightnessSetting.get());
|
||||
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, BAR_HEIGHT + 4, 150);
|
||||
const filledHeight = Math.round(BAR_HEIGHT * (level ?? 0) / 100);
|
||||
image.fillRect(barX, barY + BAR_HEIGHT - filledHeight, BAR_WIDTH, filledHeight, 255);
|
||||
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((BAR_HEIGHT - font.lineHeight) / 2),
|
||||
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, barHeight + 4, 150);
|
||||
const filledHeight = Math.round(barHeight * (level ?? 0) / 100);
|
||||
image.fillRect(barX, barY + barHeight - filledHeight, BAR_WIDTH, filledHeight, 255);
|
||||
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((barHeight - font.lineHeight) / 2),
|
||||
level === null ? "Auto" : `${level}%`, 235);
|
||||
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + BAR_HEIGHT + 12, 150);
|
||||
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + barHeight + 12, 150);
|
||||
centeredText(gestureHints([[`${GESTURE_CLICK} / ${GESTURE_DOUBLE_CLICK}`, "confirm"]]),
|
||||
barY + BAR_HEIGHT + font.lineHeight + 16, 150);
|
||||
barY + barHeight + font.lineHeight + 16, 150);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { shellCrop } from "../../graphics/shell-scene";
|
||||
import type { Plane } from "../../graphics/plane";
|
||||
import { DrawOp, type ListCall, type ListClip } from "../../graphics/display-list";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, grayToNibble } from "../../graphics/image";
|
||||
import { GrayImage, grayToNibble } from "../../graphics/image";
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { activeAmbientCards } from "./ambient-cards";
|
||||
@@ -29,7 +29,9 @@ import { lineStep } from "../metrics";
|
||||
import {
|
||||
appViewportRect,
|
||||
isImmersive,
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowHeight,
|
||||
screenHeight,
|
||||
screenWidth,
|
||||
minWindowTop,
|
||||
setSwitcherBarHeight,
|
||||
SHELL_OPAQUE_BLACK,
|
||||
@@ -68,7 +70,10 @@ const TWO_COLUMN: SidebarVariant = { columns: 2, columnWidth: 32, iconSize: 28 }
|
||||
const ICON_SPACING = 8;
|
||||
/** Icon list top/bottom margins within the sidebar band, below the top bar (and a bottom row's end margins). */
|
||||
const LIST_MARGIN = 10;
|
||||
const LIST_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
|
||||
/** Height of the sidebar's icon list: the min-height band less its top bar and margins. */
|
||||
function listHeight(appId?: string): number {
|
||||
return minWindowHeight(appId) - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
|
||||
}
|
||||
|
||||
/** Bottom-row icons: one tall tab's worth of row, the icon inset 2px all round. */
|
||||
const ROW_ICON_SIZE = SWITCHER_ROW_HEIGHT - 4;
|
||||
@@ -123,7 +128,7 @@ const POPUP_DIM = 0.5;
|
||||
|
||||
/** Icon rows that fit in one sidebar column. */
|
||||
function rowsPerColumn(variant: SidebarVariant): number {
|
||||
return Math.max(1, ((LIST_HEIGHT + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
|
||||
return Math.max(1, ((listHeight() + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
|
||||
}
|
||||
|
||||
function sidebarVariant(windowCount: number): SidebarVariant {
|
||||
@@ -136,7 +141,7 @@ function sidebarVariant(windowCount: number): SidebarVariant {
|
||||
*/
|
||||
function columnLeft(variant: SidebarVariant, column: number, position: AppSwitcherPosition): number {
|
||||
return position === "right"
|
||||
? G2_LENS_WIDTH - SIDEBAR_WIDTH + column * variant.columnWidth
|
||||
? screenWidth() - SIDEBAR_WIDTH + column * variant.columnWidth
|
||||
: SIDEBAR_WIDTH - (column + 1) * variant.columnWidth;
|
||||
}
|
||||
|
||||
@@ -382,7 +387,7 @@ export function sidebarContentSpan(windowCount: number): { left: number; right:
|
||||
const variant = sidebarVariant(windowCount);
|
||||
const width = variant.columns * variant.columnWidth;
|
||||
return switcherPosition() === "right"
|
||||
? { left: G2_LENS_WIDTH - SIDEBAR_WIDTH, right: G2_LENS_WIDTH - SIDEBAR_WIDTH + width }
|
||||
? { left: screenWidth() - SIDEBAR_WIDTH, right: screenWidth() - SIDEBAR_WIDTH + width }
|
||||
: { left: SIDEBAR_WIDTH - width, right: SIDEBAR_WIDTH };
|
||||
}
|
||||
|
||||
@@ -396,7 +401,7 @@ function topBarSpan(state: ShellChromeState): { left: number; right: number } {
|
||||
if (sidebarStripVisible(state.focus, state.foregroundAppId)) {
|
||||
const position = switcherPosition();
|
||||
if (position === "left") left = Math.max(left, SIDEBAR_WIDTH);
|
||||
if (position === "right") right = Math.min(right, G2_LENS_WIDTH - SIDEBAR_WIDTH);
|
||||
if (position === "right") right = Math.min(right, screenWidth() - SIDEBAR_WIDTH);
|
||||
}
|
||||
return { left, right };
|
||||
}
|
||||
@@ -624,7 +629,7 @@ export class ShellChromeLayer implements Layer {
|
||||
) {}
|
||||
|
||||
paint(): GrayImage {
|
||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const image = new GrayImage(screenWidth(), screenHeight(), 0);
|
||||
const state = this.getState();
|
||||
this.statusEntries = [];
|
||||
this.bottomBar = this.layoutBottomBar(state);
|
||||
@@ -651,7 +656,7 @@ export class ShellChromeLayer implements Layer {
|
||||
this.statusEntries = [];
|
||||
this.bottomBar = this.layoutBottomBar(state);
|
||||
const statusInRow = statusInSwitcherRow(state.foregroundAppId);
|
||||
const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const canvas = new GrayImage(screenWidth(), screenHeight(), 0);
|
||||
const span = topBarSpan(state);
|
||||
const bar = statusBarPlacement(state);
|
||||
if (bar) {
|
||||
@@ -664,7 +669,7 @@ export class ShellChromeLayer implements Layer {
|
||||
return parts;
|
||||
}
|
||||
if (switcherShown) {
|
||||
const stripCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const stripCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
|
||||
const statusLeft = this.drawSidebar(stripCanvas, state, statusInRow ? canvas : undefined);
|
||||
// The window frame rides on the switcher row, whose top edge is its
|
||||
// bottom side, and so replays after any top bar, whose bottom row is
|
||||
@@ -704,14 +709,14 @@ export class ShellChromeLayer implements Layer {
|
||||
// to be sent at all, so the frame rides on one at its top-left corner,
|
||||
// outside its curve, which it paints black anyway. As in the bottom
|
||||
// row's case, it plays at the screen's own depth.
|
||||
const frameCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const frameCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
|
||||
frameCanvas.fillRect(frame.x, frame.y, 1, 1, SHELL_OPAQUE_BLACK);
|
||||
drawWindowFrame(frameCanvas, frame, false, true);
|
||||
parts.push(shellCrop(frameCanvas, frame.x, frame.y, 1, 1, 1));
|
||||
}
|
||||
drawAmbientCards(canvas, topBarSpan(state).right, parts);
|
||||
if (!switcherShown) return;
|
||||
const popupCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const popupCanvas = new GrayImage(screenWidth(), screenHeight(), 0);
|
||||
const box = this.drawPopup(popupCanvas, state);
|
||||
this.popupKey ??= LayerStack.allocateShellKey();
|
||||
parts.push({ ...shellCrop(popupCanvas, box.x, box.y, box.width, box.height, this.popupKey), depth: POPUP_DEPTH });
|
||||
@@ -892,8 +897,8 @@ export class ShellChromeLayer implements Layer {
|
||||
const batteries = batteryItems(state);
|
||||
if (batteries.length) {
|
||||
// Measured by drawing it: each battery style lays itself out as it draws.
|
||||
const scratch = new GrayImage(G2_LENS_WIDTH, TOP_BAR_HEIGHT, 0);
|
||||
const width = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN - drawBatteryBlock(scratch, batteries, 0, G2_LENS_WIDTH);
|
||||
const scratch = new GrayImage(screenWidth(), TOP_BAR_HEIGHT, 0);
|
||||
const width = screenWidth() - BATTERY_BLOCK_RIGHT_MARGIN - drawBatteryBlock(scratch, batteries, 0, screenWidth());
|
||||
// The block keeps its usual right margin inside the edge it's given.
|
||||
items.push({ kind: "batteries", width,
|
||||
draw: (image, x, top) => drawBatteryBlock(image, batteries, top, x + width + BATTERY_BLOCK_RIGHT_MARGIN) });
|
||||
@@ -1237,7 +1242,7 @@ function drawAmbientCards(image: GrayImage, right: number, parts?: Plane[]): voi
|
||||
if (!cards.length) return;
|
||||
const font = getDefaultSmallFont();
|
||||
const bandTop = minWindowTop();
|
||||
const bandBottom = bandTop + MIN_WINDOW_HEIGHT - windowFooterHeight();
|
||||
const bandBottom = bandTop + minWindowHeight() - windowFooterHeight();
|
||||
// Right-aligned with the top bar: clear of a right-hand sidebar.
|
||||
const x = right - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
|
||||
const textWidth = AMBIENT_CARD_WIDTH - 2 * AMBIENT_CARD_PADDING_X;
|
||||
|
||||
+36
-22
@@ -1,4 +1,4 @@
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
|
||||
import { screenHeight, screenWidth } from "../../graphics/screen-size";
|
||||
import {
|
||||
appSwitcherPositionSetting,
|
||||
type AppSwitcherPosition,
|
||||
@@ -12,6 +12,9 @@ import {
|
||||
windowBorderSetting,
|
||||
} from "../dashboard-settings";
|
||||
|
||||
/** The paired glasses' screen, which the shell lays out in (graphics/screen-size.ts). */
|
||||
export { screenHeight, screenWidth };
|
||||
|
||||
/** Top bar: 24px notification icons plus a little padding. */
|
||||
export const TOP_BAR_HEIGHT = 28;
|
||||
/**
|
||||
@@ -174,15 +177,15 @@ export function switcherRect(heightMode: WindowHeightMode, appId?: string): { x:
|
||||
const height = reserved || switcherBarHeights.overlay;
|
||||
return {
|
||||
x: appViewportLeft(appId),
|
||||
y: reserved > 0 ? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId) : G2_LENS_HEIGHT - height,
|
||||
y: reserved > 0 ? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId) : screenHeight() - height,
|
||||
width: appViewportWidth(appId),
|
||||
height,
|
||||
};
|
||||
}
|
||||
case "right":
|
||||
return { x: G2_LENS_WIDTH - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
|
||||
return { x: screenWidth() - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: minWindowHeight(appId) };
|
||||
default:
|
||||
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
|
||||
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: minWindowHeight(appId) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,15 +296,15 @@ export function isOnSwitcherEdge(x: number, y: number, heightMode: WindowHeightM
|
||||
case "bottom":
|
||||
return y >= switcherRect(heightMode, appId).y;
|
||||
case "right":
|
||||
return x >= G2_LENS_WIDTH - SIDEBAR_WIDTH;
|
||||
return x >= screenWidth() - SIDEBAR_WIDTH;
|
||||
default:
|
||||
return x < SIDEBAR_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
/** Width of app windows: the panel's when Full Screen or immersive, else 576 (see SIDEBAR_WIDTH). */
|
||||
/** Width of app windows: the screen's when Full Screen or immersive, else SIDEBAR_WIDTH less (576 on the G2). */
|
||||
function appViewportWidth(appId?: string): number {
|
||||
return fullWidth(appId) ? G2_LENS_WIDTH : G2_LENS_WIDTH - SIDEBAR_WIDTH;
|
||||
return fullWidth(appId) ? screenWidth() : screenWidth() - SIDEBAR_WIDTH;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,7 +356,7 @@ export function effectiveHeightMode(mode: WindowHeightMode, appId?: string): Win
|
||||
* rather than use the viewport's own centre.
|
||||
*/
|
||||
export function screenCenterInViewportX(): number {
|
||||
return Math.round(G2_LENS_WIDTH / 2) - appViewportLeft();
|
||||
return Math.round(screenWidth() / 2) - appViewportLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,15 +377,23 @@ export const SHELL_OPAQUE_BLACK = 1;
|
||||
*/
|
||||
export type WindowHeightMode = "min" | "medium" | "max";
|
||||
|
||||
/** Total height (header + content) of a min-height window. */
|
||||
/** Total height (header + content) of a min-height window on a screen with room for it: the G2's stock band. */
|
||||
export const MIN_WINDOW_HEIGHT = 288;
|
||||
|
||||
/**
|
||||
* Total height of a min-height window here: the stock 288px band, or the
|
||||
* whole window area on a screen too short for it (the RayNeo iO's 220 rows).
|
||||
*/
|
||||
export function minWindowHeight(appId?: string): number {
|
||||
return Math.min(MIN_WINDOW_HEIGHT, windowAreaHeight(appId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Height of the screen area windows are placed in: the whole screen, less
|
||||
* a bottom switcher's height.
|
||||
*/
|
||||
function windowAreaHeight(appId?: string): number {
|
||||
return G2_LENS_HEIGHT - switcherRowHeight(appId);
|
||||
return screenHeight() - switcherRowHeight(appId);
|
||||
}
|
||||
|
||||
/** Total height (header + content + footer) of a window's band in the given mode. */
|
||||
@@ -391,9 +402,9 @@ export function windowBandHeight(mode: WindowHeightMode, appId?: string): number
|
||||
case "max":
|
||||
return windowAreaHeight(appId);
|
||||
case "medium":
|
||||
return MIN_WINDOW_HEIGHT + windowHeaderHeight(appId) + windowFooterHeight(appId);
|
||||
return Math.min(windowAreaHeight(appId), minWindowHeight(appId) + windowHeaderHeight(appId) + windowFooterHeight(appId));
|
||||
default:
|
||||
return MIN_WINDOW_HEIGHT;
|
||||
return minWindowHeight(appId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +436,7 @@ export function minWindowTop(appId?: string): number {
|
||||
*/
|
||||
export function windowTop(mode: WindowHeightMode, appId?: string): number {
|
||||
const band = windowBandHeight(mode, appId);
|
||||
const oneRowArea = G2_LENS_HEIGHT - (switcherRowHeight(appId) > 0 ? SWITCHER_ROW_HEIGHT : 0);
|
||||
const oneRowArea = screenHeight() - (switcherRowHeight(appId) > 0 ? SWITCHER_ROW_HEIGHT : 0);
|
||||
const top = Math.round((oneRowArea - band) * verticalPositionFraction(appId));
|
||||
return Math.min(top, windowAreaHeight(appId) - band);
|
||||
}
|
||||
@@ -473,13 +484,13 @@ function unionRect(a: ScreenRect, b: ScreenRect): ScreenRect {
|
||||
* the whole panel. The phone mirror's Scaled preview zooms to this.
|
||||
*/
|
||||
export function usedScreenRect(heightMode: WindowHeightMode, appId?: string): ScreenRect {
|
||||
if (isImmersive(appId)) return { x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT };
|
||||
if (isImmersive(appId)) return { x: 0, y: 0, width: screenWidth(), height: screenHeight() };
|
||||
const frame = windowFramed(appId) ? 1 : 0;
|
||||
const x = appViewportLeft(appId) - frame;
|
||||
const width = appViewportWidth(appId) + 2 * frame;
|
||||
let used = unionRect(
|
||||
{ x, y: windowTop(heightMode, appId), width, height: windowBandHeight(heightMode, appId) },
|
||||
{ x, y: minWindowTop(appId), width, height: MIN_WINDOW_HEIGHT },
|
||||
{ x, y: minWindowTop(appId), width, height: minWindowHeight(appId) },
|
||||
);
|
||||
if (switcherPosition() !== "popup") used = unionRect(used, switcherRect(heightMode, appId));
|
||||
return used;
|
||||
@@ -487,15 +498,18 @@ export function usedScreenRect(heightMode: WindowHeightMode, appId?: string): Sc
|
||||
|
||||
/**
|
||||
* The screen area the phone mirror shows to present `used` as large as it
|
||||
* fits, centred, at the panel's own 4:3 aspect (so the mirror keeps its
|
||||
* shape whatever the display mode): `used` grown along one axis, past the
|
||||
* panel's edges if need be (the mirror shows black there).
|
||||
* fits, centred, at the screen's own aspect (4:3 on the G2, 27:11 on the iO),
|
||||
* so the mirror keeps its shape whatever the display mode: `used` grown along
|
||||
* one axis, past the screen's edges if need be (the mirror shows black there).
|
||||
*/
|
||||
export function phonePreviewRect(used: ScreenRect): ScreenRect {
|
||||
// Whole 4:3 units, so the aspect is exact.
|
||||
const units = Math.ceil(Math.max(used.width / 4, used.height / 3));
|
||||
const width = units * 4;
|
||||
const height = units * 3;
|
||||
// Whole aspect units, so the aspect is exact.
|
||||
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
|
||||
const unit = gcd(screenWidth(), screenHeight());
|
||||
const aspectW = screenWidth() / unit, aspectH = screenHeight() / unit;
|
||||
const units = Math.ceil(Math.max(used.width / aspectW, used.height / aspectH));
|
||||
const width = units * aspectW;
|
||||
const height = units * aspectH;
|
||||
return {
|
||||
x: Math.round(used.x + (used.width - width) / 2),
|
||||
y: Math.round(used.y + (used.height - height) / 2),
|
||||
|
||||
@@ -226,6 +226,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
options.reconfigureSurface?.(heightMode);
|
||||
requestRender();
|
||||
},
|
||||
layoutSize: () => stack.getBaseSize(),
|
||||
hitTest: async (x, y) => {
|
||||
const handled = await stack.hitTest(x, y);
|
||||
if (handled) requestRender();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { G2_LENS_WIDTH, GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { Menu, type MenuDrawArgs } from "../menu-core";
|
||||
import { listRowHeight, textInkBounds } from "../metrics";
|
||||
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
|
||||
import { minWindowHeight, minWindowTop, screenWidth } from "./geometry";
|
||||
|
||||
/**
|
||||
* The shared look of the shell's text dialogs (voice input, phone keyboard
|
||||
@@ -13,17 +13,26 @@ import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
|
||||
*/
|
||||
|
||||
const DIALOG_X = 40;
|
||||
const DIALOG_W = G2_LENS_WIDTH - 80;
|
||||
/** The screen less DIALOG_X on each side. */
|
||||
function dialogW(): number {
|
||||
return screenWidth() - 2 * DIALOG_X;
|
||||
}
|
||||
// The dialog fits inside the min-height window band (like the other shell
|
||||
// overlays), wherever the vertical position setting puts it.
|
||||
const DIALOG_MARGIN_Y = 28;
|
||||
const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y;
|
||||
const TEXT_MAX_WIDTH = DIALOG_W - 32;
|
||||
function dialogH(): number {
|
||||
return minWindowHeight() - 2 * DIALOG_MARGIN_Y;
|
||||
}
|
||||
function textMaxWidth(): number {
|
||||
return dialogW() - 32;
|
||||
}
|
||||
const TEXT_LEFT = DIALOG_X + 16;
|
||||
// Menu row boxes: 4px left of the text column, 2px shorter than the row
|
||||
// pitch, with each row's label inset 8px / 4px into its box.
|
||||
const MENU_X = TEXT_LEFT - 4;
|
||||
const MENU_W = DIALOG_W - 24;
|
||||
function menuW(): number {
|
||||
return dialogW() - 24;
|
||||
}
|
||||
const MENU_ROW_GAP = 2;
|
||||
const MENU_LABEL_INSET_X = 8;
|
||||
const MENU_LABEL_INSET_Y = 4;
|
||||
@@ -89,28 +98,28 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
|
||||
|
||||
// Solid dialog box over the underlying UI. Fill 1, not 0: identical after
|
||||
// 4bpp quantization, but 0 is transparent on the color-key shell surface.
|
||||
image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1);
|
||||
image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90);
|
||||
image.fillRect(DIALOG_X, top, dialogW(), dialogH(), 1);
|
||||
image.drawRect(DIALOG_X, top, dialogW(), dialogH(), 90);
|
||||
|
||||
// Title and status share one header line, the status in the space after the title.
|
||||
const left = TEXT_LEFT;
|
||||
const headerY = top + 12;
|
||||
image.drawText(font, left, headerY, content.title, 220);
|
||||
const statusLeft = left + Math.ceil(font.measureText(content.title)) + HEADER_STATUS_GAP;
|
||||
const statusWidth = TEXT_LEFT + TEXT_MAX_WIDTH - statusLeft;
|
||||
const statusWidth = TEXT_LEFT + textMaxWidth() - statusLeft;
|
||||
image.drawText(font, statusLeft, headerY, truncateText(font, content.status, statusWidth), content.statusValue ?? 130);
|
||||
|
||||
const menu = content.menu;
|
||||
const rowCount = menu?.items.length ?? 0;
|
||||
// Reserve space for the actual number of rows this menu has, or one row for the hint.
|
||||
const reservedRows = rowCount > 0 ? rowCount : content.hint ? 1 : 0;
|
||||
const textBottom = top + DIALOG_H - reservedRows * menuRowH - 8;
|
||||
const textBottom = top + dialogH() - reservedRows * menuRowH - 8;
|
||||
const textTop = headerY + font.lineHeight + 12;
|
||||
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
|
||||
|
||||
// The tail of a long message stays in view: it is what was said last (or
|
||||
// where the phone keyboard is typing).
|
||||
const wrapped = wrapText(font, content.text, TEXT_MAX_WIDTH);
|
||||
const wrapped = wrapText(font, content.text, textMaxWidth());
|
||||
const firstLine = Math.max(0, wrapped.length - maxLines);
|
||||
for (let index = firstLine; index < wrapped.length; index++) {
|
||||
image.drawText(font, left, textTop + (index - firstLine) * 16, wrapped[index]!, 235);
|
||||
@@ -118,11 +127,11 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
|
||||
|
||||
if (menu && rowCount > 0) {
|
||||
// Row boxes are one pitch apart, the last ending 6px above the dialog's bottom edge.
|
||||
const menuTop = top + DIALOG_H - rowCount * menuRowH - 4;
|
||||
menu.paint(image, { x: MENU_X, y: menuTop, width: MENU_W, height: rowCount * menuRowH - MENU_ROW_GAP }, true);
|
||||
const menuTop = top + dialogH() - rowCount * menuRowH - 4;
|
||||
menu.paint(image, { x: MENU_X, y: menuTop, width: menuW(), height: rowCount * menuRowH - MENU_ROW_GAP }, true);
|
||||
} else if (content.hint) {
|
||||
// On the line the last menu row's label would occupy, floating in front of the dialog.
|
||||
drawDepthText(image, font, truncateText(font, content.hint, TEXT_MAX_WIDTH), left, top + DIALOG_H - menuRowH, HINT_VALUE, HINT_DEPTH);
|
||||
drawDepthText(image, font, truncateText(font, content.hint, textMaxWidth()), left, top + dialogH() - menuRowH, HINT_VALUE, HINT_DEPTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-6
@@ -1,5 +1,5 @@
|
||||
import { encodeShellScene } from "../../graphics/shell-scene";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from "../../g2/events";
|
||||
@@ -82,6 +82,8 @@ import {
|
||||
windowFramed,
|
||||
windowTop,
|
||||
type WindowHeightMode,
|
||||
screenHeight,
|
||||
screenWidth,
|
||||
} from "./geometry";
|
||||
import type { AppSwitcherPosition } from "../dashboard-settings";
|
||||
|
||||
@@ -163,6 +165,12 @@ export type ShellWindow = {
|
||||
* they opened with when the bottom switcher changes height.
|
||||
*/
|
||||
relayout?: () => void;
|
||||
/**
|
||||
* The viewport size the window is laid out at (it changes on relayout), so
|
||||
* the controller can tell a window whose size fell behind the geometry from
|
||||
* one whose surface merely moved.
|
||||
*/
|
||||
layoutSize?: () => { width: number; height: number };
|
||||
/**
|
||||
* A touch from the phone's mirror at (x, y) in app-viewport coordinates.
|
||||
* True if the window acted on it; otherwise the controller sends a select.
|
||||
@@ -354,7 +362,10 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
/** How long a show_alert popup stays before auto-dismissing. */
|
||||
const ALERT_DISMISS_MS = 6000;
|
||||
const ALERT_X = 40;
|
||||
const ALERT_W = G2_LENS_WIDTH - 80;
|
||||
/** Alert width: the screen less ALERT_X on each side. */
|
||||
function alertW(): number {
|
||||
return screenWidth() - 2 * ALERT_X;
|
||||
}
|
||||
const ALERT_Y = 96;
|
||||
const ALERT_H = 96;
|
||||
|
||||
@@ -378,14 +389,14 @@ class ShellAlertLayer implements Layer {
|
||||
const font = getDefaultSmallFont();
|
||||
// Positioned within the min-height window band, like the other shell overlays.
|
||||
const alertY = minWindowTop() + ALERT_Y;
|
||||
image.fillRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1);
|
||||
image.drawRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90);
|
||||
image.fillRect(ALERT_X, alertY, alertW(), ALERT_H, 1);
|
||||
image.drawRect(ALERT_X, alertY, alertW(), ALERT_H, 90);
|
||||
image.drawText(font, ALERT_X + 16, alertY + 12, "Assistant", 200);
|
||||
image.drawTextWrapped({
|
||||
font,
|
||||
x: ALERT_X + 16,
|
||||
y: alertY + 18 + font.lineHeight + 4,
|
||||
width: ALERT_W - 32,
|
||||
width: alertW() - 32,
|
||||
text: this.text,
|
||||
value: 235,
|
||||
});
|
||||
@@ -965,7 +976,7 @@ class Shell {
|
||||
|
||||
paintSurface(): Plane[] {
|
||||
if (!this.screenOn) {
|
||||
return singlePlane(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0));
|
||||
return singlePlane(new GrayImage(screenWidth(), screenHeight(), 0));
|
||||
}
|
||||
return this.stack.paint();
|
||||
}
|
||||
|
||||
@@ -445,12 +445,13 @@ export class WorkerAppHost {
|
||||
const surfaceId = `window:${spec.windowId}`;
|
||||
const heightMode = spec.heightMode ?? "min";
|
||||
this.openWindows.add(spec.windowId);
|
||||
let viewport = appViewportSize(heightMode, this.options.appId);
|
||||
this.post({
|
||||
type: "open-window",
|
||||
windowId: spec.windowId,
|
||||
surfaceId,
|
||||
title: spec.title,
|
||||
viewport: appViewportSize(heightMode, this.options.appId),
|
||||
viewport,
|
||||
});
|
||||
const window: ShellWindow = {
|
||||
appId: this.options.appId,
|
||||
@@ -463,7 +464,11 @@ export class WorkerAppHost {
|
||||
// Every app worker resizes its live content in place, keeping its state
|
||||
// (a game in progress, a route): the bottom switcher's height changes
|
||||
// with what it holds, and full-height windows give way to it.
|
||||
relayout: () => this.post({ type: "resize-window", windowId: spec.windowId, viewport: appViewportSize(heightMode, this.options.appId) }),
|
||||
relayout: () => {
|
||||
viewport = appViewportSize(heightMode, this.options.appId);
|
||||
this.post({ type: "resize-window", windowId: spec.windowId, viewport });
|
||||
},
|
||||
layoutSize: () => viewport,
|
||||
hasAppMenu: () => this.windowGestures.get(spec.windowId)?.hasAppMenu ?? false,
|
||||
claimsLongPress: () => this.windowGestures.get(spec.windowId)?.claimsLongPress ?? false,
|
||||
close: () => {
|
||||
|
||||
Reference in new issue
Block a user