diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-05 19:42:46 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-07 16:02:18 -0500 |
| commit | 0f1c3ef1871f311d79f8274585bdb2925152f576 (patch) | |
| tree | b1b281eebc8dd2a8f07ddaad698515cfbe25b517 /tui | |
| parent | 2d54af98b89d5f7ff43bc0d887e42bde7ef87dbc (diff) | |
limit size of command window preview
Diffstat (limited to 'tui')
| -rw-r--r-- | tui/layout.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tui/layout.go b/tui/layout.go index f195048..4caa3a6 100644 --- a/tui/layout.go +++ b/tui/layout.go @@ -8,18 +8,21 @@ import ( type Box struct { id string Width, Height BoxSize + MaxWidth, MaxHeight BoxSize Dir Direction Overflow bool Style *Style Margins [4]int Scroll *ScrollState NoWrap bool + IsOverflow *bool text []textRun computedLines [][]textRun children []*Box computedPosition int computedSize [2]int computedRect rect + isOverflow bool } type BoxSize int @@ -97,6 +100,10 @@ func Push(id string, box Box) { box.computedSize[axis] = int(value) } } + b := layout.back[id] + if box.IsOverflow != nil { + *box.IsOverflow = b != nil && b.isOverflow + } } func Text(text string, style *Style) { @@ -117,14 +124,22 @@ func (b Box) axes() [2]BoxSize { return [2]BoxSize {b.Width, b.Height} } +func (b Box) maxAxes() [2]BoxSize { + return [2]BoxSize {b.MaxWidth, b.MaxHeight} +} + func (b *Box) marginsSize(axis int) int { return b.Margins[axis * 2] + b.Margins[axis * 2 + 1] } func (b *Box) computeFillSizes(axis int) { for _, c := range b.children { + size := b.computedSize[axis] if c.axes()[axis] == Fill { - c.computedSize[axis] = b.computedSize[axis] + c.computedSize[axis] = size + } + if c.maxAxes()[axis] == Fill { + c.computedSize[axis] = min(c.computedSize[axis], size) } c.computeFillSizes(axis) } @@ -143,11 +158,24 @@ func (b *Box) computeChildrenSizes(axis int) { if b.axes()[axis] == Children { b.computedSize[axis] = size } + if b.maxAxes()[axis] == Children { + b.computedSize[axis] = min(b.computedSize[axis], size) + } + if b.maxAxes()[axis] > 0 { + b.computedSize[axis] = min( + b.computedSize[axis], int(b.maxAxes()[axis]) + b.marginsSize(axis), + ) + } } func (b *Box) solve(axis int) { switch { case b.Dir.axis() == axis && b.Overflow: + size := b.marginsSize(axis) + for _, c := range b.children { + size += c.computedSize[axis] + } + b.isOverflow = size > b.computedSize[axis] break case b.Dir.axis() == axis: size := b.marginsSize(axis) |
