Chapter 10

Layout

PixiFormUI layouts are deliberately small and Flutter-like. Anything with layout(width) and layoutHeight can take part (Layoutable).

Column(items, gap = 16, padding = insets(0))#

Vertical stack. Re-lays out automatically when a child emits resize (e.g. an error message appears). column.add(...items), Column.spacer(height). Hidden children (visible = false) are skipped.

Row(items, gap = 16, breakpoint = 480)#

Equal-width children side by side; stacks vertically below breakpoint px. Use breakpoint = 0 to never stack.

new Column([
  new Row([firstName, lastName], 16, 520),
  email,
  new Row([cancel, save], 12, 0),
], 20, insets(24, 16));

ScrollView(ui, content)#

Clipped viewport with wheel, touch drag with momentum, and a scrollbar. It keeps the keyboard-focused control in view and re-reveals the focused field when the viewport shrinks (mobile keyboard). Methods: setViewport(w, h), scrollTo(y), reveal(container).

FieldGroup(ui, options): titled, optionally collapsible sections#

The canvas equivalent of <fieldset> + <legend>. Create it, add() fields (or rows, labels, nested groups), and put the group in your layout. Grouping is visual and for accessibility only: register the fields with the Form as usual, and they submit with their own flat names.

const contact = new FieldGroup(ui, {
  title: 'Contact',
  description: 'How we reach you.',
  info: 'Shown in a tooltip from the ⓘ icon.',
  collapsible: true,      // header becomes a button with a chevron
  collapsed: false,
  variant: 'outline',     // 'outline' (default) | 'card' | 'plain' (heading + divider)
}).add(new Row([email, phone], 16, 520), address);

form.add(email, phone, address);
column.add(contact);
contact.on('toggle', (expanded: boolean) => { /* … */ });
Member Purpose
add(...items) Append layout items.
expanded, setExpanded(b), toggle() Fold state (non-collapsible groups are always open).
title, description Live-editable header text.
controls() Every control inside, including nested groups.
errorCount Fields inside that currently show an error.
setDisabled(b) Disable or enable every control inside.

Behaviour:

insets(vertical, horizontal = vertical, bottom = vertical, left = horizontal)#

Padding helper in the order top/right/bottom/left, like CSS shorthand.

Custom layout containers#

Implement layout(width) and a layoutHeight getter, emit resize when your height changes, and guard against re-entrancy. Children emit resize while you lay them out:

class Card extends Container {
  private laying = false; private h = 0;
  constructor(private child: Column) { super(); this.addChild(child); child.on('resize', () => !this.laying && this.emit('resize', this)); }
  get layoutHeight() { return this.h; }
  layout(w: number) { this.laying = true; this.child.layout(w - 48); this.laying = false; this.child.position.set(24, 24); this.h = this.child.layoutHeight + 48; }
}