Documentation ¶
Overview ¶
Package widget contains classes for widgets and the main window of a program.
Index ¶
- Variables
- func FindResourcesDir(resDir string) (dir string, err error)
- func IdlToJson(idl string) []byte
- func LoadImage(filename string) (*extimage.BGRA, error)
- func NewId() string
- func RectSize(area image.Rectangle) (x, y, dx, dy float64)
- type Accessible
- type BlankWidget
- func (w *BlankWidget) Area() image.Rectangle
- func (w *BlankWidget) Draw()
- func (w *BlankWidget) MinSize() image.Point
- func (w *BlankWidget) ReceiveEvent(evt interface{})
- func (w *BlankWidget) SetArea(drawRect image.Rectangle)
- func (w *BlankWidget) SetSurface(surface *cairo.Surface)
- func (w *BlankWidget) Surface() *cairo.Surface
- type Button
- type Canvas
- func (c *Canvas) Draw()
- func (c *Canvas) LineTo(p image.Point)
- func (c *Canvas) MoveTo(p image.Point)
- func (c *Canvas) ReceiveEvent(evt interface{})
- func (c *Canvas) SetBackgroundColor(color color.Color)
- func (c *Canvas) SetBackgroundImage(img image.Image)
- func (c *Canvas) SetBrushColor(color color.Color)
- func (c *Canvas) SetBrushWidth(width int)
- type CombiGridEntry
- type CombiGridLayout
- func (l *CombiGridLayout) AddWithLayout(component Drawable, layout *LayoutDef)
- func (l *CombiGridLayout) Addf(layoutDef string, components ...Drawable)
- func (l *CombiGridLayout) Area() image.Rectangle
- func (l *CombiGridLayout) Draw()
- func (l *CombiGridLayout) Gaps() GridGaps
- func (l *CombiGridLayout) MinSize() image.Point
- func (l *CombiGridLayout) SetArea(drawRect image.Rectangle)
- func (l *CombiGridLayout) SetGaps(gaps GridGaps)
- func (l *CombiGridLayout) SetSurface(surface *cairo.Surface)
- func (l *CombiGridLayout) Surface() *cairo.Surface
- func (l *CombiGridLayout) Wrap()
- type Container
- type DefaultContainer
- type Drawable
- type GridGaps
- type Layout
- type LayoutDef
- type Spacer
- type Style
- type TestWidget
- func (w *TestWidget) Area() image.Rectangle
- func (w *TestWidget) Draw()
- func (w *TestWidget) MinSize() image.Point
- func (w *TestWidget) ReceiveEvent(evt interface{})
- func (w *TestWidget) SetArea(drawRect image.Rectangle)
- func (w *TestWidget) SetSurface(surface *cairo.Surface)
- func (w *TestWidget) Surface() *cairo.Surface
- type Widget
- type WidgetPart
- type Window
Constants ¶
This section is empty.
Variables ¶
var ( Mm int = 10 * dpi / 254 Cm int = 100 * dpi / 254 Inch int = dpi // Recommended height of capital letters (cap height) for standard font. Cap int = distanceToScreen * 7 * Mm / 1000 // Recommended height of em (about the same as type height) for standard font. Rem int = distanceToScreen * Mm / 100 )
Length units in pixel units.
var ComponentRegistry = make(map[string]Drawable)
ComponentRegistry is a registry for all components that can be drawn onto the screen. The purpose is to access widgets through an id, for example Button("okButton").SetText("All Right"), where Button is a function that asks the registry for the appropriate widget. This is very useful when the widgets are to be identified by an id, like in web applications or a textual UI description. Newly created widgets should register at this registry and provide an access function like func Label(id string) *Label.
var ConstructorRegistry = make(map[string]func(json []byte) Drawable)
ContructorRegistry maps component names to component constructors that use a JSON definition.
Functions ¶
func FindResourcesDir ¶
FindResourcesDir tries to locate a subdirectory that resides within the GOPATH environment variable.
If the functions finds the specified subdirectory in one of the GOPATH directories it returns the full path of the directory.
func IdlToJson ¶
IdlToJson converts a string in Interface Description Language (Idl) to Json. At the moment Idl is just Json with newlines, cursor returns and tabs allowed. This makes the interface descriptions more readable.
Types ¶
type Accessible ¶
Accessible is a simple interface for accessibility purposes.
type BlankWidget ¶
BlankWidget is a simple widget that is used as a default in Combigridlayout. It draws a frame and implements the Widget interface.
func NewBlankWidget ¶
func NewBlankWidget() *BlankWidget
func (*BlankWidget) Area ¶
func (w *BlankWidget) Area() image.Rectangle
func (*BlankWidget) Draw ¶
func (w *BlankWidget) Draw()
func (*BlankWidget) MinSize ¶
func (w *BlankWidget) MinSize() image.Point
func (*BlankWidget) ReceiveEvent ¶
func (w *BlankWidget) ReceiveEvent(evt interface{})
ReceiveEvent receives a single event. It overwrites event.Receiver.ReceiveEvent().
func (*BlankWidget) SetArea ¶
func (w *BlankWidget) SetArea(drawRect image.Rectangle)
func (*BlankWidget) SetSurface ¶
func (w *BlankWidget) SetSurface(surface *cairo.Surface)
func (*BlankWidget) Surface ¶
func (w *BlankWidget) Surface() *cairo.Surface
type Button ¶
type Button struct { WidgetPart Caption string Command string // contains filtered or unexported fields }
Button is a simple Button that is able to display an image.
type Canvas ¶
type Canvas struct { WidgetPart // contains filtered or unexported fields }
func (*Canvas) ReceiveEvent ¶
func (c *Canvas) ReceiveEvent(evt interface{})
ReceiveEvent receives a single event. It overwrites event.Receiver.ReceiveEvent().
func (*Canvas) SetBackgroundColor ¶
func (*Canvas) SetBackgroundImage ¶
func (*Canvas) SetBrushColor ¶
func (*Canvas) SetBrushWidth ¶
SetBrushWidth sets the width of the drawing brush in pixel units. For all drawing operations a circular brush is used.
type CombiGridEntry ¶
type CombiGridEntry struct {
// contains filtered or unexported fields
}
type CombiGridLayout ¶
type CombiGridLayout struct {
// contains filtered or unexported fields
}
CombiGridLayout implements Layout. It is a layout that supports laying out components in a grid and docking them together. CombiGridLayout was heavily inspired by MigLayout http://miglayout.com/.
CombiGridLayout is a series of components (Drawables) arranged is a grid or docked together (which also results in a grid). Each component may be a Container consisting of other components.
func NewCombiGridLayout ¶
func NewCombiGridLayout() *CombiGridLayout
func (*CombiGridLayout) AddWithLayout ¶
func (l *CombiGridLayout) AddWithLayout(component Drawable, layout *LayoutDef)
func (*CombiGridLayout) Addf ¶
func (l *CombiGridLayout) Addf(layoutDef string, components ...Drawable)
func (*CombiGridLayout) Area ¶
func (l *CombiGridLayout) Area() image.Rectangle
func (*CombiGridLayout) Draw ¶
func (l *CombiGridLayout) Draw()
func (*CombiGridLayout) Gaps ¶
func (l *CombiGridLayout) Gaps() GridGaps
func (*CombiGridLayout) MinSize ¶
func (l *CombiGridLayout) MinSize() image.Point
func (*CombiGridLayout) SetArea ¶
func (l *CombiGridLayout) SetArea(drawRect image.Rectangle)
func (*CombiGridLayout) SetGaps ¶
func (l *CombiGridLayout) SetGaps(gaps GridGaps)
func (*CombiGridLayout) SetSurface ¶
func (l *CombiGridLayout) SetSurface(surface *cairo.Surface)
func (*CombiGridLayout) Surface ¶
func (l *CombiGridLayout) Surface() *cairo.Surface
func (*CombiGridLayout) Wrap ¶
func (l *CombiGridLayout) Wrap()
Wrap jumps to the beginning of the next line.
type Container ¶
Container is a container for other widgets that should be displayed. A typical container is a window.
func NewContainer ¶
func NewContainer() Container
type DefaultContainer ¶
type DefaultContainer struct { CombiGridLayout event.Sender event.Receiver // contains filtered or unexported fields }
DefaultContainer is a sample implementation that satisfies the Container interface.
func NewDefaultContainer ¶
func NewDefaultContainer() *DefaultContainer
func NewDefaultContainerFromJson ¶
func NewDefaultContainerFromJson(jsonDef []byte) *DefaultContainer
func (*DefaultContainer) Addf ¶
func (c *DefaultContainer) Addf(layoutDef string, components ...Drawable)
Addf overwrites Addf in Layout.
func (*DefaultContainer) ReceiveEvent ¶
func (c *DefaultContainer) ReceiveEvent(evt interface{})
ReceiveEvent receives a single event.
func (*DefaultContainer) ReceiveFromEmbedded ¶
func (c *DefaultContainer) ReceiveFromEmbedded(evt interface{})
ReceiveFromEmbedded receives events from embedded components.
type Drawable ¶
type Drawable interface { Draw() SetArea(image.Rectangle) Area() image.Rectangle SetSurface(*cairo.Surface) Surface() *cairo.Surface // MinSize is the minimum space the object needs to // to be displayed. It is calculated by the object itself. MinSize() image.Point }
Drawable is anything that could be drawn onto the screen.
func NewButtonFromJson ¶
func NewCanvasFromJson ¶
func NewSpacerFromJson ¶
type Spacer ¶
type Spacer struct {
// contains filtered or unexported fields
}
Spacer is a Drawable object that can be used to add some space in a layout. Apart from that, a spacer does nothing.
func (*Spacer) SetSurface ¶
func (s *Spacer) SetSurface(surface *cairo.Surface)
type Style ¶
type Style struct { FontSize float64 Color color.Color Background color.Color MarginTop int MarginLeft int MarginRight int MarginBottom int PaddingTop int PaddingLeft int PaddingRight int PaddingBottom int BorderTopColor color.Color BorderLeftColor color.Color BorderRightColor color.Color BorderBottomColor color.Color BorderTopWidth int BorderLeftWidth int BorderRightWidth int BorderBottomWidth int }
Style determines the drawing style like CSS.
func (*Style) ContentPosition ¶
ContentPosition() returns the top left postion for content after the borders, paddings and margins are drawn.
type TestWidget ¶
TestWidget is a simple widget for testing purposes. It implements the Widget interface.
func NewTestWidget ¶
func NewTestWidget() *TestWidget
func (*TestWidget) Area ¶
func (w *TestWidget) Area() image.Rectangle
func (*TestWidget) Draw ¶
func (w *TestWidget) Draw()
func (*TestWidget) MinSize ¶
func (w *TestWidget) MinSize() image.Point
func (*TestWidget) ReceiveEvent ¶
func (w *TestWidget) ReceiveEvent(evt interface{})
ReceiveEvent receives a single event. It overwrites event.Receiver.ReceiveEvent().
func (*TestWidget) SetArea ¶
func (w *TestWidget) SetArea(drawRect image.Rectangle)
func (*TestWidget) SetSurface ¶
func (w *TestWidget) SetSurface(surface *cairo.Surface)
func (*TestWidget) Surface ¶
func (w *TestWidget) Surface() *cairo.Surface
type Widget ¶
Widget is something that can be drawn onto the screen and is capable to send and receive events.
type WidgetPart ¶
WidgetPart implements most methods of the Widget interface. To fully implement the widget interface the Draw() method must be added. WidgetPart can be used to construct new widgets by mixing it into the new widget class. WidgetPart replaces the old WidgetPart to avoid overwriting methods in prototype based inheritence.
func NewWidgetPart ¶
func NewWidgetPart() *WidgetPart
func (*WidgetPart) Area ¶
func (w *WidgetPart) Area() image.Rectangle
func (*WidgetPart) MinSize ¶
func (w *WidgetPart) MinSize() image.Point
func (*WidgetPart) SetArea ¶
func (w *WidgetPart) SetArea(drawRect image.Rectangle)
func (*WidgetPart) SetSurface ¶
func (w *WidgetPart) SetSurface(surface *cairo.Surface)
func (*WidgetPart) Surface ¶
func (w *WidgetPart) Surface() *cairo.Surface
type Window ¶
type Window struct { DefaultContainer // contains filtered or unexported fields }
Window represents a typical graphical window. It usually encapsulates a native system window. In this version of the code it is a wde window.
func NewWindowFromJson ¶
func (*Window) Draw ¶
func (w *Window) Draw()
Draw completely draws the contents of a window. This includes a recalculation of the position of widgets.
func (*Window) ReceiveFromEmbeddedChan ¶
func (w *Window) ReceiveFromEmbeddedChan(ec <-chan interface{})
ReceiveFromEmbeddedChan receives events from embedded components.