forked from Blendman974/faceclaw
[verified] merge upstream c162c8e6 into all-features
This commit is contained in:
commit
5790e98d27
176 files changed
+5311
-2307
No files matched your search
@@ -7,6 +7,7 @@ import { isMenuItemDisabled, MenuItem, MenuLayer, openModalMenu } from "../menu"
|
||||
import { Menu, drawMenuLabel } from "../menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../metrics";
|
||||
import { shell } from "../shell/shell";
|
||||
import type { Viewport } from "../viewport";
|
||||
|
||||
/**
|
||||
* One left-column entry. `items` are the right-column rows (reusing the shared
|
||||
@@ -29,8 +30,12 @@ export type SettingsSection = {
|
||||
}) => number | void;
|
||||
};
|
||||
|
||||
const PAD = 8;
|
||||
const LEFT_W = 150;
|
||||
/** Between the left column's rows and the divider, and between the divider and the right column's content. */
|
||||
const DIVIDER_GAP_LEFT = 8;
|
||||
const DIVIDER_GAP_RIGHT = 14;
|
||||
/** How far a right-column row's selection box overhangs the column's content on the left. */
|
||||
const RIGHT_ROW_OVERHANG = 2;
|
||||
/** Gap between a row's selection box and the next row. */
|
||||
const ROW_GAP = 2;
|
||||
/** Horizontal inset of row text (and custom row content) from its selection box. */
|
||||
@@ -116,27 +121,27 @@ export class SettingsPanelLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const viewport = ctx.stack.getBaseSize();
|
||||
const { width, height, padding } = viewport;
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const appFocused = ctx.stack.isFocused();
|
||||
const section = this.section();
|
||||
const rightItems = section.items;
|
||||
this.rightMenu.setItems(rightItems);
|
||||
|
||||
const top = PAD;
|
||||
const listBottom = height - PAD;
|
||||
// Fixed content keeps the padding suggested for the window's edges. The
|
||||
// two lists scroll, so they run to the top and bottom edges themselves,
|
||||
// with that padding inside them (before the first row, after the last).
|
||||
const { top, bottom: listBottom, divX, rightX, rightW } = panelColumns(viewport);
|
||||
|
||||
// Left column: section labels.
|
||||
this.leftMenu.paint(image, { x: PAD - 2, y: top, width: LEFT_W, height: listBottom - top },
|
||||
this.leftMenu.paint(image, { x: padding.left, y: 0, width: LEFT_W, height, padTop: padding.top, padBottom: padding.bottom },
|
||||
appFocused && this.focus === "left");
|
||||
|
||||
// Column divider (a light rule, not a full border).
|
||||
const divX = PAD + LEFT_W + 6;
|
||||
image.drawLine(divX, top, divX, listBottom, 40);
|
||||
|
||||
// Right column: the highlighted section's contents.
|
||||
const rightX = divX + 14;
|
||||
const rightW = width - rightX - PAD;
|
||||
let rightTop = top;
|
||||
if (section.renderDetail && !this.detailCrowdsList(section, ctx, font, { x: rightX, y: top, width: rightW, height: listBottom - top })) {
|
||||
const used = section.renderDetail({ image, x: rightX, y: top, width: rightW, height: listBottom - top, ctx });
|
||||
@@ -146,12 +151,20 @@ export class SettingsPanelLayer implements Layer {
|
||||
// Once focus is in the right column, the selected item's extended
|
||||
// description (when it has one) is drawn over the bottom of the pane by
|
||||
// the companion SettingsDescriptionOverlayLayer. The list stops above
|
||||
// that band, so the selected row always stays clear of it.
|
||||
const listHeight = listBottom - this.descriptionHeight(font, rightW) - rightTop;
|
||||
if (listHeight > 0) {
|
||||
// that band, so the selected row always stays clear of it. Under a
|
||||
// detail, and above that band, the list ends short of the window's
|
||||
// edge, where it needs no padding of its own.
|
||||
const description = this.descriptionHeight(font, rightW);
|
||||
const fromEdge = rightTop === top;
|
||||
const listTop = fromEdge ? 0 : rightTop;
|
||||
const listEnd = description ? listBottom - description : height;
|
||||
if (listEnd > rightTop) {
|
||||
this.paintCtx = ctx;
|
||||
try {
|
||||
this.rightMenu.paint(image, { x: rightX - 2, y: rightTop, width: rightW + 2, height: listHeight }, appFocused);
|
||||
this.rightMenu.paint(image, {
|
||||
x: rightX - RIGHT_ROW_OVERHANG, y: listTop, width: rightW + RIGHT_ROW_OVERHANG, height: listEnd - listTop,
|
||||
padTop: fromEdge ? padding.top : 0, padBottom: description ? 0 : padding.bottom,
|
||||
}, appFocused);
|
||||
} finally {
|
||||
this.paintCtx = null;
|
||||
}
|
||||
@@ -204,10 +217,7 @@ export class SettingsPanelLayer implements Layer {
|
||||
*/
|
||||
paintDescriptionOverlay(image: GrayImage, ctx: LayerContext): void {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const listBottom = height - PAD;
|
||||
const rightX = PAD + LEFT_W + 6 + 14;
|
||||
const rightW = width - rightX - PAD;
|
||||
const { bottom: listBottom, rightX, rightW } = panelColumns(ctx.stack.getBaseSize());
|
||||
const lines = this.descriptionLines(font, rightW);
|
||||
if (!lines.length) return;
|
||||
const top = listBottom - (lines.length * lineStep(font) + 10);
|
||||
@@ -275,6 +285,19 @@ export class SettingsPanelLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The panel's fixed geometry in a viewport: the rows fixed content spans
|
||||
* (inside the padding suggested for the top and bottom edges), the divider's
|
||||
* x, and the right column's content span. The left column's rows start at
|
||||
* the left edge's padding; the right column ends at the right edge's.
|
||||
*/
|
||||
function panelColumns(viewport: Viewport): { top: number; bottom: number; divX: number; rightX: number; rightW: number } {
|
||||
const { width, height, padding } = viewport;
|
||||
const divX = padding.left + LEFT_W + DIVIDER_GAP_LEFT;
|
||||
const rightX = divX + DIVIDER_GAP_RIGHT;
|
||||
return { top: padding.top, bottom: height - padding.bottom, divX, rightX, rightW: width - rightX - padding.right };
|
||||
}
|
||||
|
||||
/** Scroll and watch swipe-up/down both move a column's selection. */
|
||||
function scrollEventFor(event: InputEvent): InputEvent | null {
|
||||
if (event.type === "scroll-up" || event.type === "swipe-up") return { ...event, type: "scroll-up" } as InputEvent;
|
||||
|
||||
Reference in new issue
Block a user