forked from Blendman974/faceclaw
Fix issue that caused broken Nightscout widget on the status bar on iOS
This commit is contained in:
1 parent
6df52021c8
commit
32fa5c0e6e
4 files changed
+56
-7
No files matched your search
@@ -84,7 +84,8 @@ function buildNightscoutTrayIcon(state: NightscoutState): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const nowMs = Date.now();
|
||||
const label = state.latest ? `${state.latest.sgv}` : "--";
|
||||
const labelWidth = font.measureText(label);
|
||||
// A TTF face measures fractionally; the icon's size and layout need whole pixels.
|
||||
const labelWidth = Math.ceil(font.measureText(label));
|
||||
const warning = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs).any;
|
||||
const graphEnd = labelWidth + 4 + TRAY_GRAPH_WIDTH;
|
||||
const image = new GrayImage(graphEnd + (warning ? 24 : 0), TRAY_HEIGHT, 0);
|
||||
|
||||
+12
-3
@@ -4,6 +4,9 @@ import type { MenuHighlightAnimation } from "../ui/menu-highlight-motion";
|
||||
import { Glyph } from "./bdffont";
|
||||
import { wrapText } from "./textwrap";
|
||||
|
||||
// This file is also built by tests/tsconfig.json, which has no DOM or Node types.
|
||||
declare const console: { warn(message: string): void };
|
||||
|
||||
export const G2_LENS_WIDTH = 640;
|
||||
export const G2_LENS_HEIGHT = 480;
|
||||
const DEFAULT_CORNER_RADIUS = 8;
|
||||
@@ -156,9 +159,15 @@ export class GrayImage {
|
||||
private memoizedSourceHash: number | null = null;
|
||||
|
||||
constructor(width: number, height: number, fill = 0) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.pixels = new Uint8Array(width * height);
|
||||
// A fractional width would put most rows' `y * width + x` between pixels,
|
||||
// silently losing them. TTF text measures fractionally, so this is easy to
|
||||
// hit; the stack is there because the size alone doesn't identify the caller.
|
||||
if (!Number.isInteger(width) || !Number.isInteger(height)) {
|
||||
console.warn(`GrayImage: rounding up non-integer size ${width}x${height}\n${new Error().stack}`);
|
||||
}
|
||||
this.width = Math.ceil(width);
|
||||
this.height = Math.ceil(height);
|
||||
this.pixels = new Uint8Array(this.width * this.height);
|
||||
if (fill !== 0) {
|
||||
this.clear(fill);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user