gitstack

grindlemire/go-tui code browser

4.8 KB Go 158 lines 2026-06-12 · d0f5774 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// layout.go re-exports layout types from internal/layout.
// Any changes to internal/layout types must be mirrored here.
package tui

import "github.com/grindlemire/go-tui/internal/layout"

// Display specifies the layout mode for an element.
type Display = layout.Display

// Display modes.
const (
	DisplayBlock = layout.DisplayBlock // Block layout: column direction, fills parent width
	DisplayFlex  = layout.DisplayFlex  // Flex layout: explicit direction control
)

// Direction specifies the main axis for laying out children.
type Direction = layout.Direction

// Directions.
const (
	Row    = layout.Row
	Column = layout.Column
)

// Justify specifies how children are distributed along the main axis.
type Justify = layout.Justify

// Justify values.
const (
	JustifyStart        = layout.JustifyStart
	JustifyEnd          = layout.JustifyEnd
	JustifyCenter       = layout.JustifyCenter
	JustifySpaceBetween = layout.JustifySpaceBetween
	JustifySpaceAround  = layout.JustifySpaceAround
	JustifySpaceEvenly  = layout.JustifySpaceEvenly
)

// Align specifies how children are aligned along the cross axis.
type Align = layout.Align

// Align values.
const (
	AlignStart   = layout.AlignStart
	AlignEnd     = layout.AlignEnd
	AlignCenter  = layout.AlignCenter
	AlignStretch = layout.AlignStretch
)

// FlexWrap controls whether flex items wrap to new lines.
type FlexWrap = layout.FlexWrap

// FlexWrap values.
const (
	WrapNone    = layout.WrapNone    // No wrapping (default)
	Wrap        = layout.Wrap        // Wrap to next line
	WrapReverse = layout.WrapReverse // Wrap in reverse cross-axis order
)

// AlignContent controls how flex lines are distributed along the cross axis.
type AlignContent = layout.AlignContent

// AlignContent values.
const (
	ContentStart        = layout.ContentStart        // Pack lines at start
	ContentEnd          = layout.ContentEnd          // Pack lines at end
	ContentCenter       = layout.ContentCenter       // Center lines
	ContentStretch      = layout.ContentStretch      // Stretch lines to fill
	ContentSpaceBetween = layout.ContentSpaceBetween // Even space between lines
	ContentSpaceAround  = layout.ContentSpaceAround  // Even space around lines
)

// Value represents a dimension value (fixed, percent, or auto).
type Value = layout.Value

// LayoutStyle holds the layout properties for a node.
type LayoutStyle = layout.Style

// Rect represents a rectangle with position and dimensions.
type Rect = layout.Rect

// Edges represents spacing on four sides (top, right, bottom, left).
type Edges = layout.Edges

// Size represents a width/height pair.
type Size = layout.Size

// Point represents an x/y coordinate.
type Point = layout.Point

// LayoutResult holds the computed layout for a node.
type LayoutResult = layout.Layout

// Layoutable is the interface that nodes must implement for layout calculation.
type Layoutable = layout.Layoutable

// Fixed creates a Value with a fixed character count.
func Fixed(n int) Value {
	return layout.Fixed(n)
}

// Percent creates a Value representing a percentage of available space.
func Percent(p float64) Value {
	return layout.Percent(p)
}

// Auto creates a Value that sizes to content.
func Auto() Value {
	return layout.Auto()
}

// DefaultLayoutStyle returns a Style with default values.
func DefaultLayoutStyle() LayoutStyle {
	return layout.DefaultStyle()
}

// NewRect creates a new Rect with the given position and dimensions.
func NewRect(x, y, width, height int) Rect {
	return layout.NewRect(x, y, width, height)
}

// EdgeAll creates Edges with the same value on all sides.
func EdgeAll(n int) Edges {
	return layout.EdgeAll(n)
}

// EdgeSymmetric creates Edges with vertical (top/bottom) and horizontal (left/right) values.
func EdgeSymmetric(v, h int) Edges {
	return layout.EdgeSymmetric(v, h)
}

// EdgeTRBL creates Edges following CSS order: Top, Right, Bottom, Left.
func EdgeTRBL(t, r, b, l int) Edges {
	return layout.EdgeTRBL(t, r, b, l)
}

// Calculate performs flexbox layout on the given tree.
func Calculate(root Layoutable, availableWidth, availableHeight int) {
	layout.Calculate(root, availableWidth, availableHeight)
}

// TableIntrinsicSize computes the intrinsic size of a table element
// from its column widths and row heights.
func TableIntrinsicSize(table Layoutable) (width, height int) {
	return layout.TableIntrinsicSize(table)
}

// InsetRect returns a new Rect inset by the given amounts on each edge.
// The order follows CSS convention: top, right, bottom, left.
// This is a convenience function that wraps Rect.Inset(Edges).
func InsetRect(r Rect, top, right, bottom, left int) Rect {
	return r.Inset(layout.EdgeTRBL(top, right, bottom, left))
}

// InsetUniform returns a new Rect inset by n on all edges.
// This is a convenience function that wraps Rect.Inset(Edges).
func InsetUniform(r Rect, n int) Rect {
	return r.Inset(layout.EdgeAll(n))
}