Skip to content

Layout

ILayout is a recursive splitter. Each node is either a leaf (wrapping an IRenderable) or an internal node split by rows or columns. Named regions let you reach into the tree later and swap content via Update.

When to use

  • Dashboards with header / sidebar / main / footer regions.
  • Any layout where multiple panels need fixed sizes or ratios.
  • Anywhere you'd reach for a TUI window manager.

For simpler horizontal/vertical stacks without sized regions, use Columns / Rows. For aligned columnar data, use Grid.

Basic usage

pascal
var
  root, hdr, body, side, main, foot : ILayout;
begin
  root := Widgets.Layout('root');
  hdr  := Widgets.Layout('header').WithSize(3);
  side := Widgets.Layout('side').WithRatio(1);
  main := Widgets.Layout('main').WithRatio(2);
  body := Widgets.Layout('body');
  body.SplitColumns([side, main]);
  foot := Widgets.Layout('footer').WithSize(1);
  root.SplitRows([hdr, body, foot]);

  hdr.Update(Widgets.Markup('[bold yellow]Dashboard[/]'));
  side.Update(Widgets.Markup('sidebar'));
  main.Update(Widgets.Markup('main content'));
  foot.Update(Widgets.Markup('[grey]press q to quit[/]'));

  root.WithHeight(24);
  AnsiConsole.Write(root);
end;

Size strategies

A node can be fixed, ratio'd, or default:

MethodEffect
WithSize(value)Exactly value cells (in the splitting axis).
WithRatio(value)Take value/total-ratio of the leftover space.
WithMinimumSize(value)Floor on the size — the node won't shrink below this.
WithVisible(value)When False the region collapses to zero size.
WithHeight(value)Used at the root to set the overall layout height.

If a child has neither a fixed size nor a ratio, it's treated as ratio 1.

Splits

MethodEffect
SplitRows(children)Split this node vertically into the given children.
SplitColumns(children)Split this node horizontally.
Update(renderable)Set the leaf content. Replaces previous content.
FindByName(name) : ILayoutLocate a descendant by its name string.

Updating a region

Once built, you can change a region's content with Update:

pascal
side := root.FindByName('side');
side.Update(Widgets.Panel(newContent));
AnsiConsole.Write(root);

This is the typical pattern when combined with Live display to redraw a dashboard in place.

Configuration recap

pascal
hdr  := Widgets.Layout('header').WithSize(3).WithMinimumSize(3);
side := Widgets.Layout('side').WithRatio(1).WithMinimumSize(20);
main := Widgets.Layout('main').WithRatio(2);
foot := Widgets.Layout('footer').WithSize(1).WithVisible(showFooter);

API reference

See also

Released under the MIT License.