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
@@ -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 });
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user