@jsvision/ui / center
Function: center()
center<
V>(view,width,height):V
Defined in: ui/src/view/dsl/absolute.ts:119
Center a fixed-size view in its parent as an out-of-flow overlay, re-centering on resize, and return the same view — standalone, no stack() wrapper. Sets an absolute origin rect plus the View.centered flag, which the engine re-solves lag-free in the reflow pass; every other layout prop is merge-preserved.
Distinct from the stack-layer centered() tag: centered() only takes effect inside a stack(); center() acts directly on any view.
Type Parameters
V
V extends View
Parameters
view
V
The view to center.
width
number
Fixed width in cells.
height
number
Fixed height in cells.
Returns
V
The same view, for inline chaining.
Example
ts
import { View, center, type DrawContext } from '@jsvision/ui';
class Panel extends View {
constructor(private readonly label: string) { super(); }
draw(ctx: DrawContext) { ctx.fill(' ', ctx.color('window')); ctx.text(1, 0, this.label); }
}
// A 40×12 dialog centered in its parent, staying centered as the parent resizes.
const confirmDialog = new Panel('Confirm');
center(confirmDialog, 40, 12);