widget

package
v0.0.0-...-57c1bf3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package widget provides graphical user interface widgets.

TODO: give an overview and some example code.

Index

Constants

View Source
const (
	AxisNone       = Axis(0)
	AxisHorizontal = Axis(1)
	AxisVertical   = Axis(2)
	AxisBoth       = Axis(3) // AxisBoth equals AxisHorizontal | AxisVertical.
)

Variables

This section is empty.

Functions

func RunWindow

func RunWindow(s screen.Screen, root node.Node, opts *RunWindowOptions) error

RunWindow creates a new window for s, with the given widget tree, and runs its event loop.

A nil opts is valid and means to use the default option values.

func WithLayoutData

func WithLayoutData(n node.Node, layoutData interface{}) node.Node

WithLayoutData returns the given node after setting its embedded LayoutData field.

Types

type Axis

type Axis uint8

Axis is zero, one or both of the horizontal and vertical axes. For example, a widget may be scrollable in one of the four AxisXxx values.

func (Axis) Horizontal

func (a Axis) Horizontal() bool

func (Axis) Vertical

func (a Axis) Vertical() bool

type Flow

type Flow struct {
	node.ContainerEmbed
	Axis Axis
}

Flow is a container widget that lays out its children in sequence along an axis, either horizontally or vertically. The children's laid out size may differ from their natural size, along or across that axis, if a child's LayoutData is a FlowLayoutData.

func NewFlow

func NewFlow(a Axis, children ...node.Node) *Flow

NewFlow returns a new Flow widget containing the given children.

func (*Flow) Layout

func (w *Flow) Layout(t *theme.Theme)

func (*Flow) Measure

func (w *Flow) Measure(t *theme.Theme, widthHint, heightHint int)

type FlowLayoutData

type FlowLayoutData struct {
	// AlongWeight is the relative weight for distributing any space surplus or
	// deficit along the Flow's axis. For example, if an AxisHorizontal Flow's
	// Rect width was 100 pixels greater than the sum of its children's natural
	// widths, and three children had non-zero FlowLayoutData.AlongWeight
	// values 6, 3 and 1 (and their FlowLayoutData.ExpandAlong values were
	// true) then those children's laid out widths would be larger than their
	// natural widths by 60, 30 and 10 pixels.
	//
	// A negative AlongWeight is equivalent to zero.
	AlongWeight int

	// ExpandAlong is whether the child's laid out size should increase along
	// the Flow's axis, based on AlongWeight, if there is a space surplus (the
	// children's measured size total less than the parent's size). To allow
	// size decreases as well as increases, set ShrinkAlong.
	ExpandAlong bool

	// ShrinkAlong is whether the child's laid out size should decrease along
	// the Flow's axis, based on AlongWeight, if there is a space deficit (the
	// children's measured size total more than the parent's size). To allow
	// size increases as well as decreases, set ExpandAlong.
	ShrinkAlong bool

	// ExpandAcross is whether the child's laid out size should increase along
	// the Flow's cross-axis if there is a space surplus (the child's measured
	// size is less than the parent's size). To allow size decreases as well as
	// increases, set ShrinkAcross.
	//
	// For example, if an AxisHorizontal Flow's Rect height was 80 pixels, any
	// child whose FlowLayoutData.ExpandAcross was true would also be laid out
	// with at least an 80 pixel height.
	ExpandAcross bool

	// ShrinkAcross is whether the child's laid out size should decrease along
	// the Flow's cross-axis if there is a space deficit (the child's measured
	// size is more than the parent's size). To allow size increases as well as
	// decreases, set ExpandAcross.
	//
	// For example, if an AxisHorizontal Flow's Rect height was 80 pixels, any
	// child whose FlowLayoutData.ShrinkAcross was true would also be laid out
	// with at most an 80 pixel height.
	ShrinkAcross bool
}

FlowLayoutData is the node LayoutData type for a Flow's children.

type Image

type Image struct {
	node.LeafEmbed
	Src     image.Image
	SrcRect image.Rectangle
}

Image is a leaf widget that paints an image.Image.

func NewImage

func NewImage(src image.Image, srcRect image.Rectangle) *Image

NewImage returns a new Image widget for the part of a source image defined by src and srcRect.

func (*Image) Measure

func (w *Image) Measure(t *theme.Theme, widthHint, heightHint int)

func (*Image) PaintBase

func (w *Image) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error

type Label

type Label struct {
	node.LeafEmbed
	Text       string
	ThemeColor theme.Color
}

Label is a leaf widget that holds a text label.

func NewLabel

func NewLabel(text string) *Label

NewLabel returns a new Label widget.

func (*Label) Measure

func (w *Label) Measure(t *theme.Theme, widthHint, heightHint int)

