Refactor font handling; add image-compression estimation debug option

This commit is contained in:
James Babcock committed 2026-06-01 11:36:46 -07:00
1 parent 5a92637537
commit 964cd11785
15 files changed
+389 -130

No files matched your search

+4 -2
View File
@@ -1,3 +1,4 @@
import { getDefaultSmallFont } from "../../graphics/bdffont";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
@@ -18,6 +19,7 @@ const SWATCH_HEIGHT = 16;
export class ScreenTestLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const font = getDefaultSmallFont();
for (let value = 0; value < COLOR_VALUE_COUNT; value += COLOR_VALUE_STEP) {
const slot = value / COLOR_VALUE_STEP;
@@ -26,10 +28,10 @@ export class ScreenTestLayer implements Layer {
const cellX = GRID_X + col * CELL_WIDTH;
const cellY = row * CELL_HEIGHT;
const label = String(value);
const labelX = cellX + Math.max(0, Math.floor((CELL_WIDTH - ctx.font.measureText(label)) / 2));
const labelX = cellX + Math.max(0, Math.floor((CELL_WIDTH - font.measureText(label)) / 2));
const swatchX = cellX + Math.floor((CELL_WIDTH - SWATCH_WIDTH) / 2);
image.drawText(ctx.font, labelX, cellY + LABEL_Y_OFFSET, label, 185);
image.drawText(font, labelX, cellY + LABEL_Y_OFFSET, label, 185);
fillSwatch(image, swatchX, cellY + SWATCH_Y_OFFSET, SWATCH_WIDTH, SWATCH_HEIGHT, value);
}
+7 -6
View File
@@ -1,8 +1,8 @@
import { loadEmbeddedTerminus32 } from "../../graphics/bdffont";
import { getDefaultSmallFont, getFont } from "../../graphics/bdffont";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
const stopwatchFont = loadEmbeddedTerminus32();
const stopwatchFont = getFont("terminus32");
export class StopwatchLayer implements Layer {
private readonly startedAtMs = Date.now();
@@ -14,17 +14,18 @@ export class StopwatchLayer implements Layer {
const elapsedMs = this.elapsedMs();
const timeLabel = formatStopwatchElapsed(elapsedMs);
const stateLabel = this.pausedAtMs === null ? "Running" : "Paused";
const smallFont = getDefaultSmallFont();
image.drawText(ctx.font, 24, 24, "Stopwatch", 180);
image.drawText(smallFont, 24, 24, "Stopwatch", 180);
const quadrantWidth = G2_LENS_WIDTH / 2;
const quadrantHeight = G2_LENS_HEIGHT / 2;
const timeX = Math.max(0, Math.round((quadrantWidth - stopwatchFont.measureText(timeLabel)) / 2));
const timeY = Math.max(0, Math.round((quadrantHeight - stopwatchFont.lineHeight) / 2));
image.drawText(stopwatchFont, timeX, timeY, timeLabel, 245);
image.drawText(ctx.font, 90, 142, stateLabel, 150);
image.drawText(ctx.font, 90, 160, "Click: pause / resume", 150);
image.drawText(ctx.font, 90, 178, "Double-click: back", 150);
image.drawText(smallFont, 90, 142, stateLabel, 150);
image.drawText(smallFont, 90, 160, "Click: pause / resume", 150);
image.drawText(smallFont, 90, 178, "Double-click: back", 150);
return image;
}
+7 -6
View File
@@ -1,5 +1,5 @@
import { wrapText } from "../../graphics/textwrap";
import { type BdfFont } from "../../graphics/bdffont";
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
@@ -20,29 +20,30 @@ export class TelepromptLayer implements Layer {
constructor(private readonly documentText: string | null) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
image.drawText(ctx.font, MARGIN_X + 4, TITLE_Y, "Teleprompt", 220);
image.drawText(font, MARGIN_X + 4, TITLE_Y, "Teleprompt", 220);
if (this.documentText === null) {
const message = [
"Open a plain text document on your phone and Share it to Faceclaw.",
];
for (let index = 0; index < message.length; index++) {
image.drawText(ctx.font, BODY_X, BODY_Y + index * LINE_STEP, message[index]!, 200);
image.drawText(font, BODY_X, BODY_Y + index * LINE_STEP, message[index]!, 200);
}
return image;
}
const lines = this.getLines(ctx.font);
const lines = this.getLines(font);
const visibleLines = lines.slice(this.firstLine, this.firstLine + BODY_LINE_COUNT);
for (let index = 0; index < visibleLines.length; index++) {
image.drawText(ctx.font, BODY_X, BODY_Y + index * LINE_STEP, visibleLines[index]!, 230);
image.drawText(font, BODY_X, BODY_Y + index * LINE_STEP, visibleLines[index]!, 230);
}
const currentPage = Math.floor(this.firstLine / PAGE_STEP) + 1;
const totalPages = totalPageCount(lines.length);
image.drawText(ctx.font, BODY_X, FOOTER_Y, `Page ${currentPage}/${totalPages}`, 110);
image.drawText(font, BODY_X, FOOTER_Y, `Page ${currentPage}/${totalPages}`, 110);
return image;
}
+9 -8
View File
@@ -1,5 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { type BdfFont } from "../../graphics/bdffont";
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
import { voiceControlBridge, type VoiceTranscriptEvent } from "../../native/voice-control";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
@@ -22,24 +22,25 @@ export class TranscribeLayer implements Layer {
}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const modeLabel = this.mode === "full" ? "Full" : this.mode === "wakeword" ? "Wakeword" : "Off";
const text = this.transcript || "Listening...";
const wrapped = wrapTranscribeText(ctx.font, text, G2_LENS_WIDTH - 64);
const wrapped = wrapTranscribeText(font, text, G2_LENS_WIDTH - 64);
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
image.drawText(ctx.font, 24, 24, "Transcribe", 200);
image.drawText(ctx.font, G2_LENS_WIDTH - 108, 24, modeLabel, this.mode === "full" ? 220 : 130);
//image.drawText(ctx.font, 24, 46, truncateTranscribeLine(this.status, 74), 110);
image.drawText(ctx.font, 24, 46, this.status, 110);
image.drawText(font, 24, 24, "Transcribe", 200);
image.drawText(font, G2_LENS_WIDTH - 108, 24, modeLabel, this.mode === "full" ? 220 : 130);
//image.drawText(font, 24, 46, truncateTranscribeLine(this.status, 74), 110);
image.drawText(font, 24, 46, this.status, 110);
const firstLine = Math.max(0, wrapped.length - 10);
for (let index = firstLine; index < wrapped.length; index++) {
const y = 72 + (index - firstLine) * 16;
image.drawText(ctx.font, 32, y, wrapped[index]!, 230);
image.drawText(font, 32, y, wrapped[index]!, 230);
}
image.drawText(ctx.font, 24, 252, "Click: mode / Double-click: back", 110);
image.drawText(font, 24, 252, "Click: mode / Double-click: back", 110);
return image;
}
+46 -41
View File
@@ -1,6 +1,6 @@
import takeRight from "lodash/takeRight";
import { BdfFont, loadEmbeddedTerminus24 } from "../graphics/bdffont";
import { BdfFont, getDefaultLargeFont, getDefaultSmallFont } from "../graphics/bdffont";
import { GrayImage, imageFromAsciiArt } from "../graphics/image";
import { wrapText } from "../graphics/textwrap";
import { mediaControllerBridge, type MediaControllerState } from "../native/media-controller";
@@ -26,7 +26,6 @@ export type DashboardPluginCardRenderArgs = {
image: GrayImage;
bounds: DashboardPluginCardBounds;
selected: boolean;
font: BdfFont;
state: DashboardPluginState;
};
@@ -47,7 +46,8 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
{
id: "input-debug-log",
label: "Input debug log",
renderCard: ({ image, bounds, font, state }) => {
renderCard: ({ image, bounds, state }) => {
const font = getDefaultSmallFont();
image.drawText(font, bounds.x + 10, bounds.y + 14, "Input log", 180);
const lineHeight = 14;
const visibleLineCount = Math.max(1, Math.floor((bounds.height - 28) / lineHeight));
@@ -61,7 +61,8 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
{
id: "music-controller",
label: "Music controller",
renderCard: ({ image, bounds, font, state }) => {
renderCard: ({ image, bounds, state }) => {
const font = getDefaultSmallFont();
const media = state.media;
image.drawText(font, bounds.x + 10, bounds.y + 14, "Now playing", 180);
if (!media.accessEnabled) {
@@ -88,7 +89,8 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
{
id: "nightscout",
label: "Nightscout",
renderCard: ({ image, bounds, font, state }) => {
renderCard: ({ image, bounds, state }) => {
const font = getDefaultSmallFont();
const nightscout = state.nightscout;
const nowMs = Date.now();
image.drawText(font, bounds.x + 10, bounds.y + 10, "Nightscout", 180);
@@ -146,7 +148,7 @@ const DASHBOARD_PLUGINS: DashboardPlugin[] = [
const PLUGIN_MAP = new Map<DashboardPluginId, DashboardPlugin>(
DASHBOARD_PLUGINS.map((plugin) => [plugin.id, plugin]),
);
const nightscoutLargeFont = loadEmbeddedTerminus24();
const nightscoutLargeFont = getDefaultLargeFont();
const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
@@ -489,9 +491,10 @@ class DebugLogLayer implements Layer {
constructor(private readonly getState: () => DashboardPluginState) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(576, 288, 0);
image.drawRect(12, 12, 552, 264, 52);
image.drawText(ctx.font, 22, 16, "Input debug log", 220);
image.drawText(font, 22, 16, "Input debug log", 220);
const logs = this.getState().logLines;
const lineHeight = 14;
@@ -501,9 +504,9 @@ class DebugLogLayer implements Layer {
const start = Math.max(0, maxOffset - this.scrollOffset);
const visible = logs.slice(start, start + visibleCount);
for (let index = 0; index < visible.length; index++) {
image.drawText(ctx.font, 22, 42 + index * lineHeight, visible[index]!, 180);
image.drawText(font, 22, 42 + index * lineHeight, visible[index]!, 180);
}
image.drawText(ctx.font, 22, 252, "Scroll: browse Double-click: back", 110);
image.drawText(font, 22, 252, "Scroll: browse Double-click: back", 110);
return image;
}
@@ -528,40 +531,41 @@ class MusicControllerLayer implements Layer {
constructor(private readonly getState: () => DashboardPluginState) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(576, 288, 0);
const media = this.getState().media;
image.drawRect(12, 12, 552, 264, 52);
image.drawText(ctx.font, 22, 16, "Music controller", 220);
image.drawText(font, 22, 16, "Music controller", 220);
if (!media.accessEnabled) {
const lines = wrapText(
ctx.font,
font,
"Notification access is required before Android will expose active media sessions to Faceclaw. Click to open settings.",
520,
);
for (let i = 0; i < lines.length; i++) {
image.drawText(ctx.font, 22, 44 + i * 14, lines[i]!, 180);
image.drawText(font, 22, 44 + i * 14, lines[i]!, 180);
}
image.drawText(ctx.font, 22, 252, "Click: open settings Double-click: back", 110);
image.drawText(font, 22, 252, "Click: open settings Double-click: back", 110);
return image;
}
if (!media.available) {
image.drawText(ctx.font, 22, 44, "No active media session.", 180);
image.drawText(ctx.font, 22, 58, "Start playback in another app,", 180);
image.drawText(ctx.font, 22, 72, "then reopen this card.", 180);
image.drawText(ctx.font, 22, 252, "Double-click: back", 110);
image.drawText(font, 22, 44, "No active media session.", 180);
image.drawText(font, 22, 58, "Start playback in another app,", 180);
image.drawText(font, 22, 72, "then reopen this card.", 180);
image.drawText(font, 22, 252, "Double-click: back", 110);
return image;
}
image.drawText(ctx.font, 22, 44, media.title || "Unknown title", 220);
image.drawText(ctx.font, 22, 60, media.artist || media.album || "Unknown artist", 180);
image.drawText(ctx.font, 22, 76, media.packageName, 130);
image.drawText(ctx.font, 22, 104, `State: ${playbackLabel(media)}`, 180);
image.drawText(ctx.font, 22, 132, "Click: play/pause", 180);
image.drawText(ctx.font, 22, 146, "Scroll up: previous", 180);
image.drawText(ctx.font, 22, 160, "Scroll down: next", 180);
image.drawText(ctx.font, 22, 252, "Double-click: back", 110);
image.drawText(font, 22, 44, media.title || "Unknown title", 220);
image.drawText(font, 22, 60, media.artist || media.album || "Unknown artist", 180);
image.drawText(font, 22, 76, media.packageName, 130);
image.drawText(font, 22, 104, `State: ${playbackLabel(media)}`, 180);
image.drawText(font, 22, 132, "Click: play/pause", 180);
image.drawText(font, 22, 146, "Scroll up: previous", 180);
image.drawText(font, 22, 160, "Scroll down: next", 180);
image.drawText(font, 22, 252, "Double-click: back", 110);
return image;
}
@@ -598,23 +602,24 @@ class NightscoutLayer implements Layer {
constructor(private readonly getState: () => DashboardPluginState) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(576, 288, 0);
const nightscout = this.getState().nightscout;
const nowMs = Date.now();
image.drawRect(12, 12, 552, 264, 52);
image.drawText(ctx.font, 22, 16, "Nightscout", 220);
image.drawText(font, 22, 16, "Nightscout", 220);
if (!this.getState().nightscoutConfigured || nightscout.configurationMissing) {
image.drawText(ctx.font, 22, 44, "Nightscout needs configuration.", 180);
image.drawText(ctx.font, 22, 62, "Double-click and use Settings", 140);
image.drawText(ctx.font, 22, 78, "Integrations > Nightscout.", 140);
image.drawText(font, 22, 44, "Nightscout needs configuration.", 180);
image.drawText(font, 22, 62, "Double-click and use Settings", 140);
image.drawText(font, 22, 78, "Integrations > Nightscout.", 140);
return image;
}
if (!nightscout.available || !nightscout.latest) {
image.drawText(ctx.font, 22, 44, "No Nightscout data available.", 180);
image.drawText(ctx.font, 22, 58, truncateLine(nightscout.status, 60), 140);
image.drawText(ctx.font, 22, 252, "Click: refresh Double-click: back", 110);
image.drawText(font, 22, 44, "No Nightscout data available.", 180);
image.drawText(font, 22, 58, truncateLine(nightscout.status, 60), 140);
image.drawText(font, 22, 252, "Click: refresh Double-click: back", 110);
return image;
}
@@ -626,28 +631,28 @@ class NightscoutLayer implements Layer {
if (isNightscoutPointStale(latest, nowMs)) {
drawNightscoutValueStrikeThrough(image, glucoseX, 40, glucoseWidth);
}
image.drawText(ctx.font, glucoseX + glucoseWidth + 8, 36, nightscout.units, 140);
image.drawText(font, glucoseX + glucoseWidth + 8, 36, nightscout.units, 140);
const trendText = `Delta ${formatDelta(nightscout.delta)} Trend `;
image.drawText(ctx.font, 22, 62, trendText, 180);
drawDirectionIndicator(image, ctx.font, 22 + ctx.font.measureText(trendText), 62, nightscout.direction, 180);
image.drawText(font, 22, 62, trendText, 180);
drawDirectionIndicator(image, font, 22 + font.measureText(trendText), 62, nightscout.direction, 180);
image.drawText(
ctx.font,
font,
22,
78,
`IOB ${nightscout.iob === null ? "--" : nightscout.iob.toFixed(2)} COB ${nightscout.cob === null ? "--" : formatWholeNumber(nightscout.cob)} Updated ${formatTimestamp(latest.timestampMs)}`,
160,
);
image.drawText(
ctx.font,
font,
22,
94,
`CAGE ${formatAgeShortFromTimestamp(nightscout.cageTimestampMs, nowMs)} Loop ${nightscout.openapsStatusShort}`,
160,
);
image.drawText(ctx.font, 22, 110, `Pump ${truncateLine(nightscout.pumpStatus || "--", 56)}`, 150);
drawNightscoutGraph(image, { x: 22, y: 128, width: 532, height: 96 }, nightscout, nowMs, ctx.font);
image.drawText(ctx.font, 22, 234, "2-hour glucose history with basal / carbs / boluses", 130);
image.drawText(ctx.font, 22, 252, "Click: refresh Double-click: back", 110);
image.drawText(font, 22, 110, `Pump ${truncateLine(nightscout.pumpStatus || "--", 56)}`, 150);
drawNightscoutGraph(image, { x: 22, y: 128, width: 532, height: 96 }, nightscout, nowMs, font);
image.drawText(font, 22, 234, "2-hour glucose history with basal / carbs / boluses", 130);
image.drawText(font, 22, 252, "Click: refresh Double-click: back", 110);
return image;
}
+14
View File
@@ -22,10 +22,12 @@ export const DEFAULT_SYSTEM_CARD_NAME = "Faceclaw";
export const DEFAULT_SCREEN_TIMEOUT: ScreenTimeoutSetting = "30s";
export const DEFAULT_WAKE_MODE: WakeModeSetting = "tiled";
export const DEFAULT_VOICE_CONTROL_ENABLED = false;
export const DEFAULT_ESTIMATE_COMPRESSION_RATIOS_ENABLED = false;
const SYSTEM_CARD_NAME_KEY = "dashboard.systemCardName";
const SCREEN_TIMEOUT_KEY = "display.screenTimeout";
const WAKE_MODE_KEY = "display.wakeMode";
const VOICE_CONTROL_ENABLED_KEY = "voice.enabled";
const ESTIMATE_COMPRESSION_RATIOS_ENABLED_KEY = "debug.estimateCompressionRatios";
const SYSTEM_CARD_SETTING_KEYS: Record<SystemCardSettingKey, string> = {
showFaceclawLogo: "dashboard.systemCard.showFaceclawLogo",
showBatteryIndicators: "dashboard.systemCard.showBatteryIndicators",
@@ -149,6 +151,18 @@ export function saveVoiceControlEnabled(value: boolean): boolean {
return value;
}
export function loadEstimateCompressionRatiosEnabled(): boolean {
return ApplicationSettings.getBoolean(
ESTIMATE_COMPRESSION_RATIOS_ENABLED_KEY,
DEFAULT_ESTIMATE_COMPRESSION_RATIOS_ENABLED,
);
}
export function saveEstimateCompressionRatiosEnabled(value: boolean): boolean {
ApplicationSettings.setBoolean(ESTIMATE_COMPRESSION_RATIOS_ENABLED_KEY, value);
return value;
}
export function nextScreenTimeoutSetting(value: ScreenTimeoutSetting): ScreenTimeoutSetting {
switch (value) {
case "15s":
+33 -5
View File
@@ -1,5 +1,5 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import { loadEmbeddedTerminus12, loadEmbeddedTerminus16, loadEmbeddedTerminus32 } from "../graphics/bdffont";
import { getDefaultMediumFont, getDefaultSmallFont } from "../graphics/bdffont";
import { BATTERY_ICON_WIDTH, drawBattery } from "../graphics/battery";
import { loadPngAsGrayImage } from "../graphics/imagefile";
import { type RawInputEvent } from "../native/faceclaw-communicator";
@@ -22,6 +22,7 @@ import {
getDashboardSlotIds,
isNightscoutSettingsConfigured,
loadDashboardSlotConfig,
loadEstimateCompressionRatiosEnabled,
loadNightscoutSettings,
loadScreenTimeoutSetting,
loadSystemCardSettings,
@@ -31,6 +32,7 @@ import {
nextScreenTimeoutSetting,
nextWakeModeSetting,
saveDashboardSlotPlugin,
saveEstimateCompressionRatiosEnabled,
saveNightscoutApiToken,
saveNightscoutSiteUrl,
saveScreenTimeoutSetting,
@@ -72,6 +74,7 @@ let dashboardState = {
screenTimeout: loadScreenTimeoutSetting(),
wakeMode: loadWakeModeSetting(),
voiceControlEnabled: loadVoiceControlEnabled(),
estimateCompressionRatiosEnabled: loadEstimateCompressionRatiosEnabled(),
tiledWakePaintPending: false,
telepromptDocumentText: null as string | null,
nightscoutSettings: loadNightscoutSettings(),
@@ -96,8 +99,8 @@ const dashboardActions: LayerActions = {
startDedicatedVoiceInput: () => {},
stopDedicatedVoiceInput: () => {},
};
const dashboardFont = loadEmbeddedTerminus12();
const dashboardSystemFont = loadEmbeddedTerminus16();
const dashboardFont = getDefaultSmallFont();
const dashboardSystemFont = getDefaultMediumFont();
const NOTIFICATION_ICON_SIZE = 24;
const SYSTEM_CARD_ITEM_HEIGHT = 38;
const SYSTEM_CARD_ITEM_GAP = 2;
@@ -245,6 +248,10 @@ export function setDashboardVoiceControlEnabled(value: boolean): void {
dashboardState.voiceControlEnabled = saveVoiceControlEnabled(value);
}
export function isDashboardCompressionRatioEstimationEnabled(): boolean {
return dashboardState.estimateCompressionRatiosEnabled;
}
export function applyDashboardScreenTimeout(nowMs = Date.now()): boolean {
const timeoutMs = screenTimeoutMs(dashboardState.screenTimeout);
if (timeoutMs === null || !dashboardState.screenOn) return false;
@@ -439,7 +446,6 @@ class DashboardLayer implements Layer {
image,
bounds,
selected: false,
font: dashboardFont,
state: pluginState,
});
}
@@ -648,6 +654,24 @@ function createDisplaySettingsMenuLayer(): MenuLayer {
drawRightValueMenuItem(image, dashboardFont, x, y, width, "Wake mode", wakeModeLabel(dashboardState.wakeMode));
},
},
{
label: "Estimate compression ratios",
onSelect: () => {
setEstimateCompressionRatiosEnabled(!dashboardState.estimateCompressionRatiosEnabled);
},
render: ({ image, x, y, width, selected }) => {
drawToggleMenuItem(
image,
dashboardFont,
x,
y,
width,
"Estimate compression ratios",
dashboardState.estimateCompressionRatiosEnabled,
selected,
);
},
},
],
TOP_LEFT_MENU_LAYOUT,
);
@@ -662,6 +686,10 @@ function setWakeMode(value: WakeModeSetting): void {
dashboardState.wakeMode = saveWakeModeSetting(value);
}
function setEstimateCompressionRatiosEnabled(value: boolean): void {
dashboardState.estimateCompressionRatiosEnabled = saveEstimateCompressionRatiosEnabled(value);
}
function createVoiceSettingsMenuLayer(): MenuLayer {
return new MenuLayer(
"Settings > Voice",
@@ -935,6 +963,6 @@ function maskToken(token: string): string {
return token.length <= 6 ? "******" : `${token.slice(0, 2)}...${token.slice(-4)}`;
}
const dashboardLayers = new LayerStack(new DashboardLayer(), dashboardFont, dashboardActions);
const dashboardLayers = new LayerStack(new DashboardLayer(), dashboardActions);
dashboardLayers.push(createRootMenuLayer());
+1 -3
View File
@@ -26,7 +26,6 @@ export type PaintBelow = () => GrayImage;
export interface LayerContext {
readonly stack: LayerStack;
readonly font: BdfFont;
readonly actions: LayerActions;
}
@@ -40,11 +39,10 @@ export class LayerStack {
private readonly layers: Layer[];
private readonly ctx: LayerContext;
constructor(baseLayer: Layer, font: BdfFont, actions: LayerActions) {
constructor(baseLayer: Layer, actions: LayerActions) {
this.layers = [baseLayer];
this.ctx = {
stack: this,
font,
actions,
};
}
+9 -7
View File
@@ -1,6 +1,6 @@
import { GrayImage } from "../graphics/image";
import { wrapText } from "../graphics/textwrap";
import { type BdfFont } from "../graphics/bdffont";
import { getDefaultSmallFont, type BdfFont } from "../graphics/bdffont";
import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers";
const DEFAULT_MENU_X = 8;
@@ -92,12 +92,13 @@ export class MenuLayer implements Layer {
) {}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const font = getDefaultSmallFont();
const { x, y, width, height } = this.layout;
const image = paintBelow();
image.fillRoundedRect(x, y, width, height, 0);
image.drawRoundedRect(x, y, width, height, 72);
if (this.title) {
image.drawText(ctx.font, x + 12, y + 8, this.title, 220);
image.drawText(font, x + 12, y + 8, this.title, 220);
}
const bodyY = y + (this.title ? MENU_TITLE_HEIGHT : 0) + 8;
@@ -121,7 +122,7 @@ export class MenuLayer implements Layer {
ctx,
});
} else {
image.drawText(ctx.font, x + 22, y + 3, item.label, selected ? 255 : 200);
image.drawText(font, x + 22, y + 3, item.label, selected ? 255 : 200);
}
}
@@ -161,15 +162,16 @@ export class TextPageLayer implements Layer {
) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(576, 288, 0);
image.drawText(ctx.font, 18, 14, this.title, 220);
image.drawText(font, 18, 14, this.title, 220);
image.drawRect(12, 12, 552, 264, 52);
const wrapped = wrapText(ctx.font, this.body, 520);
const wrapped = wrapText(font, this.body, 520);
for (let index = 0; index < wrapped.length; index++) {
image.drawText(ctx.font, 24, 42 + index * 14, wrapped[index]!, 190);
image.drawText(font, 24, 42 + index * 14, wrapped[index]!, 190);
}
image.drawText(ctx.font, 24, 252, "Double-click to go back", 110);
image.drawText(font, 24, 252, "Double-click to go back", 110);
return image;
}
+16 -17
View File
@@ -1,4 +1,4 @@
import { BdfFont } from "../graphics/bdffont";
import { BdfFont, getDefaultSmallFont } from "../graphics/bdffont";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
import { wrapText } from "../graphics/textwrap";
import {
@@ -40,20 +40,21 @@ export class NotificationsListLayer implements Layer {
constructor(private readonly exitToRootMenu?: (ctx: LayerContext) => void) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const notifications = readActiveNotifications(MAX_NOTIFICATIONS);
const selectedIndex = this.resolveSelectedIndex(notifications);
const layouts = notifications.map((notification, index) =>
buildNotificationCardLayout(ctx.font, notification, index === selectedIndex),
buildNotificationCardLayout(font, notification, index === selectedIndex),
);
image.drawRect(PAGE_X, PAGE_Y, PAGE_WIDTH, PAGE_HEIGHT, 52);
image.drawText(ctx.font, PAGE_X + 12, PAGE_Y + 9, "Notifications", 220);
image.drawText(ctx.font, G2_LENS_WIDTH - 96, PAGE_Y + 9, `${notifications.length} active`, 150);
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notifications", 220);
image.drawText(font, G2_LENS_WIDTH - 96, PAGE_Y + 9, `${notifications.length} active`, 150);
if (!notifications.length) {
image.drawText(ctx.font, 24, 72, "No current Android notifications.", 190);
image.drawText(ctx.font, 24, 252, "Double-click to return to dashboard", 110);
image.drawText(font, 24, 72, "No current Android notifications.", 190);
image.drawText(font, 24, 252, "Double-click to return to dashboard", 110);
return image;
}
@@ -62,14 +63,14 @@ export class NotificationsListLayer implements Layer {
for (let index = 0; index < layouts.length; index++) {
const layout = layouts[index]!;
if (cursorY + layout.height >= LIST_TOP && cursorY <= LIST_BOTTOM) {
drawNotificationCard(image, ctx.font, layout, CARD_X, cursorY, CARD_WIDTH, index === selectedIndex);
drawNotificationCard(image, font, layout, CARD_X, cursorY, CARD_WIDTH, index === selectedIndex);
}
cursorY += layout.height + CARD_GAP;
if (cursorY > LIST_BOTTOM + 80) break;
}
const footer = `${selectedIndex + 1}/${notifications.length} tap: open double: dashboard`;
image.drawText(ctx.font, PAGE_X + 12, 258, footer, 110);
image.drawText(font, PAGE_X + 12, 258, footer, 110);
return image;
}
@@ -119,21 +120,21 @@ export class SingleNotificationLayer implements Layer {
constructor(private readonly notificationKey: string) {}
paint(ctx: LayerContext, _paintBelow: PaintBelow): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const notification = readActiveNotifications(MAX_NOTIFICATIONS).find((item) => item.key === this.notificationKey);
image.drawRect(PAGE_X, PAGE_Y, PAGE_WIDTH, PAGE_HEIGHT, 52);
if (!notification) {
image.drawText(ctx.font, PAGE_X + 12, PAGE_Y + 9, "Notification", 220);
image.drawText(ctx.font, 24, 72, "This notification is no longer active.", 190);
image.drawText(ctx.font, 24, 252, "Double-click to go back", 110);
image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notification", 220);
image.drawText(font, 24, 72, "This notification is no longer active.", 190);
image.drawText(font, 24, 252, "Double-click to go back", 110);
return image;
}
const menu = buildDetailMenu(notification);
this.selectedMenuIndex = clamp(this.selectedMenuIndex, 0, Math.max(0, menu.length - 1));
drawDetailContent(image, ctx.font, notification);
drawDetailMenu(image, ctx.font, menu, this.selectedMenuIndex);
drawDetailContent(image, font, notification);
drawDetailMenu(image, font, menu, this.selectedMenuIndex);
return image;
}
@@ -263,9 +264,8 @@ function drawDetailContent(image: GrayImage, font: BdfFont, notification: Androi
function drawDetailMenu(image: GrayImage, font: BdfFont, menu: DetailMenuItem[], selectedIndex: number): void {
const menuX = 404;
const menuY = 40;
const menuY = 24;
const menuWidth = 148;
image.drawText(font, menuX, 24, "Menu", 170);
for (let index = 0; index < menu.length; index++) {
const y = menuY + index * 22;
const selected = index === selectedIndex;
@@ -276,7 +276,6 @@ function drawDetailMenu(image: GrayImage, font: BdfFont, menu: DetailMenuItem[],
const label = truncateToWidth(font, menu[index]!.label, menuWidth - 12);
image.drawText(font, menuX, y + 2, label, selected ? 255 : 185);
}
image.drawText(font, 404, 258, "tap: select", 110);
}
function buildDetailMenu(notification: AndroidNotification): DetailMenuItem[] {