diff --git a/doc/widget_development.md b/doc/widget_development.md index 09adfaa..4c4563c 100644 --- a/doc/widget_development.md +++ b/doc/widget_development.md @@ -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 scenario where the infrastructure provides a canvas that doesn't match the 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** the canvas will be limited to the specified size. Widgets can either specify a diff --git a/widgetapi/widgetapi.go b/widgetapi/widgetapi.go index 2449c5f..01211b8 100644 --- a/widgetapi/widgetapi.go +++ b/widgetapi/widgetapi.go @@ -85,10 +85,11 @@ type Widget interface { // size, etc. // // Most widgets will return statically compiled options (minimum and - // maximum size, etc.). If the returned options depend on runtime state - // (e.g. the user data provided to the widget), the widget cannot depend on - // the infrastructure to no call the Draw method with a canvas that doesn't - // meet the requested options. This is because the data in the widget might - // change between calls to Options and Draw. + // maximum size, etc.). If the returned options depend on the runtime state + // of the widget (e.g. the user data provided to the widget), the widget + // must protect against a case where the infrastructure calls the Draw + // method with a canvas that doesn't meet the requested options. This is + // because the data in the widget might change between calls to Options and + // Draw. Options() Options }