Files
faceclaw/app/apps/terminal/hub-header.ts
T
James Babcock a02b849200 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.
2026-11-11 15:19:29 -08:00

42 lines
1.7 KiB
TypeScript

import { wrapText, type WrapFont } from '../../graphics/textwrap';
import type { Edges } from '../../ui/viewport';
/**
* Where the hub's title line (and a wrapped status block under it) starts,
* right of the window's left padding: the list's selection boxes start at
* the padding and unindented row text sits this far inside its box, so the
* title lines up with it.
*/
export const HUB_TITLE_INSET_X = 6;
/** The title line's top, below the window's top padding. */
const HUB_TITLE_OFFSET_Y = 2;
/** Between the title and a status that shares its row. */
const HUB_STATUS_GAP = 16;
/** Between the header's last line and the list's first text line. */
const HUB_LIST_GAP = 6;
/**
* Lay the hub's header out in a window `width` wide with the suggested
* `padding` (viewport.ts): the title inside the top and left padding, the
* status ending at the right padding. Keep short status on the title row;
* give long errors their full width.
*/
export function layoutHubHeader(
font: WrapFont,
title: string,
status: string,
viewport: { width: number; padding: Edges<number> },
step: number,
) {
const { width, padding } = viewport;
const titleX = padding.left + HUB_TITLE_INSET_X;
const titleY = padding.top + HUB_TITLE_OFFSET_Y;
const right = width - padding.right;
const inlineX = titleX + font.measureText(title) + HUB_STATUS_GAP;
const inline = !/[\r\n]/.test(status) && font.measureText(status) <= Math.max(0, right - inlineX);
const lines = inline ? [status] : wrapText(font, status, Math.max(1, right - titleX));
const x = inline ? inlineX : titleX;
const y = inline ? titleY : titleY + step;
return { titleX, titleY, x, y, lines, listTop: titleY + HUB_LIST_GAP + step * (inline ? 1 : 1 + lines.length) };
}