forked from Blendman974/faceclaw
Merge branch 'nightscout-missed-bolus-detector'
This commit is contained in:
commit
fedc7fed67
14 files changed
+1012
-68
No files matched your search
+61
-39
@@ -190,22 +190,7 @@ export class NotificationsListLayer implements Layer {
|
||||
*/
|
||||
export class SingleNotificationLayer implements Layer {
|
||||
/** The action column; its items are rebuilt from the live notification on every paint and input. */
|
||||
private readonly detailMenu = new Menu<DetailMenuItem>({
|
||||
wrap: false,
|
||||
rowGap: DETAIL_MENU_ROW_GAP,
|
||||
highlight: { radius: 6 },
|
||||
getHeight: (item, width) => {
|
||||
const font = getDefaultSmallFont();
|
||||
return detailMenuRowLines(font, item, width).length * lineStep(font) + 8;
|
||||
},
|
||||
draw: ({ image, item, x, y, width, selected }) => {
|
||||
const font = getDefaultSmallFont();
|
||||
const lines = detailMenuRowLines(font, item, width);
|
||||
for (let line = 0; line < lines.length; line++) {
|
||||
image.drawText(font, x + DETAIL_MENU_TEXT_X, y + DETAIL_MENU_TEXT_Y + line * lineStep(font), lines[line]!, selected ? 255 : 185);
|
||||
}
|
||||
},
|
||||
});
|
||||
private readonly detailMenu = createNotificationActionMenu<DetailMenuItem>((item) => item.kind === "disable-source");
|
||||
private confirmation: { source: AndroidNotification; menu: Menu<ConfirmationItem> } | null = null;
|
||||
// The last paint, which a tray-hosted layer repeats once its notification
|
||||
// is gone, until the tray swaps in a neighbour's (see closeUnavailableNotification).
|
||||
@@ -234,7 +219,7 @@ export class SingleNotificationLayer implements Layer {
|
||||
|
||||
this.detailMenu.setItems(buildDetailMenu(notification, this.options.origin));
|
||||
drawDetailContent(image, font, notification, iconForNotification(notification.key), width, height);
|
||||
this.detailMenu.paint(image, detailMenuBox(width, height), ctx.stack.isFocused());
|
||||
this.detailMenu.paint(image, notificationActionMenuBox(width, height), ctx.stack.isFocused());
|
||||
this.lastImage = image;
|
||||
return image;
|
||||
}
|
||||
@@ -432,20 +417,9 @@ function drawDetailContent(
|
||||
width: number,
|
||||
height: number,
|
||||
): void {
|
||||
const contentX = DETAIL_CONTENT_X;
|
||||
const menuX = width - DETAIL_MENU_WIDTH - 24;
|
||||
const contentWidth = menuX - contentX - 20;
|
||||
image.drawText(font, contentX, DETAIL_TITLE_Y, "Notification", 220);
|
||||
// The header row (icon + app name) and the body stack below the title's
|
||||
// line box, so a large UI font pushes them down instead of overlapping.
|
||||
const headerTop = DETAIL_TITLE_Y + font.lineHeight + DETAIL_HEADER_GAP;
|
||||
const headerHeight = Math.max(ICON_SIZE, font.lineHeight);
|
||||
let appLineX = contentX;
|
||||
if (icon) {
|
||||
image.bitBlt(icon, contentX, headerTop + ((headerHeight - ICON_SIZE) >> 1), { transparentZero: true });
|
||||
appLineX = contentX + ICON_SIZE + ICON_TEXT_GAP;
|
||||
}
|
||||
image.drawText(font, appLineX, centeredTextY(font, headerTop, headerHeight), `${notification.appName || notification.packageName} ${formatRelativeTime(notification.postTime)}`, 150);
|
||||
const contentX = NOTIFICATION_CONTENT_X;
|
||||
const contentWidth = notificationContentWidth(width);
|
||||
const bodyTop = drawNotificationHeader(image, font, icon, `${notification.appName || notification.packageName} ${formatRelativeTime(notification.postTime)}`);
|
||||
|
||||
const lines: string[] = [];
|
||||
lines.push(...wrapText(font, notification.title || "(untitled)", contentWidth));
|
||||
@@ -461,7 +435,6 @@ function drawDetailContent(
|
||||
}
|
||||
|
||||
const step = lineStep(font);
|
||||
const bodyTop = headerTop + headerHeight + DETAIL_BODY_GAP;
|
||||
const maxLines = Math.max(1, ((height - bodyTop - step) / step) | 0);
|
||||
for (let index = 0; index < Math.min(lines.length, maxLines); index++) {
|
||||
const line = lines[index]!;
|
||||
@@ -472,8 +445,63 @@ function drawDetailContent(
|
||||
}
|
||||
}
|
||||
|
||||
/** Left edge of a notification detail view's content column. */
|
||||
export const NOTIFICATION_CONTENT_X = DETAIL_CONTENT_X;
|
||||
|
||||
/** Width of a notification detail view's content column, left of the action column. */
|
||||
export function notificationContentWidth(width: number): number {
|
||||
return width - DETAIL_MENU_WIDTH - 24 - NOTIFICATION_CONTENT_X - 20;
|
||||
}
|
||||
|
||||
/**
|
||||
* The top of a notification detail view: the "Notification" title, then the
|
||||
* source's icon and label. Returns the y where the body starts.
|
||||
*/
|
||||
export function drawNotificationHeader(image: GrayImage, font: UiFont, icon: GrayImage | null, sourceLabel: string): number {
|
||||
const contentX = NOTIFICATION_CONTENT_X;
|
||||
image.drawText(font, contentX, DETAIL_TITLE_Y, "Notification", 220);
|
||||
// The header row (icon + app name) and the body stack below the title's
|
||||
// line box, so a large UI font pushes them down instead of overlapping.
|
||||
const headerTop = DETAIL_TITLE_Y + font.lineHeight + DETAIL_HEADER_GAP;
|
||||
const headerHeight = Math.max(ICON_SIZE, font.lineHeight);
|
||||
let sourceX = contentX;
|
||||
if (icon) {
|
||||
image.bitBlt(icon, contentX, headerTop + ((headerHeight - ICON_SIZE) >> 1), { transparentZero: true });
|
||||
sourceX = contentX + ICON_SIZE + ICON_TEXT_GAP;
|
||||
}
|
||||
image.drawText(font, sourceX, centeredTextY(font, headerTop, headerHeight), sourceLabel, 150);
|
||||
return headerTop + headerHeight + DETAIL_BODY_GAP;
|
||||
}
|
||||
|
||||
/**
|
||||
* A notification detail view's right-hand action column. Rows truncate their
|
||||
* label to one line, except those `wraps` picks, which wrap it.
|
||||
*/
|
||||
export function createNotificationActionMenu<T extends { label: string }>(wraps: (item: T) => boolean = () => false): Menu<T> {
|
||||
const rowLines = (font: UiFont, item: T, rowWidth: number): string[] => {
|
||||
const textWidth = rowWidth - 2 * DETAIL_MENU_TEXT_X;
|
||||
return wraps(item) ? wrapText(font, item.label, textWidth) : [truncateText(font, item.label, textWidth)];
|
||||
};
|
||||
return new Menu<T>({
|
||||
wrap: false,
|
||||
rowGap: DETAIL_MENU_ROW_GAP,
|
||||
highlight: { radius: 6 },
|
||||
getHeight: (item, width) => {
|
||||
const font = getDefaultSmallFont();
|
||||
return rowLines(font, item, width).length * lineStep(font) + 8;
|
||||
},
|
||||
draw: ({ image, item, x, y, width, selected }) => {
|
||||
const font = getDefaultSmallFont();
|
||||
const lines = rowLines(font, item, width);
|
||||
for (let line = 0; line < lines.length; line++) {
|
||||
image.drawText(font, x + DETAIL_MENU_TEXT_X, y + DETAIL_MENU_TEXT_Y + line * lineStep(font), lines[line]!, selected ? 255 : 185);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** The action column's row boxes: right of the content, from DETAIL_MENU_TOP to the bottom margin. */
|
||||
function detailMenuBox(width: number, height: number): MenuBox {
|
||||
export function notificationActionMenuBox(width: number, height: number): MenuBox {
|
||||
return {
|
||||
x: width - DETAIL_MENU_WIDTH - 32,
|
||||
y: DETAIL_MENU_TOP,
|
||||
@@ -482,12 +510,6 @@ function detailMenuBox(width: number, height: number): MenuBox {
|
||||
};
|
||||
}
|
||||
|
||||
/** An action row's text lines: the disable-source row wraps, the rest truncate to one line. */
|
||||
function detailMenuRowLines(font: UiFont, item: DetailMenuItem, rowWidth: number): string[] {
|
||||
const textWidth = rowWidth - 2 * DETAIL_MENU_TEXT_X;
|
||||
return item.kind === "disable-source" ? wrapText(font, item.label, textWidth) : [truncateText(font, item.label, textWidth)];
|
||||
}
|
||||
|
||||
function buildDetailMenu(notification: AndroidNotification, origin: SingleNotificationLayerOrigin): DetailMenuItem[] {
|
||||
return [
|
||||
{ kind: "back", label: "Back" },
|
||||
|
||||
Reference in new issue
Block a user