container

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: Apache-2.0 Imports: 16 Imported by: 123

Documentation

Overview

Package container defines a type that wraps other containers or widgets.

The container supports splitting container into sub containers, defining container styles and placing widgets. The container also creates and manages canvases assigned to the placed widgets.

Example

Example demonstrates how to use the Container API.

bc, err := barchart.New()
if err != nil {
	panic(err)
}
if _, err := New(
	/* terminal = */ nil,
	SplitVertical(
		Left(
			SplitHorizontal(
				Top(
					Border(linestyle.Light),
				),
				Bottom(
					SplitHorizontal(
						Top(
							Border(linestyle.Light),
						),
						Bottom(
							Border(linestyle.Light),
						),
					),
				),
				SplitPercent(30),
			),
		),
		Right(
			Border(linestyle.Light),
			PlaceWidget(bc),
		),
	),
); err != nil {
	panic(err)
}
Output:

Index

Examples

Constants

View Source
const DefaultSplitPercent = 50

DefaultSplitPercent is the default value for the SplitPercent option.

Variables

This section is empty.

Functions

This section is empty.

Types

type BottomOption

type BottomOption interface {
	// contains filtered or unexported methods
}

BottomOption is used to provide options to the bottom sub container after a horizontal split of the parent.

func Bottom

func Bottom(opts ...Option) BottomOption

Bottom applies options to the bottom sub container after a horizontal split of the parent.

type Container

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

Container wraps either sub containers or widgets and positions them on the terminal. This is thread-safe.

func New

func New(t terminalapi.Terminal, opts ...Option) (*Container, error)

New returns a new root container that will use the provided terminal and applies the provided options.

func (*Container) Draw

func (c *Container) Draw() error

Draw draws this container and all of its sub containers.

func (*Container) String

func (c *Container) String() string

String represents the container metadata in a human readable format. Implements fmt.Stringer.

func (*Container) Subscribe added in v0.7.0

func (c *Container) Subscribe(eds *event.DistributionSystem)

Subscribe tells the container to subscribe itself and widgets to the provided event distribution system. This method is private to termdash, stability isn't guaranteed and changes won't be backward compatible.

type LeftOption

type LeftOption interface {
	// contains filtered or unexported methods
}

LeftOption is used to provide options to the left sub container after a vertical split of the parent.

func Left

func Left(opts ...Option) LeftOption

Left applies options to the left sub container after a vertical split of the parent.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options to a container.

func AlignHorizontal

func AlignHorizontal(h align.Horizontal) Option

AlignHorizontal sets the horizontal alignment for the widget placed in the container. Has no effect if the container contains no widget. Defaults to alignment in the center.

func AlignVertical

func AlignVertical(v align.Vertical) Option

AlignVertical sets the vertical alignment for the widget placed in the container. Has no effect if the container contains no widget. Defaults to alignment in the middle.

func Border

func Border(ls linestyle.LineStyle) Option

Border configures the container to have a border of the specified style.

func BorderColor

func BorderColor(color cell.Color) Option

BorderColor sets the color of the border around the container. This option is inherited to sub containers created by container splits.

func BorderTitle

func BorderTitle(title string) Option

BorderTitle sets a text title within the border.

func BorderTitleAlignCenter

func BorderTitleAlignCenter() Option

BorderTitleAlignCenter aligns the border title in the center.

func BorderTitleAlignLeft

func BorderTitleAlignLeft() Option

BorderTitleAlignLeft aligns the border title on the left.

func BorderTitleAlignRight

func BorderTitleAlignRight() Option

BorderTitleAlignRight aligns the border title on the right.

func FocusedColor

func FocusedColor(color cell.Color) Option

FocusedColor sets the color of the border around the container when it has keyboard focus. This option is inherited to sub containers created by container splits.

func PlaceWidget

func PlaceWidget(w widgetapi.Widget) Option

PlaceWidget places the provided widget into the container. The use of this option removes any sub containers. Containers with sub containers cannot have widgets.

func SplitHorizontal

func SplitHorizontal(t TopOption, b BottomOption, opts ...SplitOption) Option

SplitHorizontal splits the container along the horizontal axis into two sub containers. The use of this option removes any widget placed at this container, containers with sub containers cannot contain widgets.

func SplitVertical

func SplitVertical(l LeftOption, r RightOption, opts ...SplitOption) Option

SplitVertical splits the container along the vertical axis into two sub containers. The use of this option removes any widget placed at this container, containers with sub containers cannot contain widgets.

type RightOption

type RightOption interface {
	// contains filtered or unexported methods
}

RightOption is used to provide options to the right sub container after a vertical split of the parent.

func Right(opts ...Option) RightOption

Right applies options to the right sub container after a vertical split of the parent.

type SplitOption added in v0.4.0

type SplitOption interface {
	// contains filtered or unexported methods
}

SplitOption is used when splitting containers.

func SplitPercent added in v0.4.0

func SplitPercent(p int) SplitOption

SplitPercent sets the relative size of the split as percentage of the available space. When using SplitVertical, the provided size is applied to the new left container, the new right container gets the reminder of the size. When using SplitHorizontal, the provided size is applied to the new top container, the new bottom container gets the reminder of the size. The provided value must be a positive number in the range 0 < p < 100. If not provided, defaults to DefaultSplitPercent.

type TopOption

type TopOption interface {
	// contains filtered or unexported methods
}

TopOption is used to provide options to the top sub container after a horizontal split of the parent.

func Top

func Top(opts ...Option) TopOption

Top applies options to the top sub container after a horizontal split of the parent.

Jump to

Keyboard shortcuts

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