Change Nightscout icon, app-switcher sidebar highlight style

This commit is contained in:
James Babcock committed 2026-07-08 13:51:59 -07:00
1 parent 3a10c9b13e
commit 2c04d99dfb
9 files changed
+311 -68

No files matched your search

@@ -31,15 +31,20 @@ public final class IconRenderer {
return new byte[0];
}
try {
float viewW = 24f, viewH = 24f;
float minX = 0f, minY = 0f, viewW = 24f, viewH = 24f;
Matcher vb = VIEWBOX_RE.matcher(svg);
if (vb.find()) {
String[] parts = vb.group(1).trim().split("[\\s,]+");
if (parts.length == 4) {
minX = Float.parseFloat(parts[0]);
minY = Float.parseFloat(parts[1]);
viewW = Float.parseFloat(parts[2]);
viewH = Float.parseFloat(parts[3]);
}
}
// Lucide-style icons are stroked outlines (fill="none"); everything
// else (Noun Project glyphs, brand logos) is a filled shape.
boolean stroked = svg.contains("fill=\"none\"");
Path path = new Path();
Matcher m = TAG_RE.matcher(svg);
while (m.find()) {
@@ -52,15 +57,20 @@ public final class IconRenderer {
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
float scale = Math.min(size / viewW, size / viewH);
// Center the (square) viewBox in the bitmap.
// Center the (square) viewBox in the bitmap, then map its origin.
canvas.translate((size - viewW * scale) / 2f, (size - viewH * scale) / 2f);
canvas.scale(scale, scale);
canvas.translate(-minX, -minY);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(strokeWidth);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setColor(0xffffffff);
if (stroked) {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(strokeWidth);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeJoin(Paint.Join.ROUND);
} else {
paint.setStyle(Paint.Style.FILL);
}
canvas.drawPath(path, paint);
int[] pixels = new int[size * size];
+6 -5
View File
@@ -9,12 +9,13 @@ If build.sh exists, it's a machine-specific wrapper that sets some environment
variables to point to where tools are installed, then runs
`nativescript build android`.
If build_and_run.sh exists, it does everything build.sh does plus
`native run android --device <id> --justlaunch`,
`nativescript run android --device <id> --justlaunch`,
which will launch the app on the developer's phone if it is plugged in and has
adb enabled. If no phone is connected, it will fail and the output will contain
the string "Cannot find connected devices." To lint and typecheck, prefer to
use build.sh; if the user asks you to run or test the app, use build_and_run.sh
and then use `adb logcat` to view the results.
adb enabled. If no phone is connected, it will still build but the install step
will fail and the output will contain the string "Cannot find connected
devices." To lint and typecheck, prefer to use build.sh; if the user asks you
to run or test the app, use build_and_run.sh and then use `adb logcat` to view
the results.
If you are working on low-level communication bits, consider checking out
https://github.com/Commute773/g2-kit-unofficial/ and referring to ble/docs/
+9 -9
View File
@@ -205,15 +205,15 @@ class DashboardController {
requestRender: () => shell.foregroundWindow()?.requestRender(),
},
apps: [
{ appId: "stopwatch", label: "Stopwatch" },
{ appId: "terminal", label: "Terminal" },
{ appId: "teleprompt", label: "Teleprompt" },
{ appId: "music", label: "Music" },
{ appId: "nightscout", label: "Nightscout" },
{ appId: "transcribe", label: "Transcribe" },
{ appId: "notifications", label: "Notifications" },
{ appId: "debug-tests", label: "Debug tests" },
{ appId: "settings", label: "Settings" },
{ appId: "stopwatch", label: "Stopwatch", icon: "timer" },
{ appId: "terminal", label: "Terminal", icon: "terminal" },
{ appId: "teleprompt", label: "Teleprompt", icon: "file-text" },
{ appId: "music", label: "Music", icon: "music" },
{ appId: "nightscout", label: "Nightscout", icon: "nightscout" },
{ appId: "transcribe", label: "Transcribe", icon: "mic" },
{ appId: "notifications", label: "Notifications", icon: "bell" },
{ appId: "debug-tests", label: "Debug tests", icon: "flask-conical" },
{ appId: "settings", label: "Settings", icon: "settings" },
],
launchApp: (appId) => this.launchApp(appId),
submitFrame: (image, paintMs, frameId) =>
+12 -10
View File
@@ -19,25 +19,27 @@ const ICON_STROKE_WIDTH = 2;
// 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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
'<svg viewBox="0 0 24 24" fill="none"><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>',
nightscout:
'<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="70.29 0 371.43 512"><g fill="#fff"><path d="M245.67.33c-26.83 1.88-48.51 7.53-71.01 18.48-12.93 6.31-23.82 13.24-35.58 22.6-6.52 5.14-22.75 21.43-28 27.95C89.04 97 76.06 127.65 71.22 163.38c-1.12 8.6-1.27 37.06-.25 47.85 3.46 35.53 12.16 69.02 27.33 105.37 18.83 45.25 49.17 93.31 88.52 140.44 12.17 14.56 33.39 37.72 39.76 43.47 15.17 13.54 36.19 15.27 52.94 4.33 4.38-2.85 10.44-8.76 23.62-23.06 31.2-33.75 58.18-69.33 78.8-103.84 25.1-42 40.72-78.7 50.8-119.37 8.91-35.89 11.35-74.52 6.57-103.08-3.16-18.94-7.99-33.7-17-51.92C401.59 61.68 366.77 29.76 323 12.5 300.04 3.49 269.34-1.35 245.67.33m21.99 29.42c12.83.66 31.61 4.94 45.2 10.28 35.99 14.15 65.87 41.64 82.97 76.25 8.76 17.71 13.34 33.24 15.58 52.69.66 5.9.76 10.38.56 22.14-.25 14.81-.51 18.17-2.44 31.82-8.35 58.95-36.6 121.71-83.08 184.27-21.38 28.71-57.93 70.3-65 73.86-3 1.53-7.99 1.58-10.94.2-7.13-3.41-42.56-43.62-64.65-73.3-33.09-44.39-55.79-86.33-70.3-129.81-11.5-34.61-16.59-65.16-15.83-95.9.41-17.36 2.44-29.52 7.53-45.15 18.43-56.71 68.87-98.65 127.77-106.39 7.18-.92 19.6-1.68 24.13-1.43 1.68.12 5.5.32 8.5.47"/><path d="M247.05 58.51c-11.56.97-23.31 3.41-33.49 6.87-6.36 2.19-18.94 8.2-24.89 11.96-13.49 8.4-26.27 20.26-36.35 33.7l-1.43 1.93 3.31-1.27c8.65-3.26 18.73-4.84 30.7-4.84 13.03 0 22.5 1.73 33.7 6.21 6.67 2.65 12.78 6.11 18.78 10.64 5.09 3.87 13.64 12.52 16.44 16.65.97 1.43 1.88 2.6 2.04 2.6s1.17-1.27 2.29-2.85c5.14-7.18 14.86-16.14 22.91-21.02 21.18-12.98 50.34-16.09 74.68-7.94l4.94 1.68-1.58-2.29c-7.33-10.69-22.25-24.48-35.28-32.78-14.86-9.42-32.93-15.93-51.26-18.48-7.04-.97-18.74-1.33-25.51-.77"/><path d="M178.07 133.9c-20.46 2.39-36.04 13.44-44.64 31.66-3.41 7.13-4.89 13.44-5.19 21.99-.71 18.68 4.99 41.39 14.91 59.41 20.46 37.16 57.27 62 98.55 66.53 11.5 1.27 28.56.46 40.37-1.99 22.7-4.63 44.29-15.88 61.39-31.97 6.82-6.41 16.29-17.97 21.18-25.81 15.17-24.38 22.55-57.88 17.26-78.29-1.43-5.65-4.73-12.98-7.99-17.71-3.41-5.04-9.88-11.45-14.91-14.76-5.14-3.41-12.78-6.57-19.14-7.89-5.29-1.17-19.9-1.32-24.69-.31-19.7 4.28-34.61 16.75-41.03 34.31-3.82 10.33-3.67 8.55-3.87 51.57-.15 42.2-.1 41.08-3 42.45-.81.36-5.09.56-11.66.56h-10.44l-1.63-1.48-1.68-1.48-.31-39.4c-.31-42.76-.2-41.44-3.31-50.7-3.56-10.69-11.61-21.23-21.02-27.59-10.9-7.32-25.41-10.68-39.15-9.1m12.22 6.06c10.74 1.22 20.31 5.85 28.61 13.74 6.67 6.36 11 13.54 13.64 22.65 1.02 3.61 1.17 5.14 1.12 12.98 0 8.2-.1 9.26-1.37 13.39-4.17 13.49-12.73 23.82-25.04 30.24-11.05 5.7-23.62 7.02-35.79 3.72-13.69-3.77-25.76-14.15-31.87-27.59-6.11-13.29-5.5-30.29 1.53-43.12 7.94-14.61 21.94-24.08 38.33-26.01 4.88-.56 5.95-.56 10.84 0m141.66 0c23.57 2.7 41.39 20.41 44.13 43.88 2.44 20.72-9.52 41.54-28.86 50.34-13.08 5.9-29.17 5.65-41.74-.66-13.18-6.62-22.55-18.17-26.52-32.73-1.48-5.5-1.37-18.33.2-24.18 1.48-5.4 4.48-11.86 7.43-15.93 2.49-3.56 9.06-10.03 12.62-12.47 6.01-4.12 14.91-7.43 22.04-8.2 5.82-.61 5.66-.61 10.7-.05"/><path d="M180.62 168.47c-11.2 2.39-18.58 13.39-16.39 24.54 3.26 16.59 23.42 22.81 35.33 10.89 10.28-10.33 7.28-27.44-5.96-33.7-4.08-1.89-9.01-2.55-12.98-1.73m141.92.2c-8.4 1.83-14.91 8.81-16.29 17.41-1.02 6.26 1.37 13.29 6.11 17.92 13.69 13.49 36.8 2.9 35.48-16.29a21.05 21.05 0 0 0-17.1-19.24c-3.37-.61-4.64-.61-8.2.2M163.15 318.02c8.4 16.8 18.12 33.55 28.71 49.48 7.18 10.84 9.01 13.29 9.52 12.98 1.37-.87 26.32-39.81 25.81-40.27-.05-.05-3.05-.81-6.72-1.63-19.9-4.58-39.35-13.44-55.89-25.45-2.19-1.63-4.43-3.21-4.99-3.61-.71-.51.41 2.14 3.56 8.5m183.57-4.68c-13.39 9.82-30.9 18.48-46.98 23.11-10.33 2.95-23.47 5.19-35.63 6.01l-5.75.36-3.82 6.82c-8.5 15.22-21.69 35.99-31.05 48.97-2.34 3.26-4.28 6.06-4.28 6.21 0 1.27 23.21 28.4 33.49 39.2l3.26 3.41 3.46-3.67c37.01-39.71 67.55-82.62 88.42-124.31 4.17-8.3 4.89-9.98 4.33-9.93-.21 0-2.65 1.73-5.45 3.82"/></g></svg>',
} as const;
export type IconName = keyof typeof ICON_SVGS;
+88 -12
View File
@@ -22,7 +22,8 @@ export type ShellChromeWindow = {
windowId: string;
title: string;
attention: boolean;
drawIcon: (image: GrayImage, x: number, y: number, size: number) => void;
/** Draw the window's indicator icon. inverted = black-on-white (focused tab). */
drawIcon: (image: GrayImage, x: number, y: number, size: number, inverted?: boolean) => void;
};
export type ShellChromeState = {
@@ -36,23 +37,39 @@ export type ShellChromeState = {
/** Placeholder window icon: rounded outline with a single letter. */
export function makeLetterWindowIcon(letter: string): ShellChromeWindow["drawIcon"] {
return (image, x, y, size) => {
return (image, x, y, size, inverted) => {
const font = getDefaultMediumFont();
image.drawRoundedRect(x, y, size, size, 120, 6);
if (!inverted) {
image.drawRoundedRect(x, y, size, size, 120, 6);
}
const textX = x + Math.max(0, ((size - font.measureText(letter)) / 2) | 0);
const textY = y + Math.max(0, ((size - font.lineHeight) / 2) | 0);
image.drawText(font, textX, textY, letter, 210);
image.drawText(font, textX, textY, letter, inverted ? SHELL_OPAQUE_BLACK : 210);
};
}
/** 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) => {
return (image, x, y, size, inverted) => {
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 });
if (!inverted) {
image.bitBlt(icon, dx, dy, { transparentZero: true });
return;
}
// Invert onto a white background: coverage becomes darkness. Full coverage
// maps to SHELL_OPAQUE_BLACK (1) rather than 0, since 0 is the surface's
// transparent color key.
for (let row = 0; row < icon.height; row++) {
for (let col = 0; col < icon.width; col++) {
const coverage = icon.pixels[row * icon.width + col] ?? 0;
if (coverage > 0) {
image.setPixel(dx + col, dy + row, Math.max(SHELL_OPAQUE_BLACK, 255 - coverage));
}
}
}
};
}
@@ -87,7 +104,6 @@ export class ShellChromeLayer implements Layer {
private drawSidebar(image: GrayImage, state: ShellChromeState): void {
image.fillRect(0, 0, SIDEBAR_WIDTH, G2_LENS_HEIGHT, SHELL_OPAQUE_BLACK);
image.drawLine(SIDEBAR_WIDTH - 1, 0, SIDEBAR_WIDTH - 1, G2_LENS_HEIGHT - 1, BORDER_VALUE);
// Scroll the icon list to keep the selection visible; chevrons mark
// windows off-screen above/below.
@@ -104,16 +120,34 @@ export class ShellChromeLayer implements Layer {
this.scrollRow = clamp(this.scrollRow, 0, Math.max(0, count - visibleCount));
const lastVisible = Math.min(count, this.scrollRow + visibleCount);
// The selection is a "diversion" of the sidebar/main separator line: the
// line bulges right around the selected icon (rounded on the left, open
// to the main area on the right), so the separator is drawn with a gap
// there. When the sidebar has focus, the diversion is filled white and
// the icon drawn inverted.
const sep = SIDEBAR_WIDTH - 1;
const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible;
const selTabTop = selVisible ? listTop + (state.selectedIndex - this.scrollRow) * itemStride - 2 : 0;
const selTabBottom = selTabTop + ICON_SIZE + 4;
if (selVisible) {
image.drawLine(sep, 0, sep, selTabTop, BORDER_VALUE);
image.drawLine(sep, selTabBottom, sep, G2_LENS_HEIGHT - 1, BORDER_VALUE);
} else {
image.drawLine(sep, 0, sep, G2_LENS_HEIGHT - 1, BORDER_VALUE);
}
for (let index = this.scrollRow; index < lastVisible; index++) {
const window = state.windows[index]!;
const y = listTop + (index - this.scrollRow) * itemStride;
if (index === state.selectedIndex) {
const highlight = state.focus === "sidebar" ? 200 : 70;
image.drawRoundedRect(0, y - 2, SIDEBAR_WIDTH - 3, ICON_SIZE + 4, highlight, 6);
const selected = index === state.selectedIndex;
const focused = selected && state.focus === "sidebar";
if (selected) {
drawSelectionTab(image, y - 2, y + ICON_SIZE + 2, focused);
}
window.drawIcon(image, ICON_MARGIN_X, y, ICON_SIZE);
window.drawIcon(image, ICON_MARGIN_X, y, ICON_SIZE, focused);
if (window.attention) {
image.fillRoundedRect(ICON_MARGIN_X + ICON_SIZE - 7, y - 1, 8, 8, 255, 4);
// Black dot on the white focused tab, white dot otherwise.
image.fillRoundedRect(ICON_MARGIN_X + ICON_SIZE - 7, y - 1, 8, 8, focused ? SHELL_OPAQUE_BLACK : 255, 4);
}
}
@@ -223,6 +257,48 @@ function drawTrayIcons(image: GrayImage, trayIcons: GrayImage[], rightEdge: numb
return x;
}
const TAB_RADIUS = 6;
// How far the diversion pokes past the separator into the main area.
const TAB_EXTEND = 1;
const TAB_STROKE = 150;
/**
* Draw the selection "diversion" of the separator line around a sidebar icon:
* rounded on the left, square and open on the right, extending a few px past
* the separator into the main area. Focused = filled white; otherwise an
* outline.
*/
function drawSelectionTab(image: GrayImage, top: number, bottom: number, focused: boolean): void {
const right = SIDEBAR_WIDTH - 1 + TAB_EXTEND;
if (focused) {
for (let yy = top; yy < bottom; yy++) {
const inset = tabLeftInset(yy, top, bottom, TAB_RADIUS);
image.fillRect(inset, yy, right - inset + 1, 1, 255);
}
return;
}
// Outline: curved left edge (per-row) plus straight top and bottom edges.
for (let yy = top; yy < bottom; yy++) {
image.setPixel(tabLeftInset(yy, top, bottom, TAB_RADIUS), yy, TAB_STROKE);
}
image.drawLine(tabLeftInset(top, top, bottom-1, TAB_RADIUS), top, right, top, TAB_STROKE);
image.drawLine(tabLeftInset(bottom-1, top, bottom-1, TAB_RADIUS), bottom-1, right, bottom-1, TAB_STROKE);
}
/** Left boundary x of the tab at row yy: 0 in the middle, curving to the rounded left corners. */
function tabLeftInset(yy: number, top: number, bottom: number, radius: number): number {
const cy = yy + 0.5;
let dy = 0;
if (cy < top + radius) {
dy = top + radius - cy;
} else if (cy > bottom - radius) {
dy = cy - (bottom - radius);
} else {
return 0;
}
return Math.max(0, Math.round(radius - Math.sqrt(Math.max(0, radius * radius - dy * dy))));
}
/** Small triangle marker for sidebar overflow; direction -1 = up, 1 = down. */
function drawChevron(image: GrayImage, centerX: number, y: number, direction: -1 | 1): void {
const half = 5;
+172 -25
View File
@@ -1,13 +1,21 @@
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
import { GrayImage } from "../../graphics/image";
import { LayerActions } from "../layers";
import { MenuLayer } from "../menu";
import { APP_VIEWPORT } from "./geometry";
import { createInProcessWindow, YieldAtRootLayer } from "./in-process-window";
import { type ShellWindow } from "./shell";
import { renderIcon, type IconName } from "../../graphics/icons";
import { clamp } from "../../util/numeric-util";
import {
GESTURE_CLICK,
GESTURE_DOUBLE_CLICK,
GESTURE_SCROLL,
} from "../gestures";
import { DashboardInputEvent, Layer, LayerActions, LayerContext } from "../layers";
import { drawSelectionHighlight } from "../menu";
import { createInProcessWindow } from "./in-process-window";
import { shell, type ShellWindow } from "./shell";
export type LauncherAppEntry = {
appId: string;
label: string;
icon: IconName;
};
export type LauncherOptions = {
@@ -23,28 +31,156 @@ export type LauncherOptions = {
export const LAUNCHER_WINDOW_ID = "launcher";
export const LAUNCHER_SURFACE_ID = "window:launcher";
const COLS = 5;
// Row height is sized so 3.5 rows fit the viewport: three full rows are
// always visible, and a fourth (half-clipped) row peeks in to signal that
// there are more apps to scroll to.
const VISIBLE_ROWS = 3.5;
const FULL_ROWS = Math.floor(VISIBLE_ROWS);
const GRID_TOP = 6;
const FOOTER_HEIGHT = 16;
const ICON_SIZE = 44;
const LABEL_GAP = 2;
type LauncherMode = "row" | "item";
/**
* The launcher: a pinned, uncloseable in-process window listing launchable
* apps. Selecting an app asks the controller to launch it (new window,
* possibly in an existing app worker) and foregrounds the new window.
* The launcher grid: app icons with labels, arranged in a 3-column grid.
* Navigation has two levels so the max number of swipes to any app is halved:
* entering from the sidebar starts in "row" mode (scroll picks a row); a tap
* drops into "item" mode on that row, defaulting to the middle column (scroll
* picks the app); a tap launches it. Double-click backs out one level (item →
* row), and from the top level yields to the sidebar.
*/
class LauncherGridLayer implements Layer {
private mode: LauncherMode = "row";
private selectedRow = 0;
private selectedCol = 1;
private scrollRow = 0;
private wasFocused = false;
constructor(private readonly options: LauncherOptions) {}
private rowCount(): number {
return Math.max(1, Math.ceil(this.options.apps.length / COLS));
}
private itemsInRow(row: number): number {
return Math.max(0, Math.min(COLS, this.options.apps.length - row * COLS));
}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const focused = ctx.stack.isFocused();
// Re-entering the launcher (focus gained) resets to row selection.
if (focused && !this.wasFocused) {
this.mode = "row";
}
this.wasFocused = focused;
const rows = this.rowCount();
this.selectedRow = clamp(this.selectedRow, 0, rows - 1);
this.selectedCol = clamp(this.selectedCol, 0, Math.max(0, this.itemsInRow(this.selectedRow) - 1));
const gridBottom = height - FOOTER_HEIGHT;
const rowH = (gridBottom - GRID_TOP) / VISIBLE_ROWS;
const colW = width / COLS;
// Scroll to keep the selected row among the fully-visible rows.
if (this.selectedRow < this.scrollRow) {
this.scrollRow = this.selectedRow;
} else if (this.selectedRow > this.scrollRow + FULL_ROWS - 1) {
this.scrollRow = this.selectedRow - (FULL_ROWS - 1);
}
this.scrollRow = clamp(this.scrollRow, 0, Math.max(0, rows - FULL_ROWS));
const rowY = (row: number) => GRID_TOP + (row - this.scrollRow) * rowH;
// Selection highlight (row band, or a single cell in item mode).
const selY = rowY(this.selectedRow);
if (this.mode === "row") {
drawSelectionHighlight(image, 4, selY + 2, width - 8, rowH - 4, focused, 6);
} else {
drawSelectionHighlight(image, this.selectedCol * colW + 6, selY + 2, colW - 12, rowH - 4, focused, 6);
}
for (let index = 0; index < this.options.apps.length; index++) {
const app = this.options.apps[index]!;
const row = Math.floor(index / COLS);
if (row < this.scrollRow) continue;
const blockTop = rowY(row) + Math.max(2, (rowH - ICON_SIZE - font.lineHeight - LABEL_GAP) / 2);
if (blockTop >= gridBottom) break; // fully below the grid
const centerX = (index % COLS) * colW + colW / 2;
const icon = renderIcon(app.icon, ICON_SIZE);
if (icon) {
// Clip the icon at the grid bottom so a peeking row shows only its top.
const clipHeight = Math.min(icon.height, Math.floor(gridBottom - blockTop));
image.bitBlt(icon, Math.round(centerX - icon.width / 2), Math.round(blockTop), {
height: clipHeight,
transparentZero: true,
});
}
const labelY = Math.round(blockTop + ICON_SIZE + LABEL_GAP);
if (labelY + font.lineHeight <= gridBottom) {
const label = truncate(font, app.label, colW - 8);
image.drawText(font, Math.round(centerX - font.measureText(label) / 2), labelY, label, 210);
}
}
const hint =
this.mode === "row"
? `${GESTURE_SCROLL} row ${GESTURE_CLICK} pick ${GESTURE_DOUBLE_CLICK} back`
: `${GESTURE_SCROLL} app ${GESTURE_CLICK} launch ${GESTURE_DOUBLE_CLICK} row`;
image.drawText(font, 8, height - 14, hint, 110);
return image;
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
const rows = this.rowCount();
switch (event.type) {
case "scroll-up":
case "scroll-down": {
const delta = event.type === "scroll-down" ? 1 : -1;
if (this.mode === "row") {
this.selectedRow = clamp(this.selectedRow + delta, 0, rows - 1);
} else {
this.selectedCol = clamp(this.selectedCol + delta, 0, Math.max(0, this.itemsInRow(this.selectedRow) - 1));
}
return;
}
case "click": {
if (this.mode === "row") {
this.mode = "item";
// Default to the middle column (clamped to the row's app count).
this.selectedCol = Math.min(Math.floor(COLS / 2), this.itemsInRow(this.selectedRow) - 1);
} else {
const index = this.selectedRow * COLS + this.selectedCol;
const app = this.options.apps[index];
if (app) await this.options.launchApp(app.appId);
}
return;
}
case "double-click":
if (this.mode === "item") {
this.mode = "row";
} else {
shell.yieldFocusToSidebar();
}
return;
default:
return;
}
}
}
/**
* The launcher: a pinned, uncloseable in-process window presenting the app
* grid. Selecting an app asks the controller to launch it and foregrounds the
* new window.
*/
export function createLauncherWindow(options: LauncherOptions): ShellWindow {
const menu = new MenuLayer(
"Apps",
options.apps.map((app) => ({
label: app.label,
onSelect: async () => {
await options.launchApp(app.appId);
},
})),
{
x: 8,
y: 8,
width: 272,
minHeight: 0,
maxHeight: APP_VIEWPORT.height - 16,
},
);
return createInProcessWindow({
appId: "launcher",
windowId: LAUNCHER_WINDOW_ID,
@@ -53,8 +189,19 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
icon: "layout-grid",
closeable: false,
actions: options.actions,
baseLayer: new YieldAtRootLayer(menu),
// Not wrapped in YieldAtRootLayer: the grid handles double-click itself to
// back out of item selection before yielding to the sidebar.
baseLayer: new LauncherGridLayer(options),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
}).window;
}
function truncate(font: BdfFont, text: string, maxWidth: number): string {
if (font.measureText(text) <= maxWidth) return text;
let out = text;
while (out.length > 1 && font.measureText(`${out}...`) > maxWidth) {
out = out.slice(0, -1);
}
return `${out}...`;
}
+1 -1
View File
@@ -32,7 +32,7 @@ export function createNightscoutAppWindow(options: InProcessAppOptions): InProce
windowId: NIGHTSCOUT_WINDOW_ID,
title: "Nightscout",
iconLetter: "Ns",
icon: "activity",
icon: "nightscout",
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(new NightscoutLayer()),
+6
View File
@@ -273,6 +273,9 @@ class Shell {
yieldFocusToSidebar(): void {
if (this.focus === "sidebar") return;
this.focus = "sidebar";
// Repaint the window so its selection highlight dims to the unfocused
// style this frame.
this.foregroundWindow()?.requestRender();
this.config.requestShellRender();
}
@@ -353,6 +356,9 @@ class Shell {
case "click":
if (this.windows.length) {
this.focus = "window";
// Repaint the window now so its selection highlight reflects focus
// this frame, not one frame late.
this.foregroundWindow()?.requestRender();
}
return { shell: true, window: false };
default:
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="70.29 0 371.43 512"><g fill="#fff"><path d="M245.67.33c-26.83 1.88-48.51 7.53-71.01 18.48-12.93 6.31-23.82 13.24-35.58 22.6-6.52 5.14-22.75 21.43-28 27.95C89.04 97 76.06 127.65 71.22 163.38c-1.12 8.6-1.27 37.06-.25 47.85 3.46 35.53 12.16 69.02 27.33 105.37 18.83 45.25 49.17 93.31 88.52 140.44 12.17 14.56 33.39 37.72 39.76 43.47 15.17 13.54 36.19 15.27 52.94 4.33 4.38-2.85 10.44-8.76 23.62-23.06 31.2-33.75 58.18-69.33 78.8-103.84 25.1-42 40.72-78.7 50.8-119.37 8.91-35.89 11.35-74.52 6.57-103.08-3.16-18.94-7.99-33.7-17-51.92C401.59 61.68 366.77 29.76 323 12.5 300.04 3.49 269.34-1.35 245.67.33m21.99 29.42c12.83.66 31.61 4.94 45.2 10.28 35.99 14.15 65.87 41.64 82.97 76.25 8.76 17.71 13.34 33.24 15.58 52.69.66 5.9.76 10.38.56 22.14-.25 14.81-.51 18.17-2.44 31.82-8.35 58.95-36.6 121.71-83.08 184.27-21.38 28.71-57.93 70.3-65 73.86-3 1.53-7.99 1.58-10.94.2-7.13-3.41-42.56-43.62-64.65-73.3-33.09-44.39-55.79-86.33-70.3-129.81-11.5-34.61-16.59-65.16-15.83-95.9.41-17.36 2.44-29.52 7.53-45.15 18.43-56.71 68.87-98.65 127.77-106.39 7.18-.92 19.6-1.68 24.13-1.43 1.68.12 5.5.32 8.5.47"/><path d="M247.05 58.51c-11.56.97-23.31 3.41-33.49 6.87-6.36 2.19-18.94 8.2-24.89 11.96-13.49 8.4-26.27 20.26-36.35 33.7l-1.43 1.93 3.31-1.27c8.65-3.26 18.73-4.84 30.7-4.84 13.03 0 22.5 1.73 33.7 6.21 6.67 2.65 12.78 6.11 18.78 10.64 5.09 3.87 13.64 12.52 16.44 16.65.97 1.43 1.88 2.6 2.04 2.6s1.17-1.27 2.29-2.85c5.14-7.18 14.86-16.14 22.91-21.02 21.18-12.98 50.34-16.09 74.68-7.94l4.94 1.68-1.58-2.29c-7.33-10.69-22.25-24.48-35.28-32.78-14.86-9.42-32.93-15.93-51.26-18.48-7.04-.97-18.74-1.33-25.51-.77"/><path d="M178.07 133.9c-20.46 2.39-36.04 13.44-44.64 31.66-3.41 7.13-4.89 13.44-5.19 21.99-.71 18.68 4.99 41.39 14.91 59.41 20.46 37.16 57.27 62 98.55 66.53 11.5 1.27 28.56.46 40.37-1.99 22.7-4.63 44.29-15.88 61.39-31.97 6.82-6.41 16.29-17.97 21.18-25.81 15.17-24.38 22.55-57.88 17.26-78.29-1.43-5.65-4.73-12.98-7.99-17.71-3.41-5.04-9.88-11.45-14.91-14.76-5.14-3.41-12.78-6.57-19.14-7.89-5.29-1.17-19.9-1.32-24.69-.31-19.7 4.28-34.61 16.75-41.03 34.31-3.82 10.33-3.67 8.55-3.87 51.57-.15 42.2-.1 41.08-3 42.45-.81.36-5.09.56-11.66.56h-10.44l-1.63-1.48-1.68-1.48-.31-39.4c-.31-42.76-.2-41.44-3.31-50.7-3.56-10.69-11.61-21.23-21.02-27.59-10.9-7.32-25.41-10.68-39.15-9.1m12.22 6.06c10.74 1.22 20.31 5.85 28.61 13.74 6.67 6.36 11 13.54 13.64 22.65 1.02 3.61 1.17 5.14 1.12 12.98 0 8.2-.1 9.26-1.37 13.39-4.17 13.49-12.73 23.82-25.04 30.24-11.05 5.7-23.62 7.02-35.79 3.72-13.69-3.77-25.76-14.15-31.87-27.59-6.11-13.29-5.5-30.29 1.53-43.12 7.94-14.61 21.94-24.08 38.33-26.01 4.88-.56 5.95-.56 10.84 0m141.66 0c23.57 2.7 41.39 20.41 44.13 43.88 2.44 20.72-9.52 41.54-28.86 50.34-13.08 5.9-29.17 5.65-41.74-.66-13.18-6.62-22.55-18.17-26.52-32.73-1.48-5.5-1.37-18.33.2-24.18 1.48-5.4 4.48-11.86 7.43-15.93 2.49-3.56 9.06-10.03 12.62-12.47 6.01-4.12 14.91-7.43 22.04-8.2 5.82-.61 5.66-.61 10.7-.05"/><path d="M180.62 168.47c-11.2 2.39-18.58 13.39-16.39 24.54 3.26 16.59 23.42 22.81 35.33 10.89 10.28-10.33 7.28-27.44-5.96-33.7-4.08-1.89-9.01-2.55-12.98-1.73m141.92.2c-8.4 1.83-14.91 8.81-16.29 17.41-1.02 6.26 1.37 13.29 6.11 17.92 13.69 13.49 36.8 2.9 35.48-16.29a21.05 21.05 0 0 0-17.1-19.24c-3.37-.61-4.64-.61-8.2.2M163.15 318.02c8.4 16.8 18.12 33.55 28.71 49.48 7.18 10.84 9.01 13.29 9.52 12.98 1.37-.87 26.32-39.81 25.81-40.27-.05-.05-3.05-.81-6.72-1.63-19.9-4.58-39.35-13.44-55.89-25.45-2.19-1.63-4.43-3.21-4.99-3.61-.71-.51.41 2.14 3.56 8.5m183.57-4.68c-13.39 9.82-30.9 18.48-46.98 23.11-10.33 2.95-23.47 5.19-35.63 6.01l-5.75.36-3.82 6.82c-8.5 15.22-21.69 35.99-31.05 48.97-2.34 3.26-4.28 6.06-4.28 6.21 0 1.27 23.21 28.4 33.49 39.2l3.26 3.41 3.46-3.67c37.01-39.71 67.55-82.62 88.42-124.31 4.17-8.3 4.89-9.98 4.33-9.93-.21 0-2.65 1.73-5.45 3.82"/></g></svg>

After

Width:  |  Height:  |  Size: 3.7 KiB