1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-28 13:48:51 +08:00

Self-review fixes.

This commit is contained in:
Jakub Sobon 2019-01-27 00:07:00 -05:00
parent 8f6c2e59b7
commit 94f656e3c7
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
2 changed files with 25 additions and 6 deletions

View File

@ -43,7 +43,25 @@ returned on a call to the **Options** method aren't static, but depend on the
user data provided to the widget, the widget **must** protect against the user data provided to the widget, the widget **must** protect against the
scenario where the infrastructure provides a canvas that doesn't match the scenario where the infrastructure provides a canvas that doesn't match the
returned options. This is because the infrastructure cannot guarantee the user returned options. This is because the infrastructure cannot guarantee the user
won't change the inputs between calls to **Options** and **Draw**. won't change the data between calls to **Options** and **Draw**.
A widget can draw a character indicating that a resize is needed in such cases:
```go
func (w *Widget) Draw(cvs *canvas.Canvas) error {
min := w.minSize() // Output depends on the current state.
needAr, err := area.FromSize(min)
if err != nil {
return err
}
if !needAr.In(cvs.Area()) {
return draw.ResizeNeeded(cvs)
}
// Draw the widget.
return nil
}
```
If the container configuration results in a canvas larger than **MaximumSize** If the container configuration results in a canvas larger than **MaximumSize**
the canvas will be limited to the specified size. Widgets can either specify a the canvas will be limited to the specified size. Widgets can either specify a

View File

@ -85,10 +85,11 @@ type Widget interface {
// size, etc. // size, etc.
// //
// Most widgets will return statically compiled options (minimum and // Most widgets will return statically compiled options (minimum and
// maximum size, etc.). If the returned options depend on runtime state // maximum size, etc.). If the returned options depend on the runtime state
// (e.g. the user data provided to the widget), the widget cannot depend on // of the widget (e.g. the user data provided to the widget), the widget
// the infrastructure to no call the Draw method with a canvas that doesn't // must protect against a case where the infrastructure calls the Draw
// meet the requested options. This is because the data in the widget might // method with a canvas that doesn't meet the requested options. This is
// change between calls to Options and Draw. // because the data in the widget might change between calls to Options and
// Draw.
Options() Options Options() Options
} }