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
@@ -5,11 +5,19 @@ import { GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/
|
||||
import { Layer, type LayerContext } from "../../ui/layers";
|
||||
import { micSession, type CaptionLine, type MicSessionState } from "./mic-session";
|
||||
|
||||
/** From the title's top to the first caption row. */
|
||||
const BODY_TOP_OFFSET = 20;
|
||||
/** Indent of the caption rows under the title. */
|
||||
const ROW_INDENT = 4;
|
||||
|
||||
/**
|
||||
* On-glasses captions: each line is prefixed with the speaker's name (their
|
||||
* id until tagged); foreign-language lines show the translation directly
|
||||
* beneath the recognized original. Scroll reviews recent lines; the view
|
||||
* snaps back to live on new speech.
|
||||
*
|
||||
* The title and the hint line stay put, at the padding suggested for the
|
||||
* window's top and bottom edges; the caption rows scroll between the two.
|
||||
*/
|
||||
export class CaptionsLayer implements Layer {
|
||||
private state: MicSessionState = micSession.getState();
|
||||
@@ -33,19 +41,21 @@ export class CaptionsLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const state = this.state;
|
||||
const left = padding.left;
|
||||
const rowX = left + ROW_INDENT;
|
||||
const bodyTop = padding.top + BODY_TOP_OFFSET;
|
||||
|
||||
image.drawText(font, 12, 4, "Captions", 220);
|
||||
image.drawText(font, left, padding.top, "Captions", 220);
|
||||
if (!state.captionsActive) {
|
||||
image.drawText(font, 12, 26, state.captionsNote, 130);
|
||||
image.drawText(font, left, bodyTop + 2, state.captionsNote, 130);
|
||||
}
|
||||
|
||||
const rows = this.buildRows(font, width - 36, state.captionLines);
|
||||
const rows = this.buildRows(font, Math.max(0, width - padding.right - rowX), state.captionLines);
|
||||
const step = lineStep(font) + 1;
|
||||
const bodyTop = 24;
|
||||
const footerY = height - font.lineHeight - 4;
|
||||
const footerY = height - padding.bottom - font.lineHeight;
|
||||
const visibleRows = Math.max(1, Math.floor((footerY - bodyTop) / step));
|
||||
const maxScrollback = Math.max(0, rows.length - visibleRows);
|
||||
this.scrollback = Math.min(this.scrollback, maxScrollback);
|
||||
@@ -54,16 +64,16 @@ export class CaptionsLayer implements Layer {
|
||||
const row = rows[index]!;
|
||||
const y = bodyTop + (index - firstRow) * step;
|
||||
if (row.prefix) {
|
||||
image.drawText(font, 16, y, row.prefix, row.prefixValue);
|
||||
image.drawText(font, 16 + font.measureText(row.prefix), y, row.text, row.value);
|
||||
image.drawText(font, rowX, y, row.prefix, row.prefixValue);
|
||||
image.drawText(font, rowX + font.measureText(row.prefix), y, row.text, row.value);
|
||||
} else {
|
||||
image.drawText(font, 16 + row.indent, y, row.text, row.value);
|
||||
image.drawText(font, rowX + row.indent, y, row.text, row.value);
|
||||
}
|
||||
}
|
||||
|
||||
image.drawText(
|
||||
font,
|
||||
12,
|
||||
left,
|
||||
footerY,
|
||||
`${GESTURE_SCROLL} history ${GESTURE_DOUBLE_CLICK} back` +
|
||||
(this.scrollback > 0 ? ` (${this.scrollback} back)` : ""),
|
||||
|
||||
@@ -4,6 +4,12 @@ import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
|
||||
import { Layer, type LayerContext } from "../../ui/layers";
|
||||
import { micSession, type MicSessionState } from "./mic-session";
|
||||
|
||||
/** From the title's top to the status line, and to the first meter row. */
|
||||
const STATUS_OFFSET_Y = 18;
|
||||
const METERS_OFFSET_Y = 42;
|
||||
/** Width of the mic-name column left of the meters. */
|
||||
const LABEL_COLUMN_WIDTH = 118;
|
||||
|
||||
/**
|
||||
* Live level meters, one per active microphone (a single mixed channel on
|
||||
* stock firmware; up to four mics with the mic-control firmware), plus the
|
||||
@@ -22,24 +28,27 @@ export class LevelsLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const state = this.state;
|
||||
// Text starts at the padding suggested for the window's left edge, and
|
||||
// the meters run to the right edge's.
|
||||
const left = padding.left;
|
||||
|
||||
image.drawText(font, 12, 6, "Microphone Levels", 220);
|
||||
image.drawText(font, 12, 24, state.statusText, 110);
|
||||
image.drawText(font, left, padding.top, "Microphone Levels", 220);
|
||||
image.drawText(font, left, padding.top + STATUS_OFFSET_Y, state.statusText, 110);
|
||||
|
||||
const barX = 130;
|
||||
const barWidth = width - barX - 40;
|
||||
const barX = left + LABEL_COLUMN_WIDTH;
|
||||
const barWidth = Math.max(0, width - padding.right - barX);
|
||||
const rowHeight = 26;
|
||||
let y = 48;
|
||||
let y = padding.top + METERS_OFFSET_Y;
|
||||
const labels = state.levelLabels.length ? state.levelLabels : ["Glasses mic"];
|
||||
labels.forEach((label, index) => {
|
||||
const level = state.levels[index] ?? 0;
|
||||
const enabled = state.levelsEnabled[index] ?? true;
|
||||
image.drawText(font, 12, y + 3, enabled ? label : `${label} (off)`, enabled ? 190 : 90);
|
||||
image.drawText(font, left, y + 3, enabled ? label : `${label} (off)`, enabled ? 190 : 90);
|
||||
image.drawRect(barX, y, barWidth, 16, enabled ? 70 : 40);
|
||||
const fill = Math.round((barWidth - 4) * level);
|
||||
const fill = Math.round(Math.max(0, barWidth - 4) * level);
|
||||
if (fill > 0) {
|
||||
// A disabled mic still meters (dimly) so its signal can be checked
|
||||
// before switching it back on.
|
||||
@@ -55,15 +64,15 @@ export class LevelsLayer implements Layer {
|
||||
|
||||
y += 6;
|
||||
if (state.doaDeviceDeg !== null) {
|
||||
image.drawText(font, 12, y, `Direction of arrival: ${Math.round(state.doaDeviceDeg)}°`, 160);
|
||||
image.drawText(font, left, y, `Direction of arrival: ${Math.round(state.doaDeviceDeg)}°`, 160);
|
||||
y += 18;
|
||||
}
|
||||
image.drawText(font, 12, y, `Signal-strength ratio: ${state.ssr}`, 130);
|
||||
image.drawText(font, left, y, `Signal-strength ratio: ${state.ssr}`, 130);
|
||||
y += 18;
|
||||
const ancText = state.ancOn && state.ancEngine ? `on — ${state.ancEngine}` : "off";
|
||||
image.drawText(font, 12, y, `Noise cancellation: ${ancText}`, 130);
|
||||
image.drawText(font, left, y, `Noise cancellation: ${ancText}`, 130);
|
||||
|
||||
image.drawText(font, 12, height - font.lineHeight - 4, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
image.drawText(font, left, height - padding.bottom - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { imageFromAsciiArt } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { appViewportSize } from "../../ui/shell/geometry";
|
||||
import {
|
||||
MenuLayer,
|
||||
TextPageLayer,
|
||||
@@ -62,15 +61,7 @@ const TRAY_ICON = imageFromAsciiArt(
|
||||
{ "#": 220 },
|
||||
);
|
||||
|
||||
const MENU_LAYOUT = {
|
||||
x: 8,
|
||||
y: 8,
|
||||
width: 292,
|
||||
showBorder: false,
|
||||
minHeight: 0,
|
||||
maxHeight: appViewportSize("min").height - 16,
|
||||
opaque: true,
|
||||
};
|
||||
const MENU_LAYOUT = { page: true, width: 268 } as const;
|
||||
|
||||
/** Persist a config change; the running session applies it live. */
|
||||
function updateMicConfig(mutate: (config: MicConfig) => MicConfig): void {
|
||||
|
||||
@@ -5,6 +5,16 @@ import { Layer, type LayerContext } from "../../ui/layers";
|
||||
import { micSession, type MicSessionState } from "./mic-session";
|
||||
import { dotBrightness } from "./radar-dots";
|
||||
|
||||
/** Room above the plot's ring for its "front" label. */
|
||||
const FRONT_LABEL_BAND = 14;
|
||||
/** Gap between the ring and the hint line under it. */
|
||||
const RING_FOOTER_GAP = 10;
|
||||
/** The least the ring keeps clear of the window's sides, which leaves the readout panel its corner. */
|
||||
const RING_SIDE_CLEARANCE = 90;
|
||||
/** The readout panel: the least its column is wide, and its drop below the title's top. */
|
||||
const PANEL_MIN_WIDTH = 104;
|
||||
const PANEL_OFFSET_Y = 20;
|
||||
|
||||
/**
|
||||
* The Sonic Radar: a top-down view around the wearer's head. The shaded
|
||||
* wedge is the listening beam (scroll rotates it, click locks it onto the
|
||||
@@ -14,6 +24,10 @@ import { dotBrightness } from "./radar-dots";
|
||||
* scene is world-anchored (an N tick marks north and dots stay put as the
|
||||
* head turns); dots glow full-bright while their speaker is talking and fade
|
||||
* with the time since they last spoke.
|
||||
*
|
||||
* The plot is centred on the window, between the title row and the hint
|
||||
* line; those and the readout panel keep to the padding suggested for the
|
||||
* window's edges.
|
||||
*/
|
||||
export class RadarLayer implements Layer {
|
||||
private state: MicSessionState = micSession.getState();
|
||||
@@ -28,17 +42,20 @@ export class RadarLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const state = this.state;
|
||||
|
||||
const footerY = height - padding.bottom - font.lineHeight;
|
||||
const ringTop = padding.top + FRONT_LABEL_BAND;
|
||||
const ringBottom = footerY - RING_FOOTER_GAP;
|
||||
const centerX = (width / 2) | 0;
|
||||
const centerY = ((height - 24) / 2 + 6) | 0;
|
||||
const radius = Math.min(centerX - 90, ((height - 40) / 2) | 0);
|
||||
const centerY = ((ringTop + ringBottom) / 2) | 0;
|
||||
const radius = Math.max(0, Math.min(centerX - RING_SIDE_CLEARANCE, ((ringBottom - ringTop) / 2) | 0));
|
||||
|
||||
image.drawText(font, 12, 6, "Sonic Radar", 220);
|
||||
image.drawText(font, padding.left, padding.top, "Sonic Radar", 220);
|
||||
const modeText = state.mode === "extended" ? "4-mic array" : "firmware DoA";
|
||||
image.drawText(font, width - font.measureText(modeText) - 12, 6, modeText, 110);
|
||||
image.drawText(font, width - padding.right - font.measureText(modeText), padding.top, modeText, 110);
|
||||
|
||||
// Beam wedge (device frame; the head is the reference for display).
|
||||
const beamDeviceDeg = this.deviceBeamDeg(state);
|
||||
@@ -70,7 +87,7 @@ export class RadarLayer implements Layer {
|
||||
// Radar rings.
|
||||
drawCircle(image, centerX, centerY, radius, 60);
|
||||
drawCircle(image, centerX, centerY, (radius / 2) | 0, 30);
|
||||
image.drawText(font, centerX - (font.measureText("front") / 2) | 0, centerY - radius - 14, "front", 90);
|
||||
image.drawText(font, centerX - (font.measureText("front") / 2) | 0, centerY - radius - FRONT_LABEL_BAND, "front", 90);
|
||||
|
||||
// Compass north tick: anchors the world frame visually as the head turns.
|
||||
if (state.headingDeg !== null) {
|
||||
@@ -127,37 +144,31 @@ export class RadarLayer implements Layer {
|
||||
}
|
||||
const label = dot.name;
|
||||
const labelValue = Math.max(90, value - 50);
|
||||
const labelX = dotX + 8 + font.measureText(label) > width ? dotX - font.measureText(label) - 8 : dotX + 8;
|
||||
const labelX = dotX + 8 + font.measureText(label) > width - padding.right ? dotX - font.measureText(label) - 8 : dotX + 8;
|
||||
image.drawText(font, labelX, dotY - 6, label, labelValue);
|
||||
}
|
||||
|
||||
// Side panel: beam + level readouts.
|
||||
const panelX = width - 116;
|
||||
let panelY = 26;
|
||||
image.drawText(
|
||||
font,
|
||||
panelX,
|
||||
panelY,
|
||||
state.headingDeg !== null ? `Heading ${Math.round(state.headingDeg)}°` : "No compass",
|
||||
state.headingDeg !== null ? 150 : 90,
|
||||
);
|
||||
panelY += 16;
|
||||
image.drawText(font, panelX, panelY, `Beam ${Math.round(state.beamWorldDeg)}°`, 170);
|
||||
panelY += 16;
|
||||
image.drawText(font, panelX, panelY, `Width ${Math.round(state.beamWidthDeg)}°`, 130);
|
||||
panelY += 16;
|
||||
image.drawText(font, panelX, panelY, state.beamLocked ? "Locked on talker" : "Manual aim", 130);
|
||||
panelY += 16;
|
||||
if (state.doaDeviceDeg !== null) {
|
||||
image.drawText(font, panelX, panelY, `Heard ${Math.round(state.doaDeviceDeg)}°`, 200);
|
||||
// Side panel: beam + level readouts, in a column that ends at the right
|
||||
// edge's padding and is wide enough for its longest line.
|
||||
const panelLines: Array<[text: string, value: number]> = [
|
||||
state.headingDeg !== null ? [`Heading ${Math.round(state.headingDeg)}°`, 150] : ["No compass", 90],
|
||||
[`Beam ${Math.round(state.beamWorldDeg)}°`, 170],
|
||||
[`Width ${Math.round(state.beamWidthDeg)}°`, 130],
|
||||
[state.beamLocked ? "Locked on talker" : "Manual aim", 130],
|
||||
];
|
||||
if (state.doaDeviceDeg !== null) panelLines.push([`Heard ${Math.round(state.doaDeviceDeg)}°`, 200]);
|
||||
panelLines.push([state.beamFilterOn ? "Filter: beam only" : "Filter: off", 130]);
|
||||
const panelWidth = Math.max(PANEL_MIN_WIDTH, ...panelLines.map(([text]) => Math.ceil(font.measureText(text))));
|
||||
const panelX = width - padding.right - panelWidth;
|
||||
let panelY = padding.top + PANEL_OFFSET_Y;
|
||||
for (const [text, value] of panelLines) {
|
||||
image.drawText(font, panelX, panelY, text, value);
|
||||
panelY += 16;
|
||||
}
|
||||
image.drawText(font, panelX, panelY, state.beamFilterOn ? "Filter: beam only" : "Filter: off", 130);
|
||||
|
||||
const footerY = height - font.lineHeight - 4;
|
||||
image.drawText(
|
||||
font,
|
||||
12,
|
||||
padding.left,
|
||||
footerY,
|
||||
`${GESTURE_SCROLL} aim ${GESTURE_CLICK} lock ${GESTURE_DOUBLE_CLICK} back`,
|
||||
110,
|
||||
|
||||
Reference in new issue
Block a user