Files
feuerwerk/src/ui/draw.ts
T
rootandClaude Opus 5 4d84231b9f Trim needless comments and fix the picker width
Remove comments that only restate the code, keeping the section banners
and the notes that carry a reason, a measured fact or an external
contract.

ButtonOptions.width claimed to be a fixed width but only set minWidth,
so the Graph and Texture pickers grew with the name they showed. It is
now what it promises, with a separate minWidth for the buttons that have
two forms. Narrow buttons shrink their padding, otherwise a 24px icon
button had 8px left for its glyph and truncate dropped it entirely.

__gm.labelsDropped() guards that class: the overflow guard only saw text
that was too wide, never a label truncated to nothing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 15:52:05 +02:00

53 lines
1.9 KiB
TypeScript

import type { Graphics } from 'pixi.js';
import { Theme } from './Theme';
export interface ControlBoxOptions {
fill: number;
border: number;
radius?: number;
x?: number;
y?: number;
}
/**
* The shared look of every control. The stroke is inset by half a pixel so it lands on whole
* device pixels and stays crisp instead of blurring over two.
*/
export function drawControlBox(g: Graphics, w: number, h: number, options: ControlBoxOptions): void {
const { fill, border, radius = Theme.radius, x = 0, y = 0 } = options;
g.roundRect(x, y, w, h, radius).fill(fill);
g.roundRect(x + 0.5, y + 0.5, w - 1, h - 1, radius).stroke({ width: 1, color: border });
}
export interface GridOptions {
/** Where the origin of the drawn space sits on screen, in the same pixels as `w`/`h`. */
originX: number;
originY: number;
/** Spacing in screen pixels (world/graph step times zoom). */
step: number;
w: number;
h: number;
alpha: number;
/** Alpha of the two lines through the origin; omitted = no axes. */
axisAlpha?: number;
}
/**
* White at a low alpha rather than a fixed colour, so the grid reads on whatever background the
* scene sets. `g` is cleared by the caller.
*/
export function drawGrid(g: Graphics, options: GridOptions): void {
const { originX, originY, step, w, h, alpha, axisAlpha } = options;
const startX = ((originX % step) + step) % step;
const startY = ((originY % step) + step) % step;
for (let x = startX; x < w; x += step) g.moveTo(x, 0).lineTo(x, h);
for (let y = startY; y < h; y += step) g.moveTo(0, y).lineTo(w, y);
g.stroke({ width: 1, color: GRID_COLOR, alpha });
if (axisAlpha === undefined) return;
const axis = { width: 1, color: GRID_COLOR, alpha: axisAlpha };
if (originX >= 0 && originX <= w) g.moveTo(originX, 0).lineTo(originX, h).stroke(axis);
if (originY >= 0 && originY <= h) g.moveTo(0, originY).lineTo(w, originY).stroke(axis);
}
const GRID_COLOR = 0xffffff;