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 ColWidthPerc(widthPerc int, subElements ...Element) Element
- func ColWidthPercWithOpts(widthPerc 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.
type Element ¶
type Element interface {
// contains filtered or unexported methods
}
Element is an element that can be added to the grid.
func ColWidthPerc ¶
ColWidthPerc creates a column of the specified 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 RowHeightPerc ¶
RowHeightPerc creates a row of the specified 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.