Skip to content

@jsvision/ui / spacer

Function: spacer()

spacer(arg?): View

Defined in: ui/src/view/dsl/flex.ts:264

Insert an empty spacer between children. With a numeric weight (default 1) it is flexible — it absorbs leftover space, pushing later children toward the far edge; with { fixed: n } it is a hard, exact n-cell gap.

Parameters

arg?

number | { fixed: number; }

A flex weight (default 1), or { fixed: n } for an exact n-cell gap.

Returns

View

A fresh invisible view with the requested size, ready to drop into a col/row.

Example

ts
import { View, row, spacer, 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); }
}

// Push `help` to the right edge; keep a hard 2-cell gap before `cancel`.
const ok = new Panel('OK');
const cancel = new Panel('Cancel');
const help = new Panel('Help');
const bar = row(ok, spacer({ fixed: 2 }), cancel, spacer(), help);