Files
feuerwerk/src/ui/UIContext.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

32 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Application, Container } from 'pixi.js';
import { FocusManager } from './FocusManager';
import { KeyboardBridge } from './KeyboardBridge';
/** Services shared by all widgets, created once by `initUI()`. */
export interface UIContext {
app: Application;
focus: FocusManager;
keyboard: KeyboardBridge;
/** Top-most container for popups, menus and drag previews. */
overlay: Container;
}
let context: UIContext | null = null;
/** `root` is where Tab cycling searches; `overlay` must be drawn above it. */
export function initUI(app: Application, root: Container, overlay: Container): UIContext {
context = { app, focus: new FocusManager(root), keyboard: new KeyboardBridge(), overlay };
// Capture phase on the stage runs before any widget handler: a press outside the focused
// widget blurs it (committing text edits) before the press can change selection.
app.stage.addEventListener('pointerdown', (e) => context?.focus.blurIfOutside(e.target), { capture: true });
// Clicking the canvas must not steal DOM focus from the keyboard bridge input.
app.canvas.addEventListener('mousedown', (e) => e.preventDefault());
app.canvas.addEventListener('contextmenu', (e) => e.preventDefault());
return context;
}
export function ui(): UIContext {
if (!context) throw new Error('UI not initialised – call initUI() first');
return context;
}