Exploring the design of the Widget API
As we described in Chapter 2, The Future According to Fyne, its APIs are designed to convey semantic meaning rather than a list of features. This is followed on by the Widget definition, whereby we add APIs that describe behavior and hide the details of rendering. The interface that all widgets must implement is simply an extension of the basic CanvasObject
object (introduced in Chapter 3, Window, Canvas, and Drawing), which adds a CreateRenderer()
method. It is defined in the source code as follows:
// Widget defines the standard behaviors of any widget. // This extends the CanvasObject - a widget behaves in // the same basic way but will encapsulate many child // objects to create the rendered widget. type Widget interface { CanvasObject CreateRenderer() WidgetRenderer }
The new CreateRenderer()
method is used by Fyne to determine how the widget...