mirror of https://github.com/mum4k/termdash.git
Updated Dynamic layout (markdown)
parent
7230a596d3
commit
6526b51bdc
|
@ -26,7 +26,7 @@ The **Container.Update** method applies the specified options to a container wit
|
|||
|
||||
### Replacing widget in a container
|
||||
|
||||
The following code places a button widget inside a container and then updates the container by replacing the button with a Text widget:
|
||||
The following code places a button widget inside a container and then updates the container by replacing the button with a text widget:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
|
@ -62,4 +62,52 @@ if err := c.Update("myID", container.PlaceWidget(t)); err != nil {
|
|||
}
|
||||
```
|
||||
|
||||
### Changing the layout by specifying new splits
|
||||
### Changing the layout by specifying new splits
|
||||
|
||||
When container is updated by adding a new split, any previously placed widgets or sub-containers are replaced with the new layout. This can be utilized to change the layout of the screen and display new grid and content.
|
||||
|
||||
The following code places a button widget inside a container and then updates the container by splitting it into two and placing a button and a text widget:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
|
||||
b, err := button.New("hello world", func() error {
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("button.New => %v", err)
|
||||
}
|
||||
|
||||
t, err := text.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("text.New => %v", err)
|
||||
}
|
||||
|
||||
c, err := container.New(
|
||||
t,
|
||||
container.PlaceWidget(b),
|
||||
container.ID("myID"),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("container.New => %v", err)
|
||||
}
|
||||
|
||||
if err := c.Update(
|
||||
"myID",
|
||||
container.SplitVertical(
|
||||
container.Left(
|
||||
container.PlaceWidget(b),
|
||||
),
|
||||
container.Right(
|
||||
container.PlaceWidget(t),
|
||||
),
|
||||
),
|
||||
); err != nil {
|
||||
return fmt.Errorf("c.Update => %v", err)
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue