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>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
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;
|
||
}
|