Updated Container API (markdown)

Jakub Sobon 2019-03-02 18:53:05 -05:00
parent b3d58b3f49
commit 71d5f505a3
1 changed files with 34 additions and 1 deletions

@ -24,4 +24,37 @@ Given a container, developers can create sub-containers by **splitting** the con
This property is recursive, meaning developers can further split the sub-containers using the same rules. The following diagram demonstrates how splits are utilized to create a layout.
[[/images/container-api/container_splits.png|container_splits]]
[[/images/container-api/container_splits.png|container_splits]]
## [container.New](https://godoc.org/github.com/mum4k/termdash/container#New):
The **container.New** function is used to constract a container. The API of this function uses a recursive builder patters, the complete layout of all the containers in the tree is established in a single call.
To create the terminal layout indicated in the diagram above, the developer can use the following call:
```go
tb, err := termbox.New()
if err != nil {
return fmt.Errorf("termbox.New => %v", err)
}
if _, err := container.New(
tb,
container.SplitVertical(
container.Left(), // Container left empty in this example.
container.Right(
container.SplitHorizontal(
container.Top() // Container left empty in this example.
container.Bottom(
container.SplitVertical(
container.Left(), // Container left empty in this example.
container.Right(), // Container left empty in this example.
),
),
),
),
),
); err != nil {
panic(err)
}
```