Skip to content

Layouts

A LayoutManager is attached to a container Component and positions its children on each doLayout() call. All managers extend LayoutManager, which handles fill / anchor constraint resolution.

Available layouts

ManagerDescription
AbsoluteNo-op — children are positioned manually
AccordionCollapsible vertical sections, one or many open at a time
BorderFive-region layout: north, south, east, west, center
CardStacked layers — one visible at a time
ColumnHorizontal sequence with gap control
FitPlaces one child inside the container — stretch to fill (default) or centre at preferred size via FillType.NONE
GridTwo-dimensional grid
HBoxHorizontal stack with configurable spacing
RowVertical sequence with gap control
SplitTwo panes with a draggable resize gutter
TabTabbed interface with a button toolbar
VBoxVertical stack with configurable spacing

Attach a layout

typescript
import { Component } from '@jimka/typescript-ui/core';
import { Border } from '@jimka/typescript-ui/primitive';
const panel = Component({
    layoutManager: Border(),
    components: [
        { component: header,  constraints: { region: 'north'  } },
        { component: content, constraints: { region: 'center' } },
        { component: footer,  constraints: { region: 'south'  } }
    ]
});

The second argument to addComponent (or the constraints field of a ConstrainedComponent pair) is the layout's constraint — its shape is specific to the manager. Border takes a region; Grid takes a row + column; Absolute ignores it.

The same can be expressed imperatively if you need refs along the way:

typescript
const panel = Component();
panel.setLayoutManager(Border());
panel.addComponents(
    { component: header,  constraints: { region: 'north'  } },
    { component: content, constraints: { region: 'center' } },
    { component: footer,  constraints: { region: 'south'  } }
);

When doLayout runs

Layout runs in three situations:

  1. Initial render — when a component first becomes visible.
  2. Viewport resizeBody listens for window.resize and re-runs layout from the root.
  3. Explicit call — you call parent.doLayout() after changing a child's preferred size or adding / removing children.

There is no automatic re-layout on size changes. If you change a child's preferred size, you must trigger a layout pass on its parent (or an ancestor) for the change to take effect.

See also