UNPKG

@teaui/core

Version:

A high-level terminal UI library for Node

40 lines 1.26 kB
import { Container } from '../Container.js'; import { Size } from '../geometry.js'; /** * A container that reports its available size via onLayout callback. Defaults to * filling all available space (width='fill', height='fill') unless explicit * dimensions are provided. * * Useful for: * - Measuring available space before deciding what to render * - Virtualized lists that need viewport height to calculate visible items * - Responsive layouts that change based on available space */ export class Geometry extends Container { #onLayout; #prevSize = Size.zero; constructor({ onLayout, ...props }) { super(props); this.#onLayout = onLayout; } update({ onLayout, ...props }) { this.#onLayout = onLayout; super.update(props); } naturalSize(available) { return available; } render(viewport) { if (viewport.isEmpty) { return super.render(viewport); } const size = viewport.contentSize; if (size.width !== this.#prevSize.width || size.height !== this.#prevSize.height) { this.#prevSize = size; this.#onLayout?.(size); } super.render(viewport); } } //# sourceMappingURL=Geometry.js.map