layout

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package layout provides a pure-geometry layout engine for the Arena TUI. It computes rectangles for a tree of panes and contains no rendering code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderTree

func RenderTree(root *Node, content map[string]string) string

RenderTree composes the rendered content of each leaf into the layout's shape. content maps a leaf ID to its already-rendered string. Vertical splits stack with JoinVertical(Left); horizontal splits sit side by side with JoinHorizontal(Top). Invisible nodes are skipped. Unlike the geometry files, this rendering layer may depend on lipgloss.

func Solve

func Solve(root *Node, area Rect) map[string]Rect

Solve computes the rectangle for every leaf in the tree rooted at root, laid out within area. Leaf rectangles are keyed by Node.ID. Invisible nodes are omitted. Solve is a pure function: same inputs always yield the same map.

Types

type Direction

type Direction int

Direction is the axis along which a split arranges its children.

const (
	// Vertical stacks children top to bottom.
	Vertical Direction = iota
	// Horizontal places children left to right.
	Horizontal
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns a layout tree and its current area, and is the single place that mutates the layout at runtime (resize, collapse). Each mutation reflows once, so consumers read the resulting rects via Rect. Construct page trees with the builders and hand the root to NewManager.

func NewManager

func NewManager(root *Node) *Manager

NewManager returns a Manager for the given layout tree.

func (*Manager) Grow

func (m *Manager) Grow(id string, delta int)

Grow adjusts the flex weight of the leaf with the given ID by delta (weight is clamped to a minimum of 1) and reflows. Growing a fixed-size leaf has no effect. Unknown IDs are ignored.

func (*Manager) Rect

func (m *Manager) Rect(id string) (Rect, bool)

Rect returns the computed rectangle for the leaf with the given ID. The second result is false when the leaf is collapsed (absent from the layout).

func (*Manager) Root

func (m *Manager) Root() *Node

Root returns the layout tree, for composition via RenderTree.

func (*Manager) SetArea

func (m *Manager) SetArea(r Rect)

SetArea sets the available area and reflows.

func (*Manager) ToggleCollapse

func (m *Manager) ToggleCollapse(id string)

ToggleCollapse flips the visibility of the leaf with the given ID and reflows. Unknown IDs are ignored.

type Node

type Node struct {
	ID       string
	Dir      Direction
	Children []*Node

	Mode    SizeMode
	Size    int
	Weight  int
	MinW    int
	MinH    int
	Visible bool
}

Node is one element of a layout tree. A node is either a leaf (ID set, no Children) or a split (Children set). Construct nodes with the builders rather than literals so defaults (Visible, Weight) are set correctly.

func Fixed

func Fixed(size int, child *Node) *Node

Fixed makes child claim exactly size cells along its parent's axis.

func Flex

func Flex(weight int, child *Node) *Node

Flex makes child share leftover space proportional to weight.

func HSplit

func HSplit(children ...*Node) *Node

HSplit returns a horizontal split whose children sit left to right.

func Optional

func Optional(visible bool, child *Node) *Node

Optional includes child in the layout only when visible is true.

func Pane

func Pane(id string, opts ...Option) *Node

Pane returns a leaf node. It is flex with weight 1 and visible by default.

func VSplit

func VSplit(children ...*Node) *Node

VSplit returns a vertical split whose children stack top to bottom.

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

IsLeaf reports whether n has no children.

type Option

type Option func(*Node)

Option configures a Node during construction.

func Min

func Min(w, h int) Option

Min sets the minimum width and height in cells.

func Weight

func Weight(w int) Option

Weight sets the flex weight (share of leftover space).

type Rect

type Rect struct {
	X, Y, W, H int
}

Rect is a position and size in terminal cells.

type SizeMode

type SizeMode int

SizeMode controls how a node claims space within its parent split.

const (
	// ModeFlex shares leftover space proportional to Weight.
	ModeFlex SizeMode = iota
	// ModeFixed claims exactly Size cells along the parent's axis.
	ModeFixed
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL