widget

package
v0.0.0-...-e111b83 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2015 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package widget contains classes for widgets and the main window of a program.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var ConstructorRegistry = make(map[string]func(json []byte) Drawable)

ContructorRegistry maps component names to component constructors that use a JSON definition.

Functions

func FindResourcesDir

func FindResourcesDir(resDir string) (dir string, err error)

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

func IdlToJson(idl string) []byte

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.

func LoadImage

func LoadImage(filename string) (*extimage.BGRA, error)

LoadImage loads an image from a file. For good drawing performance it returns an *extimage.BGRA. extimage.BGRA can be used directly for cairo image surfaces.

func NewId

func NewId() string

NewId creates a unique string as an identifier.

func RectSize

func RectSize(area image.Rectangle) (x, y, dx, dy float64)

RectSize returns the dimensions of a Rectangle as float64 values.

Types

type Accessible

type Accessible interface {
	Caption() string
	Tip() string
	Description() string
}

Accessible is a simple interface for accessibility purposes.

type BlankWidget

type BlankWidget struct {
	event.Sender
	event.Receiver
	// contains filtered or unexported fields
}

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.

func GetButton

func GetButton(name string) *Button

func NewButton

func NewButton(caption string) *Button

func (*Button) Draw

func (b *Button) Draw()

func (*Button) LoadImage

func (b *Button) LoadImage(filename string) error

func (*Button) MinSize

func (b *Button) MinSize() image.Point

func (*Button) SetImage

func (b *Button) SetImage(img image.Image)

type Canvas

type Canvas struct {
	WidgetPart
	// contains filtered or unexported fields
}

func GetCanvas

func GetCanvas(name string) *Canvas

func NewCanvas

func NewCanvas() *Canvas

func (*Canvas) Draw

func (c *Canvas) Draw()

Draw draws the canvas onto the surface.

func (*Canvas) LineTo

func (c *Canvas) LineTo(p image.Point)

func (*Canvas) MoveTo

func (c *Canvas) MoveTo(p image.Point)

func (*Canvas) ReceiveEvent

func (c *Canvas) ReceiveEvent(evt interface{})

ReceiveEvent receives a single event. It overwrites event.Receiver.ReceiveEvent().

func (*Canvas) SetBackgroundColor

func (c *Canvas) SetBackgroundColor(color color.Color)

func (*Canvas) SetBackgroundImage

func (c *Canvas) SetBackgroundImage(img image.Image)

func (*Canvas) SetBrushColor

func (c *Canvas) SetBrushColor(color color.Color)

func (*Canvas) SetBrushWidth

func (c *Canvas) SetBrushWidth(width int)

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

type Container interface {
	Layout
	event.Receiver
	event.Sender
}

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 NewButtonFromJson(jsonDef []byte) Drawable

func NewCanvasFromJson

func NewCanvasFromJson(jsonDef []byte) Drawable

func NewSpacerFromJson

func NewSpacerFromJson(jsonDef []byte) Drawable

type GridGaps

type GridGaps struct {
	Top            int
	Begin          int
	End            int
	Bottom         int
	BetweenRows    int
	BetweenColumns int
}

func (GridGaps) Unit

func (g GridGaps) Unit(unit int) GridGaps

Unit converts grid gaps in a defined length unit to pixel units.

The unit parameter is a factor with which GridGaps are multiplied to get the length in pixel units.

Predefined are: Mm, Cm, Inch.

type Layout

type Layout interface {
	Drawable
	Addf(layoutDef string, components ...Drawable)
}

Layout positions drawable objects.

type LayoutDef

type LayoutDef struct {
	GrowX int
	GrowY int
	SpanX int
	SpanY int
}

LayoutDef defines the layout of a component in CombiGridLayout.

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 GetSpacer

func GetSpacer(name string) *Spacer

func NewSpacer

func NewSpacer() *Spacer

func (*Spacer) Area

func (s *Spacer) Area() image.Rectangle

func (*Spacer) Draw

func (s *Spacer) Draw()

func (*Spacer) MinSize

func (s *Spacer) MinSize() image.Point

func (*Spacer) SetArea

func (s *Spacer) SetArea(drawRect image.Rectangle)

func (*Spacer) SetSurface

func (s *Spacer) SetSurface(surface *cairo.Surface)

func (*Spacer) Surface

func (s *Spacer) 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

func (s *Style) ContentPosition() (x, y int)

ContentPosition() returns the top left postion for content after the borders, paddings and margins are drawn.

func (*Style) Draw

func (s *Style) Draw(surface *cairo.Surface, area image.Rectangle)

func (*Style) Size

func (s *Style) Size() (dx, dy int)

Size returns the size that is needed to draw the style without the inner content.

type TestWidget

type TestWidget struct {
	event.Sender
	event.Receiver
	// contains filtered or unexported fields
}

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

type Widget interface {
	Drawable
	event.Receiver
	event.Sender
}

Widget is something that can be drawn onto the screen and is capable to send and receive events.

type WidgetPart

type WidgetPart struct {
	event.Sender
	event.Receiver
	// contains filtered or unexported fields
}

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 GetWindow

func GetWindow(name string) *Window

func NewWindow

func NewWindow() *Window

func NewWindowFromJson

func NewWindowFromJson(jsonDef []byte) *Window

func (*Window) Close

func (w *Window) Close()

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.

func (*Window) Run

func (w *Window) Run()

Run just starts the main event loop.

func (*Window) Show

func (w *Window) Show()

Show draws the contents of the window and makes it visible on the screen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL