exp: golang.org/x/exp/shiny/widget Index | Files | Directories

package widget

import "golang.org/x/exp/shiny/widget"

Package widget provides graphical user interface widgets.

TODO: give an overview and some example code.

Index

Package Files

flow.go image.go label.go padder.go sheet.go sizer.go space.go text.go uniform.go widget.go

Constants

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

func RunWindow Uses

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 Uses

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

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

type Axis Uses

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 Uses

func (a Axis) Horizontal() bool

func (Axis) Vertical Uses

func (a Axis) Vertical() bool

type Flow Uses

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 Uses

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

NewFlow returns a new Flow widget containing the given children.

func (*Flow) Layout Uses

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

func (*Flow) Measure Uses

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

type FlowLayoutData Uses

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 Uses

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

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

func NewImage Uses

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 Uses

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

func (*Image) PaintBase Uses

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

type Label Uses

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

Label is a leaf widget that holds a text label.

func NewLabel Uses

func NewLabel(text string) *Label

NewLabel returns a new Label widget.

func (*Label) Measure Uses

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

func (*Label) PaintBase Uses

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

type Padder Uses

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 Uses

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

NewPadder returns a new Padder widget.

func (*Padder) Layout Uses

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

func (*Padder) Measure Uses

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

type RunWindowOptions Uses

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

RunWindowOptions are optional arguments to RunWindow.

type Sheet Uses

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 Uses

func NewSheet(inner node.Node) *Sheet

NewSheet returns a new Sheet widget.

func (*Sheet) OnChildMarked Uses

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

func (*Sheet) OnLifecycleEvent Uses

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

func (*Sheet) Paint Uses

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

func (*Sheet) PaintBase Uses

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

type Sizer Uses

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 Uses

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 Uses

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

type Space Uses

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 Uses

func NewSpace() *Space

NewSpace returns a new Space widget.

type Text Uses

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

Text is a leaf widget that holds a text label.

func NewText Uses

func NewText(text string) *Text

NewText returns a new Text widget.

func (*Text) Layout Uses

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

func (*Text) Measure Uses

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

func (*Text) Paint Uses

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

func (*Text) PaintBase Uses

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

type Uniform Uses

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 Uses

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

NewUniform returns a new Uniform widget of the given color.

func (*Uniform) PaintBase Uses

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

Directories

PathSynopsis
flexPackage flex provides a container widget that lays out its children following the CSS flexbox algorithm.
glwidgetPackage glwidget provides a widget containing a GL ES framebuffer.
nodePackage node provides the structure for a tree of heterogenous widget nodes.
themePackage theme provides widget themes.

Package widget imports 15 packages (graph) and is imported by 1 packages. Updated 2017-07-16. Refresh now. Tools for package owners.