From 71d5f505a369784c537454c1fb0aacc61cb7e291 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 2 Mar 2019 18:53:05 -0500 Subject: [PATCH] Updated Container API (markdown) --- Container-API.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Container-API.md b/Container-API.md index c941439..843d8a7 100644 --- a/Container-API.md +++ b/Container-API.md @@ -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]] \ No newline at end of file +[[/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) +} +``` \ No newline at end of file