layout

package module
v0.0.0-...-309f7a2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSpace

func IsSpace(child any) bool

func RenderString

func RenderString(width, height int, child any) string

RenderString renders the provided child/layout/etc into a string.

func RenderView

func RenderView(view *tea.View, width, height int, child any)

RenderView renders the provided child/layout/etc onto an existing tea.View, including applying a callback to the view to handle mouse events, which will send a downstream LayerMouseMsg to the model.

Types

type Cell

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

Cell represents a cell in a Rows or Columns layout with percentage-based or exact sizing.

func NewCell

func NewCell(child any) *Cell

NewCell creates a new Cell with the specified percentage and child. The percentage is converted from int to float64 for convenience.

func (*Cell) CalculateSize

func (c *Cell) CalculateSize(totalSize int, usedPercent float64, zeroPercentCount int) int

CalculateSize calculates the actual size this cell should occupy based on: - totalSize: the total available size (width for columns, height for rows) - usedPercent: the sum of percentages from all cells with Percent > 0 - zeroPercentCount: the number of cells with Percent == 0

If this cell has Percent > 0, it uses that percentage. If this cell has Percent == 0, it gets an equal share of remaining space.

func (*Cell) CalculatedPercent

func (c *Cell) CalculatedPercent(calculatedSize int, totalSize int) float64

CalculatedPercent calculates the actual percentage this cell occupies after size calculation.

func (*Cell) HidePercent

func (c *Cell) HidePercent(percent float64) *Cell

HidePercent sets the minimum calculated percentage threshold. If the calculated percentage is less than this value, the cell will be hidden.

func (*Cell) HideSize

func (c *Cell) HideSize(hideSize int) *Cell

HideSize sets the minimum calculated size threshold. If the calculated width or height is less than this value, the cell will be hidden.

func (*Cell) Percent

func (c *Cell) Percent(percent float64) *Cell

Percent sets the percentage of available space this cell should occupy (0-1). If 0, the cell will receive an equal share of remaining space after percentage-based and exact-size cells. Setting a percentage unsets any exact size.

func (*Cell) ShouldHide

func (c *Cell) ShouldHide(calculatedSize int, calculatedPerc float64) bool

ShouldHide determines if this cell should be hidden based on HidePerc and HideSize thresholds. It checks both the calculated percentage and calculated size against the thresholds.

func (*Cell) Size

func (c *Cell) Size(size int) *Cell

Size sets the exact size (width for columns, height for rows) this cell should occupy. Setting an exact size unsets any percentage.

type LayerMouseMsg

type LayerMouseMsg struct {
	tea.MouseMsg
	LayerID string
}

type Layout

type Layout interface {
	// Render renders the layout into a [lipgloss.Layer]. The child can use the provided
	// availableWidth and availableHeight to calculate the size of the layout it can
	// consume.
	Render(availableWidth, availableHeight int) *lipgloss.Layer
}

Layout is a generic layout interface. All layouts must implement this interface.

func BottomPadding

func BottomPadding(amount int, child any) Layout

BottomPadding creates a new layout that pads the provided child with the given amount of space on the bottom.

func Center

func Center(child any) Layout

Center creates a new layout that centers the provided children.

func Columns

func Columns(cells ...*Cell) Layout

Columns creates a new horizontal layout with the provided cells, where each cell is sized based on its percentage of available width. Cells are arranged left to right.

func Frame

func Frame(style lipgloss.Style, child any) Layout

Frame creates a new layout which contains the provided child within it, with the free space left over after the style has been applied. Use this for wrapping children in borders, padding, etc.

func Horizontal

func Horizontal(children ...any) Layout

Horizontal creates a new horizontal layout with the provided children.

func LeftPadding

func LeftPadding(amount int, child any) Layout

LeftPadding creates a new layout that pads the provided child with the given amount of space on the left.

func RightPadding

func RightPadding(amount int, child any) Layout

RightPadding creates a new layout that pads the provided child with the given amount of space on the right.

func Rows

func Rows(cells ...*Cell) Layout

Rows creates a new vertical layout with the provided cells, where each cell is sized based on its percentage of available height. Cells are arranged top to bottom.

func Space

func Space() Layout

Space creates a new space layout, which will consume all free space that is available.

func Stack

func Stack(children ...any) Layout

Stack creates a new stacked layout with the provided children, where each child (left to right) is stacked on top of the previous one, with an increasing Z-index.

func TopPadding

func TopPadding(amount int, child any) Layout

TopPadding creates a new layout that pads the provided child with the given amount of space on the top.

func Vertical

func Vertical(children ...any) Layout

Vertical creates a new vertical layout with the provided children.

Jump to

Keyboard shortcuts

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