ui

package
v0.0.0-...-b7bdad3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2017 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnchorCenter = Anchor{
	Src: geo.VecXY(0.5, 0.5),
	Dst: geo.VecXY(0.5, 0.5),
}

AnchorCenter is a predefined anchor that centers the element in both directions.

View Source
var AnchorLeft = Anchor{
	Src: geo.VecXY(0, 0.5),
	Dst: geo.VecXY(0, 0.5),
}

AnchorLeft aligns the left edges of the source and destination elements, and vertically centers it.

Functions

This section is empty.

Types

type Anchor

type Anchor struct {
	// Src is a percentage of the source's bounding rectangle to use as an anchor point.
	// E.g (0, 0) uses is the top left as an anchor, and (1, 1) uses the bottom right.
	Src geo.Vec
	// Dst is a percentage of the bounds that the element is drawn within to use as an
	// anchor point.
	Dst geo.Vec
	// Offset positions the source's Anchor point at this offset relative to the destination
	// anchor point.
	Offset geo.Vec
}

Anchor holds fields for positioning elements relative to each other. Center element:

Src: (0.5, 0.5)
Dst: (0.5, 0.5)
Offset: (0, 0)

Left align and vertically center with some padding

Src: (0, 0.5)
Dst: (0, 0.5)
Offset: (10, 0)

func (Anchor) TopLeft

func (a Anchor) TopLeft(srcBounds, dstBounds geo.Rect) geo.Vec

TopLeft returns the top left position that the source element should be to align the anchors with the offset.

type Button

type Button struct {
	IdleImg     *ebiten.Image
	HoverImg    *ebiten.Image
	Element     WeightedDrawer
	IdleAnchor  Anchor
	HoverAnchor Anchor
	Wt          float64
	Hover       bool
	OnClick     func()
	// contains filtered or unexported fields
}

Button is a container that holds one sub-element and images for its states.

func (*Button) Draw

func (b *Button) Draw(dst *ebiten.Image, bounds geo.Rect)

Draw draws the Button to the image within bounds.

func (*Button) Update

func (b *Button) Update()

Update sets b.Hover according to the current mouse position and the position that the last call to Draw put the button at.

func (*Button) Weight

func (b *Button) Weight() float64

Weight returns the relative weight for allocating space within a container.

type Drawer

type Drawer interface {
	Draw(dst *ebiten.Image, bounds geo.Rect)
}

Drawer provides the function Draw which draws an element to an image within a specified bounding rectangle.

type HorizontalContainer

type HorizontalContainer struct {
	Elements []WeightedDrawer
	Wt       float64
}

HorizontalContainer is a container that orders each of its elements horizontally. Their heights will be the full height of the bounding rectangle given to Draw and their widths will be determined by their Weights relative to the other elements.

func (*HorizontalContainer) Draw

func (h *HorizontalContainer) Draw(dst *ebiten.Image, bounds geo.Rect)

Draw draws all of the container's elements to dst within bounds.

func (*HorizontalContainer) Weight

func (h *HorizontalContainer) Weight() float64

Weight returns the relative weight of the container so that containers may be nested.

type Text

type Text struct {
	Anchor Anchor
	Text   string
	Color  color.Color
	Face   font.Face
	Wt     float64
}

Text is an element that contains text.

func (*Text) Draw

func (t *Text) Draw(dst *ebiten.Image, bounds geo.Rect)

Draw draws the Text to the image within bounds.

func (*Text) Weight

func (t *Text) Weight() float64

Weight returns the relative weight for allocating space within a container.

type VerticalContainer

type VerticalContainer struct {
	Elements []WeightedDrawer
	Wt       float64
}

VerticalContainer is a container that orders each of its elements vertically. Their widths will be the full width of the bounding rectangle given to Draw and their heights will be determined by their Weights relative to the other elements.

func (*VerticalContainer) Draw

func (v *VerticalContainer) Draw(dst *ebiten.Image, bounds geo.Rect)

Draw draws all of the container's elements to dst within bounds.

func (*VerticalContainer) Weight

func (v *VerticalContainer) Weight() float64

Weight returns the relative weight of the container so that containers may be nested.

type Weighted

type Weighted interface {
	Weight() float64
}

Weighted provides the function Weight which returns the relative space an element would like to take up.

type WeightedDrawer

type WeightedDrawer interface {
	Weighted
	Drawer
}

WeightedDrawer combines the Weighted and Drawer interfaces.

Jump to

Keyboard shortcuts

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