gitstack

grindlemire/go-tui code browser

1.4 KB Go 38 lines 2026-02-26 · 89e16ba raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package layout

// Layoutable is the interface for anything that can participate in layout calculation.
// The layout engine works entirely with this interface, enabling custom implementations.
type Layoutable interface {
	// LayoutStyle returns the layout style properties for this element.
	LayoutStyle() Style

	// LayoutChildren returns the children to be laid out.
	LayoutChildren() []Layoutable

	// SetLayout is called by the layout engine to store computed layout.
	SetLayout(Layout)

	// GetLayout returns the last computed layout.
	GetLayout() Layout

	// IsDirty returns whether this element needs layout recalculation.
	IsDirty() bool

	// SetDirty marks this element as needing recalculation.
	SetDirty(dirty bool)

	// IntrinsicSize returns the natural content-based dimensions of this element.
	// For leaf elements (like text), this returns the size needed to display content.
	// For containers, this returns the computed size based on children.
	// The layout engine uses this as the base size for Auto-sized elements.
	IntrinsicSize() (width, height int)

	// Tag returns the element tag name (e.g., "table", "tr", "td", "th").
	// Returns empty string for elements without a tag.
	Tag() string

	// HeightForWidth returns the height this element needs given an assigned width.
	// For text elements with wrapping, this computes wrapped line count.
	// For elements without text wrapping, returns the intrinsic height.
	HeightForWidth(width int) int
}