func (*Label) PaintBase

func (w *Label) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error

type Padder

type Padder struct {
	node.ShellEmbed
	Axis   Axis
	Margin unit.Value
}

Padder is a shell widget that adds a margin to the inner widget's measured size. That margin may be added horizontally (left and right), vertically (top and bottom) or both, determined by the Padder's axis.

That marginal space is not considered part of the inner widget's geometry. For example, to make that space 'clickable', construct the Padder inside of an event handling widget instead of vice versa.

func NewPadder

func NewPadder(a Axis, margin unit.Value, inner node.Node) *Padder

NewPadder returns a new Padder widget.

func (*Padder) Layout

func (w *Padder) Layout(t *theme.Theme)

func (*Padder) Measure

func (w *Padder) Measure(t *theme.Theme, widthHint, heightHint int)

type RunWindowOptions

type RunWindowOptions struct {
	NewWindowOptions screen.NewWindowOptions
	Theme            theme.Theme
}

RunWindowOptions are optional arguments to RunWindow.

type Sheet

type Sheet struct {
	node.ShellEmbed
	// contains filtered or unexported fields
}

Sheet is a shell widget that provides *image.RGBA pixel buffers (analogous to blank sheets of paper) for its descendent widgets to paint on, via their PaintBase methods. Such buffers may be cached and their contents re-used for multiple paints, which can make scrolling and animation smoother and more efficient.

A simple app may have only one Sheet, near the root of its widget tree. A more complicated app may have multiple Sheets. For example, consider a text editor consisting of a small header bar and a large text widget. Those two nodes may be backed by two separate Sheets, since scrolling the latter should not scroll the former.

func NewSheet

func NewSheet(inner node.Node) *Sheet

NewSheet returns a new Sheet widget.

func (*Sheet) OnChildMarked

func (w *Sheet) OnChildMarked(child node.Node, newMarks node.Marks)

func (*Sheet) OnLifecycleEvent

func (w *Sheet) OnLifecycleEvent(e lifecycle.Event)

func (*Sheet) Paint

func (w *Sheet) Paint(ctx *node.PaintContext, origin image.Point) (retErr error)

func (*Sheet) PaintBase

func (w *Sheet) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error

type Sizer

type Sizer struct {
	node.ShellEmbed
	NaturalWidth  unit.Value
	NaturalHeight unit.Value
}

Sizer is a shell widget that overrides its child's measured size.

func NewSizer

func NewSizer(naturalWidth, naturalHeight unit.Value, inner node.Node) *Sizer

NewSizer returns a new Sizer widget of the given natural size. Its parent widget may lay it out at a different size than its natural size, such as expanding to fill a panel's width.

func (*Sizer) Measure

func (w *Sizer) Measure(t *theme.Theme, widthHint, heightHint int)

type Space

type Space struct {
	node.LeafEmbed
}

Space is leaf widget that occupies empty space. For example, aligning two widgets to the left and right edges of a container can be achieved by placing a third Space widget between them, whose LayoutData makes that Space expand to occupy any excess space. Similarly, a widget can be centered in its container by adding an expanding Space before and after.

func NewSpace

func NewSpace() *Space

NewSpace returns a new Space widget.

type Text

type Text struct {
	node.LeafEmbed
	// contains filtered or unexported fields
}

Text is a leaf widget that holds a text label.

func NewText

func NewText(text string) *Text

NewText returns a new Text widget.

func (*Text) Layout

func (w *Text) Layout(t *theme.Theme)

func (*Text) Measure

func (w *Text) Measure(t *theme.Theme, widthHint, heightHint int)

func (*Text) Paint

func (w *Text) Paint(ctx *node.PaintContext, origin image.Point) error

func (*Text) PaintBase

func (w *Text) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error

type Uniform

type Uniform struct {
	node.ShellEmbed
	ThemeColor theme.Color
}

Uniform is a shell widget that paints a uniform color, analogous to an image.Uniform.

func NewUniform

func NewUniform(c theme.Color, inner node.Node) *Uniform

NewUniform returns a new Uniform widget of the given color.

func (*Uniform) PaintBase

func (w *Uniform) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error

Directories

Path Synopsis
Package flex provides a container widget that lays out its children following the CSS flexbox algorithm.
Package flex provides a container widget that lays out its children following the CSS flexbox algorithm.
Package glwidget provides a widget containing a GL ES framebuffer.
Package glwidget provides a widget containing a GL ES framebuffer.
Package node provides the structure for a tree of heterogenous widget nodes.
Package node provides the structure for a tree of heterogenous widget nodes.
Package theme provides widget themes.
Package theme provides widget themes.

Jump to

Keyboard shortcuts

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