forked from Blendman974/faceclaw
Sidebar uses icons for apps
This commit is contained in:
1 parent
d0c30f9ca9
commit
22c779553c
27 files changed
+379
-37
No files matched your search
@@ -896,13 +896,13 @@ class DashboardController {
|
||||
this.requestShellRender();
|
||||
return;
|
||||
}
|
||||
host.openWindow({ windowId: "terminal:hub", title: "Terminal", iconLetter: "T", focus: true });
|
||||
host.openWindow({ windowId: "terminal:hub", title: "Terminal", iconLetter: "T", icon: "terminal", focus: true });
|
||||
this.appendLog("launched terminal:hub");
|
||||
return;
|
||||
}
|
||||
const serial = this.nextWindowSerial++;
|
||||
const windowId = `${appId}:${serial}`;
|
||||
host.openWindow({ windowId, title: `Stopwatch ${serial}`, iconLetter: "S", focus: true });
|
||||
host.openWindow({ windowId, title: `Stopwatch ${serial}`, iconLetter: "S", icon: "timer", focus: true });
|
||||
this.appendLog(`launched ${windowId}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { GrayImage } from "./image";
|
||||
|
||||
declare const com: any;
|
||||
declare const global: any;
|
||||
|
||||
/**
|
||||
* Vector icons for window indicators (and anywhere else). SVGs are rendered
|
||||
* once to a correctly sized grayscale bitmap by the Java IconRenderer (a
|
||||
* small SVG subset: path/circle/rect/line/polyline) and cached here. To add
|
||||
* an icon, drop its SVG source into ICON_SVGS — Lucide icons
|
||||
* (https://lucide.dev, stroked, 24px viewBox) work as-is; simple single-color
|
||||
* Noun Project glyphs also work.
|
||||
*/
|
||||
|
||||
// Stroke width in viewBox units (Lucide's default is 2).
|
||||
const ICON_STROKE_WIDTH = 2;
|
||||
|
||||
// Lucide icons (MIT/ISC licensed). Kept verbatim so they can be diffed
|
||||
// against upstream if an icon needs updating.
|
||||
export const ICON_SVGS = {
|
||||
"layout-grid":
|
||||
'<svg viewBox="0 0 24 24"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg>',
|
||||
timer:
|
||||
'<svg viewBox="0 0 24 24"><line x1="10" x2="14" y1="2" y2="2"/><line x1="12" x2="15" y1="14" y2="11"/><circle cx="12" cy="14" r="8"/></svg>',
|
||||
terminal:
|
||||
'<svg viewBox="0 0 24 24"><path d="m7 11 2-2-2-2"/><path d="M11 13h4"/><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/></svg>',
|
||||
"file-text":
|
||||
'<svg viewBox="0 0 24 24"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>',
|
||||
music:
|
||||
'<svg viewBox="0 0 24 24"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>',
|
||||
activity:
|
||||
'<svg viewBox="0 0 24 24"><path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"/></svg>',
|
||||
bell:
|
||||
'<svg viewBox="0 0 24 24"><path d="M10.268 21a2 2 0 0 0 3.464 0"/><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"/></svg>',
|
||||
"flask-conical":
|
||||
'<svg viewBox="0 0 24 24"><path d="M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2"/><path d="M6.453 15h11.094"/><path d="M8.5 2h7"/></svg>',
|
||||
settings:
|
||||
'<svg viewBox="0 0 24 24"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></svg>',
|
||||
mic:
|
||||
'<svg viewBox="0 0 24 24"><path d="M12 19v3"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><rect x="9" y="2" width="6" height="13" rx="3"/></svg>',
|
||||
} as const;
|
||||
|
||||
export type IconName = keyof typeof ICON_SVGS;
|
||||
|
||||
const cache = new Map<string, GrayImage | null>();
|
||||
|
||||
/** Render an icon SVG to a size×size grayscale bitmap, rendered once and cached. */
|
||||
export function renderIcon(name: IconName, size: number): GrayImage | null {
|
||||
const key = `${name}:${size}`;
|
||||
const cached = cache.get(key);
|
||||
if (cached !== undefined) return cached;
|
||||
|
||||
let icon: GrayImage | null = null;
|
||||
if (global.isAndroid) {
|
||||
try {
|
||||
const bytes = com.faceclaw.app.IconRenderer.renderSvgGray(ICON_SVGS[name], Math.round(size), ICON_STROKE_WIDTH);
|
||||
if (bytes && bytes.length >= size * size) {
|
||||
icon = new GrayImage(size, size, 0);
|
||||
for (let i = 0; i < size * size; i++) {
|
||||
icon.pixels[i] = bytes[i] & 0xff;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`renderIcon(${name}) failed: ${error}`);
|
||||
}
|
||||
}
|
||||
cache.set(key, icon);
|
||||
return icon;
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../layers";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../gestures";
|
||||
import { drawSelectionHighlight } from "../menu";
|
||||
import {
|
||||
buildSoundSequencePayload,
|
||||
CFW_SEQ_MAX,
|
||||
@@ -36,7 +38,7 @@ export class BuzzerDemoLayer implements Layer {
|
||||
const image = new GrayImage(width, height, 0);
|
||||
|
||||
image.drawText(font, 20, 8, "Buzzer demo", 220);
|
||||
const status = this.playing ? `Playing: ${this.playing}` : "Click to play";
|
||||
const status = this.playing ? `Playing: ${this.playing}` : `${GESTURE_CLICK} play`;
|
||||
image.drawText(font, width - 24 - font.measureText(status), 8, status, 140);
|
||||
|
||||
const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT;
|
||||
@@ -54,14 +56,13 @@ export class BuzzerDemoLayer implements Layer {
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 15, 4);
|
||||
image.drawRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 45, 4);
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
image.drawText(font, LIST_X, y + 1, effect.name, selected ? 255 : 200);
|
||||
image.drawText(font, LIST_X + 110, y + 1, effect.desc, selected ? 180 : 120);
|
||||
}
|
||||
|
||||
image.drawText(font, 20, height - 16, "Scroll: select Click: play Double-click: back", 110);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_SCROLL} select ${GESTURE_CLICK} play ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../gestures";
|
||||
import { drawSelectionHighlight } from "../menu";
|
||||
import {
|
||||
hasAllFilesAccess,
|
||||
listDirectory,
|
||||
@@ -70,14 +72,13 @@ export class FileBrowserLayer implements Layer {
|
||||
const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 15, 4);
|
||||
image.drawRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 45, 4);
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
const value = rowValue(row, selected);
|
||||
image.drawText(font, LIST_X, y + 1, truncateRight(font, row.label, width - 2 * LIST_X), value);
|
||||
}
|
||||
|
||||
image.drawText(font, 20, height - 16, "Click: open Double-click: up / back", 110);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-
|
||||
import { isNightscoutSettingsConfigured } from "../dashboard-settings";
|
||||
import { formatAgeShortFromTimestamp, formatTimestamp } from "~/util/date-util";
|
||||
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../gestures";
|
||||
const nightscoutLargeFont = getDefaultLargeFont();
|
||||
const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
|
||||
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
|
||||
@@ -294,7 +295,6 @@ export class NightscoutLayer implements Layer {
|
||||
const nightscout = nightscoutBridge.snapshot();
|
||||
const nowMs = Date.now();
|
||||
const footerY = height - 26;
|
||||
image.drawRect(12, 12, width - 24, height - 24, 52);
|
||||
image.drawText(font, 22, 16, "Nightscout", 220);
|
||||
|
||||
if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) {
|
||||
@@ -306,7 +306,7 @@ export class NightscoutLayer implements Layer {
|
||||
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, "Click: refresh Double-click: back", 110);
|
||||
image.drawText(font, 22, footerY, `${GESTURE_CLICK} refresh ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ export class NightscoutLayer implements Layer {
|
||||
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, "Click: refresh Double-click: back", 110);
|
||||
image.drawText(font, 22, footerY, `${GESTURE_CLICK} refresh ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ export class TelepromptLayer implements Layer {
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const footerY = height - FOOTER_MARGIN;
|
||||
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / LINE_STEP));
|
||||
image.drawRect(12, 12, width - 24, height - 24, 52);
|
||||
image.drawText(font, MARGIN_X + 4, TITLE_Y, truncateToWidth(font, this.title, width - 2 * MARGIN_X - 8), 220);
|
||||
|
||||
const lines = this.getLines(font, width);
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
||||
* (createTranscribeAppWindow); this layer accumulates the transcript, shows
|
||||
* it, and saves it to Downloads on click.
|
||||
*/
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../gestures";
|
||||
export class TranscribeLayer implements Layer {
|
||||
private status = "Listening...";
|
||||
// Finalized utterances, plus the live (replace-semantics) partial appended
|
||||
@@ -37,7 +38,6 @@ export class TranscribeLayer implements Layer {
|
||||
const text = this.displayText() || "Listening...";
|
||||
const wrapped = wrapTranscribeText(font, text, width - 64);
|
||||
|
||||
image.drawRect(12, 12, width - 24, height - 24, 52);
|
||||
image.drawText(font, 24, 20, "Transcribe", 200);
|
||||
image.drawText(font, 24, 40, this.saveNotice || this.status, 110);
|
||||
|
||||
@@ -50,7 +50,7 @@ export class TranscribeLayer implements Layer {
|
||||
image.drawText(font, 32, y, wrapped[index]!, 230);
|
||||
}
|
||||
|
||||
image.drawText(font, 24, footerY, "Click: save Double-click: back", 110);
|
||||
image.drawText(font, 24, footerY, `${GESTURE_CLICK} save ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
import {
|
||||
getBooleanSetting,
|
||||
getStringSetting,
|
||||
@@ -430,14 +431,13 @@ export class EditTextSettingLayer implements Layer {
|
||||
// viewport in the settings app).
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
image.drawRect(12, 12, width - 24, height - 24, 52);
|
||||
image.drawText(font, 22, 16, this.setting.glassesEditTitle, 220);
|
||||
const message = wrapText(font, "Look at the phone app to type a value.", width - 48);
|
||||
for (let index = 0; index < message.length; index++) {
|
||||
image.drawText(font, 22, 52 + index * 14, message[index]!, 200);
|
||||
}
|
||||
image.drawText(font, 22, 110, truncateSetting(this.setting.get(), 52), 220);
|
||||
image.drawText(font, 22, height - 36, "Double-click to go back", 110);
|
||||
image.drawText(font, 22, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Compact glyphs for the ring gestures, used in on-glasses hint text instead
|
||||
* of spelling the gesture out. All codepoints exist in terminus12/16.
|
||||
*
|
||||
* click · (U+00B7 middle dot)
|
||||
* double-click ·· (twice)
|
||||
* scroll ▲▼ (U+25B2 / U+25BC)
|
||||
* long-press - (hyphen-minus)
|
||||
*/
|
||||
export const GESTURE_CLICK = "·";
|
||||
export const GESTURE_DOUBLE_CLICK = "··";
|
||||
export const GESTURE_SCROLL_UP = "▲";
|
||||
export const GESTURE_SCROLL_DOWN = "▼";
|
||||
export const GESTURE_SCROLL = "▲▼";
|
||||
export const GESTURE_LONG_PRESS = "-";
|
||||
|
||||
/**
|
||||
* Join "glyph action" hint pairs into a single line, e.g.
|
||||
* gestureHints([[GESTURE_CLICK, "save"], [GESTURE_DOUBLE_CLICK, "back"]])
|
||||
* => "· save ·· back"
|
||||
*/
|
||||
export function gestureHints(pairs: Array<[string, string]>): string {
|
||||
return pairs.map(([glyph, action]) => `${glyph} ${action}`).join(" ");
|
||||
}
|
||||
+15
-1
@@ -57,8 +57,17 @@ export class LayerStack {
|
||||
private readonly ctx: LayerContext;
|
||||
private readonly baseWidth: number;
|
||||
private readonly baseHeight: number;
|
||||
private readonly focusedFn: () => boolean;
|
||||
|
||||
constructor(baseLayer: Layer, actions: LayerActions, baseSize?: { width: number; height: number }) {
|
||||
constructor(
|
||||
baseLayer: Layer,
|
||||
actions: LayerActions,
|
||||
baseSize?: { width: number; height: number },
|
||||
// Whether this stack is the current input target; drives the strength of
|
||||
// selection highlights (a visible-but-unfocused window dims its selection).
|
||||
// Defaults to always-focused for shell overlays and standalone stacks.
|
||||
isFocused: () => boolean = () => true,
|
||||
) {
|
||||
this.layers = [baseLayer];
|
||||
this.ctx = {
|
||||
stack: this,
|
||||
@@ -66,6 +75,11 @@ export class LayerStack {
|
||||
};
|
||||
this.baseWidth = baseSize?.width ?? G2_LENS_WIDTH;
|
||||
this.baseHeight = baseSize?.height ?? G2_LENS_HEIGHT;
|
||||
this.focusedFn = isFocused;
|
||||
}
|
||||
|
||||
isFocused(): boolean {
|
||||
return this.focusedFn();
|
||||
}
|
||||
|
||||
push(layer: Layer): void {
|
||||
|
||||
+32
-3
@@ -4,6 +4,7 @@ import { getDefaultSmallFont, type BdfFont } from "../graphics/bdffont";
|
||||
import { clamp } from "../util/numeric-util";
|
||||
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers";
|
||||
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
const DEFAULT_MENU_X = 8;
|
||||
const DEFAULT_MENU_Y = 8;
|
||||
const DEFAULT_MENU_WIDTH = 272;
|
||||
@@ -46,6 +47,26 @@ export type MenuItem = {
|
||||
render?: (args: MenuItemRenderArgs) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw a selection highlight for a list row. A focused list fills the row and
|
||||
* outlines it; a visible-but-unfocused list draws only the outline, so the
|
||||
* selection stays legible without implying it will receive input.
|
||||
*/
|
||||
export function drawSelectionHighlight(
|
||||
image: GrayImage,
|
||||
x: number,
|
||||
y: number,
|
||||
width: number,
|
||||
height: number,
|
||||
focused: boolean,
|
||||
radius = 6,
|
||||
): void {
|
||||
if (focused) {
|
||||
image.fillRoundedRect(x, y, width, height, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL, radius);
|
||||
}
|
||||
image.drawRoundedRect(x, y, width, height, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE, radius);
|
||||
}
|
||||
|
||||
export function drawToggleMenuItem(
|
||||
image: GrayImage,
|
||||
font: BdfFont,
|
||||
@@ -122,14 +143,22 @@ export class MenuLayer implements Layer {
|
||||
}
|
||||
|
||||
const bodyY = y + chromeTop;
|
||||
const focused = ctx.stack.isFocused();
|
||||
const lastVisibleRow = Math.min(this.items.length, this.scrollRow + visibleRowCount);
|
||||
for (let index = this.scrollRow; index < lastVisibleRow; index++) {
|
||||
const item = this.items[index]!;
|
||||
const rowY = bodyY + (index - this.scrollRow) * MENU_ROW_HEIGHT;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(x + 12, rowY + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL);
|
||||
image.drawRoundedRect(x + 12, rowY + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE);
|
||||
drawSelectionHighlight(
|
||||
image,
|
||||
x + 12,
|
||||
rowY + MENU_HIGHLIGHT_Y_OFFSET,
|
||||
width - 24,
|
||||
MENU_HIGHLIGHT_HEIGHT,
|
||||
focused,
|
||||
8,
|
||||
);
|
||||
}
|
||||
if (item.render) {
|
||||
item.render({
|
||||
@@ -214,7 +243,7 @@ export class TextPageLayer implements Layer {
|
||||
for (let index = 0; index < wrapped.length; index++) {
|
||||
image.drawText(font, 24, 42 + index * 14, wrapped[index]!, 190);
|
||||
}
|
||||
image.drawText(font, 24, 252, "Double-click to go back", 110);
|
||||
image.drawText(font, 24, 252, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { formatRelativeTime } from "~/util/date-util";
|
||||
import { BdfFont, getDefaultSmallFont } from "../graphics/bdffont";
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { wrapText } from "../graphics/textwrap";
|
||||
import { GESTURE_DOUBLE_CLICK } from "./gestures";
|
||||
import {
|
||||
dismissNotification,
|
||||
invokeNotificationAction,
|
||||
@@ -81,7 +82,7 @@ export class NotificationsListLayer implements Layer {
|
||||
|
||||
if (!notifications.length) {
|
||||
image.drawText(font, 24, 72, "No current Android notifications.", 190);
|
||||
image.drawText(font, 24, height - 36, "Double-click: back to sidebar", 110);
|
||||
image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { readActiveNotificationIcons } from "../../native/notification-icons";
|
||||
import { readPhoneBatteryState } from "../../native/phone-battery";
|
||||
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { renderIcon, type IconName } from "../../graphics/icons";
|
||||
import { batteryDisplayModeSetting } from "../dashboard-settings";
|
||||
import { Layer } from "../layers";
|
||||
import { SHELL_OPAQUE_BLACK, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry";
|
||||
@@ -33,7 +34,7 @@ export type ShellChromeState = {
|
||||
trayIcons: GrayImage[];
|
||||
};
|
||||
|
||||
/** Reusable placeholder window icon: rounded outline with a single letter. */
|
||||
/** Placeholder window icon: rounded outline with a single letter. */
|
||||
export function makeLetterWindowIcon(letter: string): ShellChromeWindow["drawIcon"] {
|
||||
return (image, x, y, size) => {
|
||||
const font = getDefaultMediumFont();
|
||||
@@ -44,6 +45,22 @@ export function makeLetterWindowIcon(letter: string): ShellChromeWindow["drawIco
|
||||
};
|
||||
}
|
||||
|
||||
/** Window icon rendered from an SVG (Lucide), rendered once per size and cached. */
|
||||
export function makeSvgWindowIcon(name: IconName): ShellChromeWindow["drawIcon"] {
|
||||
return (image, x, y, size) => {
|
||||
const icon = renderIcon(name, size);
|
||||
if (!icon) return;
|
||||
const dx = x + Math.max(0, ((size - icon.width) / 2) | 0);
|
||||
const dy = y + Math.max(0, ((size - icon.height) / 2) | 0);
|
||||
image.bitBlt(icon, dx, dy, { transparentZero: true });
|
||||
};
|
||||
}
|
||||
|
||||
/** SVG icon when a name is given, else the letter placeholder. */
|
||||
export function windowIcon(icon: IconName | undefined, letter: string): ShellChromeWindow["drawIcon"] {
|
||||
return icon ? makeSvgWindowIcon(icon) : makeLetterWindowIcon(letter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base layer of the shell surface: the window sidebar on the left and the
|
||||
* status top bar. Everything not explicitly painted stays 0 (transparent on
|
||||
|
||||
@@ -43,6 +43,7 @@ export function createDebugTestsAppWindow(options: InProcessAppOptions): InProce
|
||||
windowId: DEBUG_TESTS_WINDOW_ID,
|
||||
title: "Debug tests",
|
||||
iconLetter: "Db",
|
||||
icon: "flask-conical",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(menu),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { beginRenderPass, endRenderPass } from "../../util/render-freshness";
|
||||
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
|
||||
import { makeLetterWindowIcon } from "./chrome-layer";
|
||||
import { windowIcon } from "./chrome-layer";
|
||||
import { type IconName } from "../../graphics/icons";
|
||||
import { APP_VIEWPORT } from "./geometry";
|
||||
import { shell, type ShellWindow } from "./shell";
|
||||
|
||||
@@ -17,6 +18,8 @@ export type InProcessWindowOptions = {
|
||||
windowId: string;
|
||||
title: string;
|
||||
iconLetter: string;
|
||||
/** Lucide icon name for the sidebar indicator; falls back to iconLetter. */
|
||||
icon?: IconName;
|
||||
closeable: boolean;
|
||||
/** Shared actions; requestRender is rebound to this window's render. */
|
||||
actions: LayerActions;
|
||||
@@ -52,6 +55,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
options.baseLayer,
|
||||
{ ...options.actions, requestRender },
|
||||
{ width: APP_VIEWPORT.width, height: APP_VIEWPORT.height },
|
||||
() => shell.isWindowFocused(options.windowId),
|
||||
);
|
||||
|
||||
// Data sources with caches (e.g. notification icons) may serve stale data
|
||||
@@ -83,7 +87,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
options.onClosed?.();
|
||||
options.removeSurface?.();
|
||||
},
|
||||
drawIcon: makeLetterWindowIcon(options.iconLetter),
|
||||
drawIcon: windowIcon(options.icon, options.iconLetter),
|
||||
handleInput: async (event, frameId) => {
|
||||
await stack.handleInput(event);
|
||||
await render(frameId);
|
||||
|
||||
@@ -50,6 +50,7 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
|
||||
windowId: LAUNCHER_WINDOW_ID,
|
||||
title: "Apps",
|
||||
iconLetter: "A",
|
||||
icon: "layout-grid",
|
||||
closeable: false,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(menu),
|
||||
|
||||
@@ -2,6 +2,8 @@ import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } 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 { drawSelectionHighlight } from "../menu";
|
||||
import {
|
||||
mediaControllerBridge,
|
||||
type MediaControllerState,
|
||||
@@ -63,14 +65,14 @@ class MusicAppLayer implements Layer {
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
image.drawText(font, 24, 44 + index * 14, lines[index]!, 180);
|
||||
}
|
||||
image.drawText(font, 20, height - 16, "Click: open settings Double-click: back", 110);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open settings ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
if (!media.available) {
|
||||
image.drawText(font, 24, 44, "No active media session.", 180);
|
||||
image.drawText(font, 24, 62, "Start playback in another app on the phone.", 150);
|
||||
image.drawText(font, 20, height - 16, "Double-click: back to sidebar", 110);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -104,14 +106,13 @@ class MusicAppLayer implements Layer {
|
||||
const y = LIST_TOP + (index - this.scrollRow) * ROW_HEIGHT;
|
||||
const selected = index === this.selectedIndex;
|
||||
if (selected) {
|
||||
image.fillRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 15, 4);
|
||||
image.drawRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 45, 4);
|
||||
drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4);
|
||||
}
|
||||
const value = !row.enabled ? (selected ? 130 : 90) : selected ? 255 : 200;
|
||||
image.drawText(font, LIST_X, y + 1, truncate(font, row.label, width - 2 * LIST_X), value);
|
||||
}
|
||||
|
||||
image.drawText(font, 20, height - 16, "Scroll: select Click: activate Double-click: back", 110);
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_SCROLL} select ${GESTURE_CLICK} activate ${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -198,6 +199,7 @@ export function createMusicAppWindow(options: InProcessAppOptions): InProcessWin
|
||||
windowId: MUSIC_WINDOW_ID,
|
||||
title: "Music",
|
||||
iconLetter: "M",
|
||||
icon: "music",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new MusicAppLayer()),
|
||||
|
||||
@@ -32,6 +32,7 @@ export function createNightscoutAppWindow(options: InProcessAppOptions): InProce
|
||||
windowId: NIGHTSCOUT_WINDOW_ID,
|
||||
title: "Nightscout",
|
||||
iconLetter: "Ns",
|
||||
icon: "activity",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new NightscoutLayer()),
|
||||
|
||||
@@ -20,6 +20,7 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
|
||||
windowId: NOTIFICATIONS_WINDOW_ID,
|
||||
title: "Notifications",
|
||||
iconLetter: "N",
|
||||
icon: "bell",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new NotificationsListLayer()),
|
||||
|
||||
@@ -37,6 +37,7 @@ export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAp
|
||||
windowId: SETTINGS_WINDOW_ID,
|
||||
title: "Settings",
|
||||
iconLetter: "Se",
|
||||
icon: "settings",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(createSettingsMenuLayer()),
|
||||
|
||||
@@ -334,6 +334,11 @@ class Shell {
|
||||
return this.windows[this.selectedIndex] ?? this.windows[0];
|
||||
}
|
||||
|
||||
/** Whether a window is the current input target (foreground + focus in-window). */
|
||||
isWindowFocused(windowId: string): boolean {
|
||||
return this.screenOn && this.focus === "window" && this.foregroundWindow()?.windowId === windowId;
|
||||
}
|
||||
|
||||
private handleSidebarInput(event: DashboardInputEvent): ShellInputOutcome {
|
||||
switch (event.type) {
|
||||
case "double-click":
|
||||
|
||||
@@ -42,6 +42,7 @@ export function createTelepromptBrowserWindow(options: TelepromptBrowserOptions)
|
||||
windowId: TELEPROMPT_WINDOW_ID,
|
||||
title: "Teleprompt",
|
||||
iconLetter: "Tp",
|
||||
icon: "file-text",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: browser,
|
||||
@@ -64,6 +65,7 @@ export function createTelepromptDocumentWindow(
|
||||
windowId,
|
||||
title,
|
||||
iconLetter: "Tp",
|
||||
icon: "file-text",
|
||||
closeable: true,
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new TelepromptLayer(text, title)),
|
||||
|
||||
@@ -55,6 +55,7 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
|
||||
windowId: TRANSCRIBE_WINDOW_ID,
|
||||
title: "Transcribe",
|
||||
iconLetter: "Tr",
|
||||
icon: "mic",
|
||||
closeable: true,
|
||||
actions,
|
||||
baseLayer: new YieldAtRootLayer(layer),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { makeLetterWindowIcon } from "./chrome-layer";
|
||||
import { windowIcon } from "./chrome-layer";
|
||||
import { type IconName } from "../../graphics/icons";
|
||||
import { shell, type ShellWindow } from "./shell";
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,7 @@ export type WorkerAppReply =
|
||||
windowId: string;
|
||||
title: string;
|
||||
iconLetter: string;
|
||||
icon?: IconName;
|
||||
focus?: boolean;
|
||||
}
|
||||
| { type: "set-title"; windowId: string; title: string }
|
||||
@@ -43,6 +45,8 @@ export type WorkerWindowSpec = {
|
||||
windowId: string;
|
||||
title: string;
|
||||
iconLetter: string;
|
||||
/** Lucide icon name for the sidebar indicator; falls back to iconLetter. */
|
||||
icon?: IconName;
|
||||
/** Foreground and focus the window once its surface exists. */
|
||||
focus?: boolean;
|
||||
};
|
||||
@@ -84,6 +88,7 @@ export class WorkerAppHost {
|
||||
windowId: message.windowId,
|
||||
title: message.title,
|
||||
iconLetter: message.iconLetter,
|
||||
icon: message.icon,
|
||||
focus: message.focus,
|
||||
});
|
||||
break;
|
||||
@@ -134,7 +139,7 @@ export class WorkerAppHost {
|
||||
this.post({ type: "close-window", windowId: spec.windowId });
|
||||
this.options.removeSurface(surfaceId);
|
||||
},
|
||||
drawIcon: makeLetterWindowIcon(spec.iconLetter),
|
||||
drawIcon: windowIcon(spec.icon, spec.iconLetter),
|
||||
handleInput: (event, frameId) => {
|
||||
this.post({ type: "input", windowId: spec.windowId, event, frameId });
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import * as frameTimings from "../native/frame-timings";
|
||||
import type { DashboardInputEvent } from "../ui/layers";
|
||||
import type { WorkerAppMessage } from "../ui/shell/worker-window";
|
||||
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../ui/gestures";
|
||||
declare const global: any;
|
||||
declare const com: any;
|
||||
|
||||
@@ -140,8 +141,8 @@ function paint(window: StopwatchWindow): GrayImage {
|
||||
|
||||
const hintsY = window.viewportHeight - 66;
|
||||
image.drawText(smallFont, 90, hintsY, stateLabel, 150);
|
||||
image.drawText(smallFont, 90, hintsY + 18, "Click: start / pause", 150);
|
||||
image.drawText(smallFont, 90, hintsY + 36, "Double-click: back to sidebar", 150);
|
||||
image.drawText(smallFont, 90, hintsY + 18, `${GESTURE_CLICK} start / pause`, 150);
|
||||
image.drawText(smallFont, 90, hintsY + 36, `${GESTURE_DOUBLE_CLICK} back`, 150);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import "@nativescript/core/globals";
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { getFont } from "../graphics/bdffont";
|
||||
import * as frameTimings from "../native/frame-timings";
|
||||
import { GESTURE_DOUBLE_CLICK } from "../ui/gestures";
|
||||
import {
|
||||
G2MirrorClient,
|
||||
type G2MirrorSession,
|
||||
@@ -356,7 +357,7 @@ function openViewWindowFor(session: G2MirrorSession): void {
|
||||
const windowId = `terminal:view:${nextViewSerial++}`;
|
||||
const label = sessionLabel(session);
|
||||
pendingViews.set(windowId, { socket: session.socket, label });
|
||||
post({ type: "open-window-request", windowId, title: label, iconLetter: "T", focus: true });
|
||||
post({ type: "open-window-request", windowId, title: label, iconLetter: "T", icon: "terminal", focus: true });
|
||||
}
|
||||
|
||||
function paint(window: TerminalWindow): GrayImage {
|
||||
@@ -389,7 +390,7 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
image.drawText(terminalFont, 32, y + 2, items[index]!.label, selected ? 255 : 200);
|
||||
}
|
||||
|
||||
image.drawText(terminalFont, 24, viewportHeight - 24, "Double-click: back to sidebar", 110);
|
||||
image.drawText(terminalFont, 24, viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -404,7 +405,7 @@ function paintView(window: ViewWindow): GrayImage {
|
||||
const image = new GrayImage(viewportWidth, viewportHeight, 0);
|
||||
if (!window.receivedData) {
|
||||
image.drawText(terminalFont, 24, 110, window.status, 170);
|
||||
image.drawText(terminalFont, 24, 130, "Double-click: back to sidebar", 110);
|
||||
image.drawText(terminalFont, 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
const cursor = window.emulator.cursor();
|
||||
|
||||
Reference in new issue
Block a user