Documentation
¶
Overview ¶
Package layout is a tiny declarative engine for composing Bubble Tea view strings. Every layout is a tree of Node; each Node knows how to render itself at a given (width, height). VStack and HStack split their allotment among Fixed- and Flex-sized children; ZStack overlays children.
The point is to remove hand-written "m.h-2" math from callers. You describe what goes where and let the stack engine divide the pixels.
Typical use:
root := layout.VStack(
layout.Fixed(1, layout.RenderFunc(func(w, h int) string { ... })),
layout.Flex(1, body),
layout.Fixed(1, layout.RenderFunc(func(w, h int) string { ... })),
)
return root.Render(termW, termH)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item is a child of VStack or HStack. Construct with Fixed or Flex.
type Node ¶
Node is the unit of layout — something that can render itself at a given outer size. Components participate by being wrapped in RenderFunc (or any adapter that yields a Node).
func Bar ¶
Bar wraps a single-row component (breadcrumb.Model, statusbar.Model, …) as a Node. The height argument to Render is ignored — these components always render one row. Pass a pointer: &m.bc, &m.sb.
func Center ¶
Center renders child at its natural size (given by naturalW/naturalH) padded to the parent's (w, h) with surrounding whitespace. Useful as the overlay layer inside a ZStack.
func Sized ¶
Sized wraps a two-dimensional component (pane.Pane, list.Model, …) as a Node. Pass a pointer: &m.list, &m.body.
func ZStack ¶
ZStack layers overlay on top of base. Both are rendered at the full (w, h). Compositing happens cell-by-cell: cells that are spaces in the overlay pass the base through; non-space cells replace base at that column. Empty overlay rows pass through entirely.
In practice this means a centered modal drawn with Center(...) only blots out the modal's bounding box; pane borders and content to the left and right of the modal stay visible. Wide characters and ANSI styles are handled via x/ansi cell-aware cutting.
type RenderFunc ¶
RenderFunc adapts a render-at-size function into a Node. It is the primary bridge from existing components: close over the component, set its dimensions inside the func, and return its View().