layout

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Layout

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

The Layout struct provides a way of arranging and displaying multiple components in a single view with the ability to navigate between them.

func NewLayout

func NewLayout(rows ...Row) *Layout

Get a new Layout instance

func (*Layout) GetActive

func (l *Layout) GetActive() *PositionalElement

Get a reference to the active element

func (*Layout) Init

func (l *Layout) Init() tea.Cmd

Call Init() on all components

func (*Layout) NavigateDown

func (l *Layout) NavigateDown()

func (*Layout) NavigateLeft

func (l *Layout) NavigateLeft()

func (*Layout) NavigateRight

func (l *Layout) NavigateRight()

func (*Layout) NavigateUp

func (l *Layout) NavigateUp()

func (*Layout) Resize

func (l *Layout) Resize(width, height int)

Set a new width and height for the Layout to occupy.

func (*Layout) SetActive

func (l *Layout) SetActive(x, y int)

Set active element

func (*Layout) UpdateActive

func (l *Layout) UpdateActive(msg tea.Msg) tea.Cmd

Update only the active element with the provided message

func (*Layout) UpdateAll

func (l *Layout) UpdateAll(msg tea.Msg) tea.Cmd

Update all elements with the provided message

func (*Layout) View

func (l *Layout) View() string

Render the layout

type LayoutModel

type LayoutModel interface {
	// tea.Model
	Init() tea.Cmd
	Update(tea.Msg) (tea.Model, tea.Cmd)
	View() string

	IsActive() bool
	SetActive() LayoutModel
	UnsetActive() LayoutModel

	// This method gets called with the actual with the component
	// will have available. This is useful when you use fill-mode
	// and do not have a fixed width.
	OnAvailWidthChange(width int) LayoutModel
}

Extends the normal tea.Model with methods set and unset it as active element.

type Position

type Position int
const (
	Left   Position = iota
	Center Position = iota
	Right  Position = iota
)

type PositionalElement

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

The PositionalElement is a wrapper around the model that should be displayed. It holds extra metadata.

func Empty

func Empty() PositionalElement

Empty element. Fill empty space in Layout.

func Fill

func Fill(model *LayoutModel, position Position, width float64) PositionalElement

Fill width dynamically. position: left | center | right width: fraction of how much space to take, e.g. 0.5 for 50%

func FillAuto

func FillAuto(model *LayoutModel, position Position) PositionalElement

Fill width dynamically. Split space equally among fill-auto elements position: left | center | right

func Fixed

func Fixed(model *LayoutModel, position Position, width int) PositionalElement

Fixed width.

func (*PositionalElement) IsSelectable

func (p *PositionalElement) IsSelectable() bool

Check if an element is selectable

func (PositionalElement) NotSelectable

func (p PositionalElement) NotSelectable() PositionalElement

Element cannot be selected by user

type Row

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

Provides one Row in the Layout Make sure that all rows have the same number of elements. You can use an "empty" element to fill the gaps.

func NewRow

func NewRow(elements ...PositionalElement) Row

Create a new row

func (*Row) All

func (r *Row) All() iter.Seq[PositionalElement]

Iterate over all elements

func (*Row) GetLength

func (r *Row) GetLength() int

Get count of element in row

func (*Row) NotNil

func (r *Row) NotNil() iter.Seq[PositionalElement]

Iterate over all non-nil elements

func (*Row) View

func (r *Row) View() string

Render row

Jump to

Keyboard shortcuts

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