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:
James Babcock committed 2026-11-11 15:19:29 -08:00
1 parent e158452ba4
commit a02b849200
115 files changed
+3600 -1583

No files matched your search

+34 -24
View File
@@ -19,13 +19,21 @@ import {
import { directionalFallback, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
const LIST_X = 20;
/** List view: the selection box extends this far left and right of the row text. */
const LIST_HIGHLIGHT_PAD = 6;
/** Header text: how far in from the rows' sides, which lines it up with list-row text. */
const HEADER_INSET_X = LIST_HIGHLIGHT_PAD;
/** Between the header's title and the path after it. */
const HEADER_PATH_GAP = 14;
/** Under the header's line, before the rows. */
const HEADER_GAP = 2;
/** Header: one line holding both the title and the current path. */
function headerHeight(font: UiFont): number {
return 10 + font.lineHeight;
/**
* Bottom of the header: one line holding both the title and the current
* path, below the padding suggested for the window's top edge.
*/
function headerBottom(font: UiFont, paddingTop: number): number {
return paddingTop + font.lineHeight + HEADER_GAP;
}
export type FilesViewMode = "icons" | "list";
@@ -147,35 +155,37 @@ export class FileBrowserLayer 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);
// The rows (grid bands, list selection boxes) span the window inside the
// padding suggested for its sides.
const rowsX = padding.left;
const rowsWidth = Math.max(0, width - padding.left - padding.right);
image.drawText(font, 20, 8, "Files", 220);
const titleX = rowsX + HEADER_INSET_X;
image.drawText(font, titleX, padding.top, "Files", 220);
const pathLabel = this.location === null ? "Places" : this.location;
const pathX = 20 + font.measureText("Files") + 14;
image.drawText(font, pathX, 8, truncateLeft(font, pathLabel, width - pathX - 20), 130);
const pathX = titleX + font.measureText("Files") + HEADER_PATH_GAP;
image.drawText(font, pathX, padding.top, truncateLeft(font, pathLabel, rowsX + rowsWidth - HEADER_INSET_X - pathX), 130);
if (filesViewModeSetting.get() === "list") {
this.paintList(image, font, ctx);
// The header stays put and the rows scroll under it, as far as the
// window's bottom edge: the padding suggested for that edge goes inside
// the scrolled content, so the last row keeps clear of a border there
// and a row cut off for scrolling meets it rather than a blank strip.
const listView = filesViewModeSetting.get() === "list";
const headerEnd = headerBottom(font, padding.top);
// List row boxes start one pixel above the header's bottom edge.
const top = listView ? headerEnd - 1 : headerEnd;
const box = { x: rowsX, y: top, width: rowsWidth, height: Math.max(0, height - top), padTop: 0, padBottom: padding.bottom };
if (listView) {
this.listMenu.setItems(this.flatRows());
this.listMenu.paint(image, box, ctx.stack.isFocused());
} else {
const headerH = headerHeight(font);
this.grid.paint(image, { x: 0, y: headerH, width, height: height - headerH - 6 }, ctx.stack.isFocused());
this.grid.paint(image, box, ctx.stack.isFocused());
}
return image;
}
private paintList(image: GrayImage, font: UiFont, ctx: LayerContext): void {
const { width, height } = ctx.stack.getBaseSize();
const headerH = headerHeight(font);
this.listMenu.setItems(this.flatRows());
// Row boxes start one pixel above the header's bottom edge.
this.listMenu.paint(
image,
{ x: LIST_X - LIST_HIGHLIGHT_PAD, y: headerH - 1, width: width - 2 * LIST_X + 2 * LIST_HIGHLIGHT_PAD, height: height - headerH - 4 },
ctx.stack.isFocused(),
);
}
private drawListRow({ image, item, x, y, width, height, selected }: MenuDrawArgs<BrowserItem>): void {
const font = getDefaultSmallFont();
const label = truncateText(font, item.label, width - 2 * LIST_HIGHLIGHT_PAD);
+19 -16
View File
@@ -5,10 +5,8 @@ import { canLoadFontFile, fontFileDisplayName, fontFileMetrics, renderFontFileTe
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, gestureHints, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
const MARGIN_X = 18;
const TITLE_Y = 8;
const BODY_TOP = 26;
const FOOTER_MARGIN = 20;
/** From the title's top to the first sample's. */
const TITLE_BAND = 18;
const SAMPLE_GAP = 4;
const SIZES = [8,9,10,11, 12, 13, 14, 16, 18, 20, 24, 28, 32, 40, 48] as const;
@@ -48,36 +46,41 @@ export class FontPreviewerLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const out = new GrayImage(width, height, 0);
const size = SIZES[this.sizeIndex]!;
const gamma = GAMMAS[this.gammaIndex]!;
// Everything keeps inside the padding suggested for the window's edges:
// the title line at the top, the samples across the width, the hint
// line at the bottom.
const left = padding.left;
const bodyWidth = Math.max(0, width - padding.left - padding.right);
const bodyTop = padding.top + TITLE_BAND;
const status = `${size}px γ ${gamma.toFixed(1)}`;
const statusWidth = font.measureText(status);
const title = truncateText(font, this.getDisplayName(), width - 2 * MARGIN_X - statusWidth - 12);
out.drawText(font, MARGIN_X, TITLE_Y, title, 220);
out.drawText(font, width - MARGIN_X - statusWidth, TITLE_Y, status, 150);
const title = truncateText(font, this.getDisplayName(), bodyWidth - statusWidth - 12);
out.drawText(font, left, padding.top, title, 220);
out.drawText(font, left + bodyWidth - statusWidth, padding.top, status, 150);
if (this.loadable === null) {
this.loadable = canLoadFontFile(this.path);
}
const footerY = height - FOOTER_MARGIN;
const footerY = height - padding.bottom - font.lineHeight;
if (!this.loadable) {
out.drawText(font, MARGIN_X, BODY_TOP + 16, "(could not load font)", 160);
out.drawText(font, MARGIN_X, footerY, gestureHints([[GESTURE_DOUBLE_CLICK, "back"]]), 110);
out.drawText(font, left, bodyTop + 16, "(could not load font)", 160);
out.drawText(font, left, footerY, gestureHints([[GESTURE_DOUBLE_CLICK, "back"]]), 110);
return out;
}
const bodyWidth = width - 2 * MARGIN_X;
let y = BODY_TOP;
let y = bodyTop;
for (const [id, text] of [
["pangram", PANGRAM],
["charset", CHARSET],
] as const) {
const line = this.getCached(id, () => renderFontFileText(this.path, text, size, gamma));
if (!line) continue;
out.bitBlt(line, MARGIN_X, y, { width: bodyWidth });
out.bitBlt(line, left, y, { width: bodyWidth });
y += line.height + SAMPLE_GAP;
}
@@ -97,13 +100,13 @@ export class FontPreviewerLayer implements Layer {
}),
);
if (paragraph) {
out.bitBlt(paragraph, MARGIN_X, y + SAMPLE_GAP);
out.bitBlt(paragraph, left, y + SAMPLE_GAP);
}
}
out.drawText(
font,
MARGIN_X,
left,
footerY,
gestureHints([
[GESTURE_SCROLL, "size"],
+21 -13
View File
@@ -5,9 +5,9 @@ import { loadImageFileAsGray, PHOTO_TONE } from "../../native/image-files";
import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
const MARGIN_X = 18;
const TITLE_Y = 8;
const BODY_TOP = 24;
/** From the title's top to the image area's. */
const TITLE_BAND = 16;
/** How far the image area keeps from the window's sides and bottom. */
const BODY_MARGIN = 2;
/**
@@ -19,7 +19,8 @@ const BODY_MARGIN = 2;
*/
export class ImageViewerLayer implements Layer {
private image: GrayImage | null = null;
private loadAttempted = false;
/** The image area ("WxH") the file was last decoded to fit; null before the first load. */
private fittedTo: string | null = null;
constructor(
private readonly path: string,
@@ -28,24 +29,31 @@ export class ImageViewerLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const out = new GrayImage(width, height, 0);
out.drawText(font, MARGIN_X, TITLE_Y, truncateText(font, this.title, width - 2 * MARGIN_X), 220);
// The title line keeps inside the padding suggested for the window's
// edges; the image fills the rest of the window whatever its edges touch.
out.drawText(font, padding.left, padding.top, truncateText(font, this.title, width - padding.left - padding.right), 220);
const bodyHeight = height - BODY_TOP - BODY_MARGIN;
if (!this.loadAttempted) {
this.loadAttempted = true;
this.image = loadImageFileAsGray(this.path, width - 2 * BODY_MARGIN, bodyHeight, PHOTO_TONE);
const bodyTop = padding.top + TITLE_BAND;
const bodyWidth = width - 2 * BODY_MARGIN;
const bodyHeight = height - bodyTop - BODY_MARGIN;
// The area moves with the window's size and its top padding, so the
// file is decoded again whenever it changes rather than once.
const fit = `${bodyWidth}x${bodyHeight}`;
if (this.fittedTo !== fit) {
this.fittedTo = fit;
this.image = loadImageFileAsGray(this.path, bodyWidth, bodyHeight, PHOTO_TONE);
}
if (!this.image) {
out.drawText(font, MARGIN_X, BODY_TOP + 16, "(could not load image)", 160);
out.drawText(font, MARGIN_X, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110);
out.drawText(font, padding.left, bodyTop + 16, "(could not load image)", 160);
out.drawText(font, padding.left, height - padding.bottom - font.lineHeight, `${GESTURE_DOUBLE_CLICK} back`, 110);
return out;
}
out.bitBlt(
this.image,
Math.round((width - this.image.width) / 2),
BODY_TOP + Math.round((bodyHeight - this.image.height) / 2),
bodyTop + Math.round((bodyHeight - this.image.height) / 2),
);
return out;
}
+23 -18
View File
@@ -5,11 +5,9 @@ import { GrayImage, type UiFont } from "../../graphics/image";
import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
const MARGIN_X = 18;
const TITLE_Y = 16;
const BODY_X = 18;
const BODY_Y = 44;
const FOOTER_MARGIN = 36;
/** The title: how far right of the body's column, and from its top to the first body line's. */
const TITLE_INSET_X = 4;
const TITLE_BAND = 28;
/** Line step for a bitmap face (the 12px font plus leading, as before). */
const BDF_LINE_STEP = 14;
@@ -24,8 +22,11 @@ function lineStepOf(font: UiFont): number {
}
/**
* Paged text viewer for a document. Sized to its hosting stack (a Files
* document window, or pushed over the file browser for view-in-place).
* Paged text viewer for a document: a title line, the page's lines, and a
* page-number line, all inside the padding suggested for the window's edges
* (the title and page number stay put, so the lines page between them).
* Sized to its hosting stack (a Files document window, or pushed over the
* file browser for view-in-place).
*/
export class TextViewerLayer implements Layer {
private lines: string[] | null = null;
@@ -42,20 +43,23 @@ export class TextViewerLayer implements Layer {
paint(ctx: LayerContext): GrayImage {
const font = getViewerFont();
const lineStep = lineStepOf(font);
const { width, height } = ctx.stack.getBaseSize();
const { width, height, padding } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const footerY = height - FOOTER_MARGIN;
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / lineStep));
image.drawText(font, MARGIN_X + 4, TITLE_Y, truncateText(font, this.title, width - 2 * MARGIN_X - 8), 220);
const bodyX = padding.left;
const bodyWidth = Math.max(0, width - padding.left - padding.right);
const bodyY = padding.top + TITLE_BAND;
const footerY = height - padding.bottom - font.lineHeight;
this.bodyLineCount = Math.max(1, Math.floor((footerY - bodyY) / lineStep));
image.drawText(font, bodyX + TITLE_INSET_X, padding.top, truncateText(font, this.title, bodyWidth - 2 * TITLE_INSET_X), 220);
const lines = this.getLines(font, width);
const lines = this.getLines(font, bodyWidth);
const visibleLines = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount);
for (let index = 0; index < visibleLines.length; index++) {
image.drawText(font, BODY_X, BODY_Y + index * lineStep, visibleLines[index]!, 230);
image.drawText(font, bodyX, bodyY + index * lineStep, visibleLines[index]!, 230);
}
const currentPage = Math.floor(this.firstLine / this.pageStep()) + 1;
image.drawText(font, BODY_X, footerY, `Page ${currentPage}/${this.totalPageCount(lines.length)}`, 110);
image.drawText(font, bodyX, footerY, `Page ${currentPage}/${this.totalPageCount(lines.length)}`, 110);
return image;
}
@@ -89,14 +93,15 @@ export class TextViewerLayer implements Layer {
this.firstLine = Math.max(0, Math.min(maxFirstLine, this.firstLine + delta));
}
private getLines(font: UiFont, width: number): string[] {
if (this.lines === null || this.wrappedForWidth !== width || this.wrappedWithFont !== font.fingerprintId) {
/** The document wrapped to the body column's width; cached per width and font. */
private getLines(font: UiFont, bodyWidth: number): string[] {
if (this.lines === null || this.wrappedForWidth !== bodyWidth || this.wrappedWithFont !== font.fingerprintId) {
const normalized = this.documentText.replace(/\t/g, " ").replace(/\r/g, "");
this.lines = wrapText(font, normalized, width - BODY_X - 12, {
this.lines = wrapText(font, normalized, bodyWidth, {
preserveLeadingWhitespace: true,
breakLongWords: true,
});
this.wrappedForWidth = width;
this.wrappedForWidth = bodyWidth;
this.wrappedWithFont = font.fingerprintId;
}
return this.lines;
+24 -14
View File
@@ -53,9 +53,11 @@ export const videoMonochromeSetting = new ConfigSettingBoolean({
/** How far one ring scroll seeks. */
const SEEK_STEP_MS = 10_000;
const MARGIN_X = 18;
const TITLE_Y = 10;
/** The settings panel's rows: at most this wide, their text this far inside their selection box. */
const PANEL_WIDTH = 340;
const PANEL_ROW_TEXT_INSET = 10;
/** The panel's title: how far below the window's top padding. */
const TITLE_OFFSET_Y = 2;
/**
* One opened video: its probe result, the native player, and the window
@@ -202,7 +204,9 @@ type PanelRow = { kind: "size" } | { kind: "audio" } | { kind: "monochrome" } |
/**
* The pre-play settings panel (the window's root): picture size, audio and
* monochrome, all remembered for the next video, then Play (or Resume plus
* Play from start once a position is kept).
* Play from start once a position is kept). The rows' selection boxes start
* at the padding suggested for the window's left edge, and the title and
* the lines under it line up with the rows' text.
*/
class VideoSettingsLayer implements Layer {
private readonly menu = new Menu<PanelRow>({
@@ -224,11 +228,16 @@ class VideoSettingsLayer 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);
image.drawText(font, MARGIN_X, TITLE_Y, truncateText(font, this.session.title, width - 2 * MARGIN_X), 220);
const rowsX = padding.left;
const available = Math.max(0, width - padding.left - padding.right);
const textX = rowsX + PANEL_ROW_TEXT_INSET;
const textWidth = available - 2 * PANEL_ROW_TEXT_INSET;
const titleY = padding.top + TITLE_OFFSET_Y;
image.drawText(font, textX, titleY, truncateText(font, this.session.title, textWidth), 220);
const step = lineStep(font);
let y = TITLE_Y + step;
let y = titleY + step;
const info = this.session.info;
const errors: string[] = [];
@@ -236,12 +245,12 @@ class VideoSettingsLayer implements Layer {
if (this.session.error) errors.push(`Playback stopped: ${this.session.error}`);
if (info) {
const facts = [`${info.width}x${info.height}`, formatMediaTime(info.durationMs), info.hasAudio ? "sound" : "no sound"];
image.drawText(font, MARGIN_X, y, facts.join(" · "), 130);
image.drawText(font, textX, y, facts.join(" · "), 130);
y += step;
}
for (const error of errors) {
for (const line of wrapText(font, error, width - 2 * MARGIN_X, { breakLongWords: true }).slice(0, 3)) {
image.drawText(font, MARGIN_X, y, line, 200);
for (const line of wrapText(font, error, textWidth, { breakLongWords: true }).slice(0, 3)) {
image.drawText(font, textX, y, line, 200);
y += step;
}
}
@@ -253,9 +262,10 @@ class VideoSettingsLayer implements Layer {
// Land on Resume/Play by default: the settings usually stay as they were.
const playIndex = rows.findIndex((row) => row.kind === "play");
this.menu.setItems(rows, index >= 0 ? index : playIndex >= 0 ? playIndex : undefined);
const panelWidth = Math.min(PANEL_WIDTH, width - 2 * (MARGIN_X - 6));
this.menu.paint(image, { x: MARGIN_X - 6, y, width: panelWidth, height: Math.max(0, height - y - 4) },
ctx.stack.isFocused());
// The rows scroll under the fixed lines above, as far as the window's
// bottom edge, with the padding suggested for that edge inside the list.
this.menu.paint(image, { x: rowsX, y, width: Math.min(PANEL_WIDTH, available), height: Math.max(0, height - y),
padTop: 0, padBottom: padding.bottom }, ctx.stack.isFocused());
return image;
}
@@ -294,8 +304,8 @@ class VideoSettingsLayer implements Layer {
private drawRow({ image, item, x, y, width, selected }: MenuDrawArgs<PanelRow>): void {
const font = getDefaultSmallFont();
const textX = x + 10;
const textWidth = width - 20;
const textX = x + PANEL_ROW_TEXT_INSET;
const textWidth = width - 2 * PANEL_ROW_TEXT_INSET;
switch (item.kind) {
case "size": {
const size = videoSizeSetting.get();