forked from Blendman974/faceclaw
Borderless modes have different padding inside the builtin apps
Most of the builtin apps had some padding between the window edge and their content, because they expect to be displayed with a line border on their edge. We added a customization option to remove the border, so, that padding is not always necessary. Make the layouts dynamically adjust, to omit the padding when it isn't needed.
This commit is contained in:
1 parent
e158452ba4
commit
a02b849200
115 files changed
+3600
-1583
No files matched your search
@@ -8,11 +8,9 @@ import { type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { lineStep } from "../../ui/metrics";
|
||||
import {
|
||||
NOTIFICATION_CONTENT_X,
|
||||
createNotificationActionMenu,
|
||||
drawNotificationHeader,
|
||||
notificationActionMenuBox,
|
||||
notificationContentWidth,
|
||||
notificationDetailLayout,
|
||||
} from "../../ui/notifications";
|
||||
import { type GlucoseRise } from "./missed-bolus-detector";
|
||||
import {
|
||||
@@ -25,7 +23,6 @@ import {
|
||||
|
||||
const ICON_SIZE = 24;
|
||||
const GRAPH_GAP = 6;
|
||||
const GRAPH_BOTTOM_MARGIN = 12;
|
||||
const MIN_GRAPH_HEIGHT = 32;
|
||||
|
||||
type ActionItem = { label: string; run: () => void };
|
||||
@@ -56,13 +53,15 @@ export class MissedBolusNotificationLayer implements Layer {
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const step = lineStep(font);
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const contentX = NOTIFICATION_CONTENT_X;
|
||||
const contentWidth = notificationContentWidth(width);
|
||||
const viewport = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(viewport.width, viewport.height, 0);
|
||||
// The same columns as a notification's detail view, inside the padding
|
||||
// suggested for the edges of whatever hosts this (the shell's modal).
|
||||
const layout = notificationDetailLayout(viewport);
|
||||
const { contentX, contentWidth } = layout;
|
||||
const nowMs = Date.now();
|
||||
|
||||
let y = drawNotificationHeader(image, font, renderIcon("nightscout", ICON_SIZE), `Nightscout ${formatRelativeTime(this.postedAtMs)}`);
|
||||
let y = drawNotificationHeader(image, font, renderIcon("nightscout", ICON_SIZE), `Nightscout ${formatRelativeTime(this.postedAtMs)}`, layout);
|
||||
image.drawText(font, contentX, y, "Missed bolus?", 230);
|
||||
y += step;
|
||||
const minutes = Math.round((this.rise.latestMs - this.rise.onsetMs) / 60_000);
|
||||
@@ -90,12 +89,12 @@ export class MissedBolusNotificationLayer implements Layer {
|
||||
y += step;
|
||||
}
|
||||
const graphTop = y + GRAPH_GAP;
|
||||
const graphHeight = height - GRAPH_BOTTOM_MARGIN - graphTop;
|
||||
const graphHeight = layout.bottom - graphTop;
|
||||
if (graphHeight >= MIN_GRAPH_HEIGHT) {
|
||||
drawNightscoutGraph(image, { x: contentX, y: graphTop, width: contentWidth, height: graphHeight }, nightscout, nowMs, font);
|
||||
}
|
||||
|
||||
this.menu.paint(image, notificationActionMenuBox(width, height), ctx.stack.isFocused());
|
||||
this.menu.paint(image, layout.menuBox, ctx.stack.isFocused());
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,19 @@ export const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
|
||||
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
|
||||
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
|
||||
|
||||
/**
|
||||
* The app page's fixed parts, placed from the title at the window's top and
|
||||
* left padding: a status message and the graph, down from the title's top,
|
||||
* and the status lines' column, right of the readout's left edge.
|
||||
*/
|
||||
const PAGE_MESSAGE_OFFSET_Y = 28;
|
||||
const PAGE_GRAPH_OFFSET_Y = 112;
|
||||
const PAGE_STATUS_OFFSET_X = 148;
|
||||
/** Gap between the page's graph and the caption under it. */
|
||||
const PAGE_CAPTION_GAP = 6;
|
||||
/** The shortest graph the page draws above its caption; with less room the graph takes the caption's. */
|
||||
const PAGE_MIN_GRAPH_HEIGHT = 40;
|
||||
|
||||
/** Draws the trend indicator; returns its width. */
|
||||
export function drawDirectionIndicator(
|
||||
image: GrayImage,
|
||||
@@ -298,36 +311,44 @@ function drawNightscoutReferenceLine(
|
||||
export class NightscoutLayer implements Layer {
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
// Sized to the hosting stack (the Nightscout app viewport).
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
// Sized to the hosting stack (the Nightscout app viewport). Nothing here
|
||||
// scrolls, so the page keeps inside the padding suggested for each of
|
||||
// the viewport's edges: the title, the readout and the graph start at
|
||||
// the left padding, and the graph and its caption end at the bottom's.
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const nightscout = nightscoutBridge.snapshot();
|
||||
const nowMs = Date.now();
|
||||
const step = lineStep(font);
|
||||
image.drawText(font, 22, 16, "Nightscout", 220);
|
||||
const left = padding.left;
|
||||
const top = padding.top;
|
||||
const right = width - padding.right;
|
||||
const bottom = height - padding.bottom;
|
||||
image.drawText(font, left, top, "Nightscout", 220);
|
||||
|
||||
const messageY = top + PAGE_MESSAGE_OFFSET_Y;
|
||||
if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) {
|
||||
image.drawText(font, 22, 44, "Nightscout needs configuration.", 180);
|
||||
image.drawText(font, 22, 44 + step, "Long-press for the menu, then pick Settings to set", 140);
|
||||
image.drawText(font, 22, 44 + 2 * step, "the site URL and API token.", 140);
|
||||
image.drawText(font, left, messageY, "Nightscout needs configuration.", 180);
|
||||
image.drawText(font, left, messageY + step, "Long-press for the menu, then pick Settings to set", 140);
|
||||
image.drawText(font, left, messageY + 2 * step, "the site URL and API token.", 140);
|
||||
return image;
|
||||
}
|
||||
|
||||
if (!nightscout.available || !nightscout.latest) {
|
||||
image.drawText(font, 22, 44, "No Nightscout data available.", 180);
|
||||
image.drawText(font, 22, 44 + step, truncateLine(nightscout.status, 60), 140);
|
||||
image.drawText(font, left, messageY, "No Nightscout data available.", 180);
|
||||
image.drawText(font, left, messageY + step, truncateLine(nightscout.status, 60), 140);
|
||||
return image;
|
||||
}
|
||||
|
||||
// Two-column header above the graph: title + current glucose on the
|
||||
// left, the status lines bottom-aligned on the right.
|
||||
const graphTop = 128;
|
||||
const graphTop = top + PAGE_GRAPH_OFFSET_Y;
|
||||
const latest = nightscout.latest;
|
||||
const glucoseText = `${latest.sgv}`;
|
||||
const glucoseX = 22;
|
||||
const glucoseX = left;
|
||||
const glucoseWidth = nightscoutLargeFont.measureText(glucoseText);
|
||||
// Glucose value vertically centered between the title and the graph.
|
||||
const titleBottom = 16 + font.lineHeight;
|
||||
const titleBottom = top + font.lineHeight;
|
||||
const glucoseY = Math.round((titleBottom + graphTop - nightscoutLargeFont.lineHeight) / 2);
|
||||
image.drawText(nightscoutLargeFont, glucoseX, glucoseY, glucoseText, 230);
|
||||
if (isNightscoutPointStale(latest, nowMs)) {
|
||||
@@ -335,8 +356,8 @@ export class NightscoutLayer implements Layer {
|
||||
}
|
||||
image.drawText(font, glucoseX + glucoseWidth + 8, glucoseY + nightscoutLargeFont.lineHeight - font.lineHeight, nightscout.units, 140);
|
||||
|
||||
const statusX = 170;
|
||||
const statusWidth = width - 22 - statusX;
|
||||
const statusX = left + PAGE_STATUS_OFFSET_X;
|
||||
const statusWidth = right - statusX;
|
||||
const alerts = evaluateNightscoutAlerts(nightscout, loadNightscoutThresholds(), nowMs);
|
||||
const statusLines: { text: string; shade: number; direction?: string; fields?: { text: string; warning?: boolean }[] }[] = [
|
||||
{ text: `Delta ${formatDelta(nightscout.delta)} Trend `, shade: 180, direction: nightscout.direction },
|
||||
@@ -382,10 +403,14 @@ export class NightscoutLayer implements Layer {
|
||||
statusY += step;
|
||||
}
|
||||
|
||||
const captionY = height - font.lineHeight - 6;
|
||||
const graphHeight = Math.max(40, captionY - 6 - graphTop);
|
||||
drawNightscoutGraph(image, { x: 22, y: graphTop, width: width - 44, height: graphHeight }, nightscout, nowMs, font);
|
||||
image.drawText(font, 22, captionY, "2-hour glucose history with basal / carbs / boluses", 130);
|
||||
// The graph spans the padded width, down to the caption on the last
|
||||
// line above the bottom padding. A window too short for both gives the
|
||||
// caption's room to the graph.
|
||||
const captionY = bottom - font.lineHeight;
|
||||
const captioned = captionY - PAGE_CAPTION_GAP - graphTop >= PAGE_MIN_GRAPH_HEIGHT;
|
||||
const graphBottom = captioned ? captionY - PAGE_CAPTION_GAP : bottom;
|
||||
drawNightscoutGraph(image, { x: left, y: graphTop, width: right - left, height: graphBottom - graphTop }, nightscout, nowMs, font);
|
||||
if (captioned) image.drawText(font, left, captionY, "2-hour glucose history with basal / carbs / boluses", 130);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user