Documentation ¶
Overview ¶
Package grid helps to build grid layouts.
Example ¶
Shows how to create a simple 4x4 grid with four widgets. All the cells in the grid contain the same widget in this example.
tbx, err := termbox.New() if err != nil { panic(err) } defer tbx.Close() bc, err := barchart.New() if err != nil { panic(err) } builder := New() builder.Add( RowHeightPerc( 50, ColWidthPerc(50, Widget(bc)), ColWidthPerc(50, Widget(bc)), ), RowHeightPerc( 50, ColWidthPerc(50, Widget(bc)), ColWidthPerc(50, Widget(bc)), ), ) gridOpts, err := builder.Build() if err != nil { panic(err) } cont, err := container.New(tbx, gridOpts...) if err != nil { panic(err) } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if err := termdash.Run(ctx, tbx, cont); err != nil { panic(err) }
Output:
Example (Iterative) ¶
Shows how to create rows iteratively. Each row contains two columns and each column contains the same widget.
tbx, err := termbox.New() if err != nil { panic(err) } defer tbx.Close() bc, err := barchart.New() if err != nil { panic(err) } builder := New() for i := 0; i < 5; i++ { builder.Add( RowHeightPerc( 20, ColWidthPerc(50, Widget(bc)), ColWidthPerc(50, Widget(bc)), ), ) } gridOpts, err := builder.Build() if err != nil { panic(err) } cont, err := container.New(tbx, gridOpts...) if err != nil { panic(err) } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() if err := termdash.Run(ctx, tbx, cont); err != nil { panic(err) }
Output:
Index ¶
- type Builder
- type Element
- func ColWidthFixed(widthCells int, subElements ...Element) Element
- func ColWidthFixedWithOpts(widthCells int, cOpts []container.Option, subElements ...Element) Element
- func ColWidthPerc(widthPerc int, subElements ...Element) Element
- func ColWidthPercWithOpts(widthPerc int, cOpts []container.Option, subElements ...Element) Element
- func RowHeightFixed(heightCells int, subElements ...Element) Element
- func RowHeightFixedWithOpts(heightCells int, cOpts []container.Option, subElements ...Element) Element
- func RowHeightPerc(heightPerc int, subElements ...Element) Element
- func RowHeightPercWithOpts(heightPerc int, cOpts []container.Option, subElements ...Element) Element
- func Widget(w widgetapi.Widget, cOpts ...container.Option) Element
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds grid layouts.
func (*Builder) Add ¶
Add adds the specified elements. The subElements can be either a single Widget or any combination of Rows and Columns. Rows are created using functions with the RowHeight prefix and Columns are created using functions with the ColWidth prefix Can be called repeatedly, e.g. to add multiple Rows or Columns.
type Element ¶
type Element interface {
// contains filtered or unexported methods
}
Element is an element that can be added to the grid.
func ColWidthFixed ¶ added in v0.10.0
ColWidthFixed creates a column of the specified fixed width. The width is supplied as a number of cells on the terminal. If the actual terminal size leaves the container with less than the specified amount of cells, the container will be created with zero cells and won't be drawn until the terminal size increases. If the sum of all the widths is less than 100% of the screen width, the last element stretches to the edge of the screen. The subElements can be either a single Widget or any combination of Rows and Columns. A column with fixed width cannot contain any sub-elements with relative size.
func ColWidthFixedWithOpts ¶ added in v0.10.0
func ColWidthFixedWithOpts(widthCells int, cOpts []container.Option, subElements ...Element) Element
ColWidthFixedWithOpts is like ColWidthFixed, but also allows to apply additional options to the container that represents the column.
func ColWidthPerc ¶
ColWidthPerc creates a column of the specified relative width. The width is supplied as width percentage of the parent element. The sum of all widths at the same level cannot be larger than 100%. If it is less that 100%, the last element stretches to the edge of the screen. The subElements can be either a single Widget or any combination of Rows and Columns.
func ColWidthPercWithOpts ¶ added in v0.9.0
ColWidthPercWithOpts is like ColWidthPerc, but also allows to apply additional options to the container that represents the column.
func RowHeightFixed ¶ added in v0.10.0
RowHeightFixed creates a row of the specified fixed height. The height is supplied as a number of cells on the terminal. If the actual terminal size leaves the container with less than the specified amount of cells, the container will be created with zero cells and won't be drawn until the terminal size increases. If the sum of all the heights is less than 100% of the screen height, the last element stretches to the edge of the screen. The subElements can be either a single Widget or any combination of Rows and Columns. A row with fixed height cannot contain any sub-elements with relative size.
func RowHeightFixedWithOpts ¶ added in v0.10.0
func RowHeightFixedWithOpts(heightCells int, cOpts []container.Option, subElements ...Element) Element
RowHeightFixedWithOpts is like RowHeightFixed, but also allows to apply additional options to the container that represents the row.
func RowHeightPerc ¶
RowHeightPerc creates a row of the specified relative height. The height is supplied as height percentage of the parent element. The sum of all heights at the same level cannot be larger than 100%. If it is less that 100%, the last element stretches to the edge of the screen. The subElements can be either a single Widget or any combination of Rows and Columns.