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
@@ -25,10 +25,6 @@ const INSTRUCTIONS_BY_FRAME: Record<NorthReference, string> = {
|
||||
magnetic: "magnetic compass heading (as read by another compass), then adjust the calibration offset below",
|
||||
};
|
||||
|
||||
/** Margins around the instruction paragraph. */
|
||||
const TEXT_PADDING_X = 16;
|
||||
const TEXT_PADDING_TOP = 10;
|
||||
|
||||
export class CompassCalibrationLayer implements Layer {
|
||||
constructor(
|
||||
/** Current uncorrected magnetometer heading, or null before the first reading. */
|
||||
@@ -36,7 +32,7 @@ export class CompassCalibrationLayer implements Layer {
|
||||
) {}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const small = getDefaultSmallFont();
|
||||
const medium = getDefaultMediumFont();
|
||||
@@ -47,14 +43,17 @@ export class CompassCalibrationLayer implements Layer {
|
||||
// Before the first reading there is no frame to name yet; the true-mode
|
||||
// wording is the default and the readout will correct it once data arrives.
|
||||
const frame = resolved?.frame ?? "true";
|
||||
const lines = wrapText(small, INSTRUCTIONS_PREAMBLE + INSTRUCTIONS_BY_FRAME[frame], width - TEXT_PADDING_X * 2);
|
||||
// The instructions fill the width inside the padding suggested for the
|
||||
// window's edges, from the top's down.
|
||||
const lines = wrapText(small, INSTRUCTIONS_PREAMBLE + INSTRUCTIONS_BY_FRAME[frame], Math.max(0, width - padding.left - padding.right));
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
image.drawText(small, TEXT_PADDING_X, TEXT_PADDING_TOP + i * smallStep, lines[i]!, 190);
|
||||
image.drawText(small, padding.left, padding.top + i * smallStep, lines[i]!, 190);
|
||||
}
|
||||
const textBottom = TEXT_PADDING_TOP + lines.length * smallStep;
|
||||
const textBottom = padding.top + lines.length * smallStep;
|
||||
|
||||
// Readouts along the bottom: dim label over a bright value, in thirds.
|
||||
const valueTop = height - medium.lineHeight;
|
||||
// Readouts along the bottom, above its padding: dim label over a bright
|
||||
// value, in equal columns.
|
||||
const valueTop = height - padding.bottom - medium.lineHeight;
|
||||
const labelTop = valueTop - small.lineHeight;
|
||||
const columns: Array<[string, string]> = [
|
||||
["Raw", raw === null ? "--°" : `${Math.round(raw)}°`],
|
||||
|
||||
@@ -41,18 +41,9 @@ export const COMPASS_SURFACE_ID = "window:compass";
|
||||
const RECONCILE_INTERVAL_MS = 400;
|
||||
/** Vertical breathing room between the readout, the status line and the rose. */
|
||||
const STACK_GAP = 8;
|
||||
/** Padding above the readout and below the rose's near edge. */
|
||||
const TOP_PAD = 2;
|
||||
const BOTTOM_PAD = 4;
|
||||
/** Clearance between the rose's widest point and the viewport edge. */
|
||||
const EDGE_PAD = 8;
|
||||
/** Inset of the top-right magnetometer calibration readout from the window edges. */
|
||||
const ACCURACY_TOP_PAD = TOP_PAD + 4;
|
||||
const ACCURACY_RIGHT_PAD = EDGE_PAD + 4;
|
||||
/** Cap on the rose's radius, so a tall window doesn't get a comical one. */
|
||||
const MAX_ROSE_RADIUS = 98;
|
||||
|
||||
|
||||
class CompassLayer implements Layer {
|
||||
private rawHeading: number | null = null;
|
||||
private diagnostics: CompassDiagnostics | null = null;
|
||||
@@ -161,35 +152,41 @@ class CompassLayer implements Layer {
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const small = getDefaultSmallFont();
|
||||
const large = getDefaultLargeFont();
|
||||
const heading = this.rawHeading === null ? null : resolveHeading(this.rawHeading).displayDegrees;
|
||||
const headingText = heading === null ? "--°" : `${Math.round(heading)}° ${cardinalDirection(heading)}`;
|
||||
const statusLines = wrapText(small, this.statusText(), width - STACK_GAP * 2);
|
||||
// Text and the rose keep inside the padding suggested for the window's edges.
|
||||
const textWidth = Math.max(0, width - padding.left - padding.right);
|
||||
const statusLines = wrapText(small, this.statusText(), textWidth);
|
||||
const smallStep = lineStep(small);
|
||||
const headingFont = large.measureText(headingText) <= width - EDGE_PAD * 2 ? large : small;
|
||||
const headingFont = large.measureText(headingText) <= textWidth ? large : small;
|
||||
const readoutWidth = headingFont.measureText(headingText);
|
||||
const readoutHeight = headingFont.lineHeight;
|
||||
|
||||
// One column centred on the display's true centre, so the rose sits where
|
||||
// the wearer is looking rather than 32px beside it (with a side strip).
|
||||
const cx = screenCenterInViewportX();
|
||||
// A line of that column: centred there, short of leaving the padded width.
|
||||
const lineX = (lineWidth: number) =>
|
||||
Math.round(Math.max(padding.left, Math.min(width - padding.right - lineWidth, cx - lineWidth / 2)));
|
||||
|
||||
// The rose is sized and placed first — it hangs off the bottom edge — and
|
||||
// the readout then floats in whatever room is left above it.
|
||||
// the readout then floats in whatever room is left above it. Its far
|
||||
// edges land on the last row and column inside the padding.
|
||||
const textHeight = readoutHeight + 4 + statusLines.length * smallStep;
|
||||
const { cy, radius, ringTop } = layoutCompassRose({
|
||||
width,
|
||||
height,
|
||||
cx,
|
||||
topClearance: TOP_PAD + textHeight + STACK_GAP,
|
||||
bottomPad: BOTTOM_PAD,
|
||||
edgePad: EDGE_PAD,
|
||||
topClearance: padding.top + textHeight + STACK_GAP,
|
||||
bottomPad: padding.bottom + 1,
|
||||
edgePad: { left: padding.left, right: padding.right + 1 },
|
||||
maxRadius: MAX_ROSE_RADIUS,
|
||||
});
|
||||
|
||||
let y = Math.max(TOP_PAD, Math.round((ringTop - TICK_HEIGHT - textHeight) / 2));
|
||||
let y = Math.max(padding.top, Math.round((ringTop - TICK_HEIGHT - textHeight) / 2));
|
||||
const fade = heading === null ? 0.45 : 1;
|
||||
const clipY = y + textHeight + 6;
|
||||
const backgroundKey = [width, height, cx, cy, radius, clipY, fade].join(",");
|
||||
@@ -201,16 +198,16 @@ class CompassLayer implements Layer {
|
||||
}
|
||||
const image = this.background.image.clone();
|
||||
drawCompassRose(image, cx, cy, radius, heading);
|
||||
const readoutX = Math.round(Math.max(EDGE_PAD, Math.min(width - EDGE_PAD - readoutWidth, cx - readoutWidth / 2)));
|
||||
image.drawText(headingFont, readoutX, y, headingText, heading === null ? 150 : 255);
|
||||
image.drawText(headingFont, lineX(readoutWidth), y, headingText, heading === null ? 150 : 255);
|
||||
y += readoutHeight + 4;
|
||||
for (const line of statusLines) {
|
||||
image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125);
|
||||
image.drawText(small, lineX(small.measureText(line)), y, line, 125);
|
||||
y += smallStep;
|
||||
}
|
||||
if (glassesHaveCompass()) {
|
||||
// The magnetometer calibration readout sits in the window's top-right corner.
|
||||
const accuracyText = magneticAccuracyText(this.diagnostics);
|
||||
image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175);
|
||||
image.drawText(small, width - padding.right - small.measureText(accuracyText), padding.top, accuracyText, 175);
|
||||
}
|
||||
|
||||
return image;
|
||||
|
||||
@@ -78,17 +78,19 @@ export function layoutCompassRose(options: {
|
||||
/** Lowest y already used above the rose (readout text, its gap). */
|
||||
topClearance: number;
|
||||
bottomPad: number;
|
||||
edgePad: number;
|
||||
/** Clearance between the rose's widest point and the box's sides: one figure for both, or each side's. */
|
||||
edgePad: number | { left: number; right: number };
|
||||
maxRadius: number;
|
||||
minRadius?: number;
|
||||
}): { cx: number; cy: number; radius: number; ringTop: number } {
|
||||
const { width, height, cx } = options;
|
||||
const sidePad = typeof options.edgePad === "number" ? { left: options.edgePad, right: options.edgePad } : options.edgePad;
|
||||
const radius = Math.max(
|
||||
options.minRadius ?? 24,
|
||||
Math.min(
|
||||
options.maxRadius,
|
||||
Math.floor((height - options.bottomPad - options.topClearance - TICK_HEIGHT) / (RING_HEIGHT_PER_RADIUS + DISC_DEPTH)),
|
||||
Math.floor((Math.min(cx, width - cx) - options.edgePad) / RING_HALF_WIDTH_PER_RADIUS),
|
||||
Math.floor(Math.min(cx - sidePad.left, width - cx - sidePad.right) / RING_HALF_WIDTH_PER_RADIUS),
|
||||
),
|
||||
);
|
||||
// The wall hangs below the rim, so the near rim sits a wall's depth up
|
||||
|
||||
Reference in new issue
Block a user