ui

package
v0.0.0-...-03afc55 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ui provides methods to draw a user interface onto the the screen and manage resizing.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DrawMode is the scaling mode used.
	DrawMode = Scaled
	// Scale controls the scaling manually when DrawModel is Unscaled
	Scale = 1.0
)
View Source
var ClickSound func()

ClickSound is the method that will be added to all buttons to play a click sound

Functions

func AddDrawable

func AddDrawable(d Drawable)

AddDrawable adds the drawable to the draw list.

func Click

func Click(x, y float64, width, height int)

Click calls Click on all interactables at the passed location.

func CycleFocus

func CycleFocus()

CycleFocus changes the focus to the next drawable

func Draw

func Draw(width, height int, delta float64)

Draw draws all drawables in the draw list to the screen.

func ForceDraw

func ForceDraw()

func HandleChar

func HandleChar(w *glfw.Window, char rune)

HandleChar passes the input to the focused drawable

func HandleKey

func HandleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey)

HandleKey passes the input to the focused drawable

func Hover

func Hover(x, y float64, width, height int)

Hover calls Hover on all interactables at the passed location.

func Intersects

func Intersects(d Drawable, x, y float64, width, height int) (float64, float64, bool)

Intersects returns whether the point x,y intersects with the drawable

func Remove

func Remove(d Drawable)

Remove removes the drawable from the screen.

Types

type AttachPoint

type AttachPoint int

AttachPoint is a side of the screen that an element can be attached to

const (
	Top, Left AttachPoint = iota, iota
	Middle, Center
	Bottom, Right
)

Attachment points

VAlign, HAlign

type Button

type Button struct {
	// contains filtered or unexported fields
}

Button is a drawable that draws a button.

func NewButton

func NewButton(x, y, w, h float64) *Button

NewButton creates a new Button drawable.

func (*Button) AddClick

func (b *Button) AddClick(f func())

AddClick adds a function to be called when the button is clicked

func (*Button) AddHover

func (b *Button) AddHover(f func(over bool))

AddHover adds a function to be called when the button is hovered

func (*Button) Attach

func (b *Button) Attach(vAttach, hAttach AttachPoint) *Button

Attach changes the location where this is attached to.

func (*Button) AttachTo

func (b *Button) AttachTo(d Drawable)

func (*Button) AttachedTo

func (b *Button) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*Button) Attachment

func (b *Button) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*Button) Click

func (b *Button) Click(r Region, x, y float64)

func (*Button) Disabled

func (b *Button) Disabled() bool

func (*Button) Draw

func (b *Button) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*Button) Height

func (b *Button) Height() float64

func (*Button) Hover

func (b *Button) Hover(r Region, x, y float64, over bool)

func (*Button) Layer

func (b *Button) Layer() int

func (*Button) Offset

func (b *Button) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*Button) OnRemove

func (b *Button) OnRemove(d Drawable)

func (*Button) Remove

func (b *Button) Remove()

Remove removes the Button element from the draw list.

func (*Button) SetDisabled

func (b *Button) SetDisabled(d bool)

func (*Button) SetDraw

func (b *Button) SetDraw(shouldDraw bool)

func (*Button) SetHeight

func (b *Button) SetHeight(h float64)

func (*Button) SetLayer

func (b *Button) SetLayer(l int)

func (*Button) SetRemoveHook

func (b *Button) SetRemoveHook(r func(Drawable))

func (*Button) SetWidth

func (b *Button) SetWidth(w float64)

func (*Button) SetX

func (b *Button) SetX(x float64)

func (*Button) SetY

func (b *Button) SetY(y float64)

func (*Button) ShouldDraw

func (b *Button) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*Button) Size

func (b *Button) Size() (float64, float64)

Size returns the size of this drawable.

func (*Button) Width

func (b *Button) Width() float64

func (*Button) X

func (b *Button) X() float64

func (*Button) Y

func (b *Button) Y() float64

type Container

type Container struct {
	HoverFunc func(over bool)
	ClickFunc func()
	// contains filtered or unexported fields
}

Container is a drawable that is used for aligning other drawables. Should never be drawn.

func NewContainer

func NewContainer(x, y, w, h float64) *Container

func (*Container) Attach

func (c *Container) Attach(vAttach, hAttach AttachPoint) *Container

Attach changes the location where this is attached to.

func (*Container) AttachTo

func (b *Container) AttachTo(d Drawable)

func (*Container) AttachedTo

func (b *Container) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*Container) Attachment

func (b *Container) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*Container) Click

func (c *Container) Click(r Region, x, y float64)

func (*Container) Draw

func (c *Container) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*Container) Height

func (c *Container) Height() float64

func (*Container) Hover

func (c *Container) Hover(r Region, x, y float64, over bool)

func (*Container) Layer

func (b *Container) Layer() int

func (*Container) Offset

func (c *Container) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*Container) OnRemove

func (b *Container) OnRemove(d Drawable)

func (*Container) SetDraw

func (b *Container) SetDraw(shouldDraw bool)

func (*Container) SetHeight

func (c *Container) SetHeight(h float64)

func (*Container) SetLayer

func (b *Container) SetLayer(l int)

func (*Container) SetRemoveHook

func (b *Container) SetRemoveHook(r func(Drawable))

func (*Container) SetWidth

func (c *Container) SetWidth(w float64)

func (*Container) SetX

func (c *Container) SetX(x float64)

func (*Container) SetY

func (c *Container) SetY(y float64)

func (*Container) ShouldDraw

func (b *Container) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*Container) Size

func (c *Container) Size() (float64, float64)

Size returns the size of this drawable.

func (*Container) Width

func (c *Container) Width() float64

func (*Container) X

func (c *Container) X() float64

func (*Container) Y

func (c *Container) Y() float64

type Drawable

type Drawable interface {
	Draw(r Region, delta float64)
	Size() (float64, float64)
	// Offset is the offset from the attachment point on
	// each axis
	Offset() (float64, float64)
	ShouldDraw() bool
	AttachedTo() Drawable
	AttachTo(d Drawable)
	Attachment() (vAttach, hAttach AttachPoint)
	Layer() int
	OnRemove(d Drawable)
	SetRemoveHook(func(Drawable))
	// contains filtered or unexported methods
}

Drawable is a scalable element that can be drawn to an area.

type Formatted

type Formatted struct {
	MaxWidth float64

	Width, Height float64
	Lines         int

	Text []*Text
	// contains filtered or unexported fields
}

Formatted is a drawable that draws a string.

func NewFormatted

func NewFormatted(val format.AnyComponent, x, y float64) *Formatted

NewFormatted creates a new Formatted drawable.

func NewFormattedWidth

func NewFormattedWidth(val format.AnyComponent, x, y, width float64) *Formatted

NewFormattedWidth creates a new Formatted drawable with a max width.

func (*Formatted) Attach

func (f *Formatted) Attach(vAttach, hAttach AttachPoint) *Formatted

Attach changes the location where this is attached to.

func (*Formatted) AttachTo

func (b *Formatted) AttachTo(d Drawable)

func (*Formatted) AttachedTo

func (b *Formatted) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*Formatted) Attachment

func (b *Formatted) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*Formatted) Draw

func (f *Formatted) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*Formatted) Layer

func (b *Formatted) Layer() int

func (*Formatted) Offset

func (f *Formatted) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*Formatted) OnRemove

func (b *Formatted) OnRemove(d Drawable)

func (*Formatted) Remove

func (f *Formatted) Remove()

Remove removes the Formatted element from the draw list.

func (*Formatted) ScaleX

func (f *Formatted) ScaleX() float64

func (*Formatted) ScaleY

func (f *Formatted) ScaleY() float64

func (*Formatted) SetDraw

func (b *Formatted) SetDraw(shouldDraw bool)

func (*Formatted) SetLayer

func (b *Formatted) SetLayer(l int)

func (*Formatted) SetRemoveHook

func (b *Formatted) SetRemoveHook(r func(Drawable))

func (*Formatted) SetScaleX

func (f *Formatted) SetScaleX(s float64)

func (*Formatted) SetScaleY

func (f *Formatted) SetScaleY(s float64)

func (*Formatted) SetX

func (f *Formatted) SetX(x float64)

func (*Formatted) SetY

func (f *Formatted) SetY(y float64)

func (*Formatted) ShouldDraw

func (b *Formatted) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*Formatted) Size

func (f *Formatted) Size() (float64, float64)

Size returns the size of this drawable.

func (*Formatted) Update

func (f *Formatted) Update(val format.AnyComponent)

Update updates the component drawn by this drawable.

func (*Formatted) X

func (f *Formatted) X() float64

func (*Formatted) Y

func (f *Formatted) Y() float64

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image is a drawable that draws a texture.

func NewImage

func NewImage(texture render.TextureInfo, x, y, w, h, tx, ty, tw, th float64, r, g, b int) *Image

NewImage creates a new image drawable.

func (*Image) A

func (i *Image) A() int

func (*Image) Attach

func (i *Image) Attach(vAttach, hAttach AttachPoint) *Image

Attach changes the location where this is attached to.

func (*Image) AttachTo

func (b *Image) AttachTo(d Drawable)

func (*Image) AttachedTo

func (b *Image) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*Image) Attachment

func (b *Image) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*Image) B

func (i *Image) B() int

func (*Image) Draw

func (i *Image) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*Image) G

func (i *Image) G() int

func (*Image) Height

func (i *Image) Height() float64

func (*Image) Layer

func (b *Image) Layer() int

func (*Image) Offset

func (i *Image) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*Image) OnRemove

func (b *Image) OnRemove(d Drawable)

func (*Image) R

func (i *Image) R() int

func (*Image) Remove

func (i *Image) Remove()

Remove removes the image element from the draw list.

func (*Image) SetA

func (i *Image) SetA(a int)

func (*Image) SetB

func (i *Image) SetB(b int)

func (*Image) SetDraw

func (b *Image) SetDraw(shouldDraw bool)

func (*Image) SetG

func (i *Image) SetG(g int)

func (*Image) SetHeight

func (i *Image) SetHeight(h float64)

func (*Image) SetLayer

func (b *Image) SetLayer(l int)

func (*Image) SetR

func (i *Image) SetR(r int)

func (*Image) SetRemoveHook

func (b *Image) SetRemoveHook(r func(Drawable))

func (*Image) SetTexture

func (i *Image) SetTexture(t render.TextureInfo)

func (*Image) SetTextureHeight

func (i *Image) SetTextureHeight(h float64)

func (*Image) SetTextureWidth

func (i *Image) SetTextureWidth(w float64)

func (*Image) SetTextureX

func (i *Image) SetTextureX(x float64)

func (*Image) SetTextureY

func (i *Image) SetTextureY(y float64)

func (*Image) SetWidth

func (i *Image) SetWidth(w float64)

func (*Image) SetX

func (i *Image) SetX(x float64)

func (*Image) SetY

func (i *Image) SetY(y float64)

func (*Image) ShouldDraw

func (b *Image) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*Image) Size

func (i *Image) Size() (float64, float64)

Size returns the size of this drawable.

func (*Image) Texture

func (i *Image) Texture() render.TextureInfo

func (*Image) TextureHeight

func (i *Image) TextureHeight() float64

func (*Image) TextureWidth

func (i *Image) TextureWidth() float64

func (*Image) TextureX

func (i *Image) TextureX() float64

func (*Image) TextureY

func (i *Image) TextureY() float64

func (*Image) Width

func (i *Image) Width() float64

func (*Image) X

func (i *Image) X() float64

func (*Image) Y

func (i *Image) Y() float64

type Interactable

type Interactable interface {
	Click(r Region, x, y float64)
	Hover(r Region, x, y float64, over bool)
}

type Mode

type Mode int

Mode defines the way the ui is rendered.

const (
	Scaled Mode = iota
	Unscaled
)

Valid modes

type Model

type Model struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel(x, y float64, verts []*ModelVertex, mat mgl32.Mat4) *Model

func (*Model) Attach

func (m *Model) Attach(vAttach, hAttach AttachPoint) *Model

Attach changes the location where this is attached to.

func (*Model) AttachTo

func (b *Model) AttachTo(d Drawable)

func (*Model) AttachedTo

func (b *Model) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*Model) Attachment

func (b *Model) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*Model) Draw

func (m *Model) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*Model) Layer

func (b *Model) Layer() int

func (*Model) Offset

func (m *Model) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*Model) OnRemove

func (b *Model) OnRemove(d Drawable)

func (*Model) Remove

func (m *Model) Remove()

Remove removes the image element from the draw list.

func (*Model) SetDraw

func (b *Model) SetDraw(shouldDraw bool)

func (*Model) SetLayer

func (b *Model) SetLayer(l int)

func (*Model) SetRemoveHook

func (b *Model) SetRemoveHook(r func(Drawable))

func (*Model) SetX

func (m *Model) SetX(x float64)

func (*Model) SetY

func (m *Model) SetY(y float64)

func (*Model) ShouldDraw

func (b *Model) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*Model) Size

func (m *Model) Size() (float64, float64)

Size returns the size of this drawable.

func (*Model) X

func (m *Model) X() float64

func (*Model) Y

func (m *Model) Y() float64

type ModelVertex

type ModelVertex struct {
	X, Y, Z                    float32
	TX, TY, TW, TH             uint16
	TOffsetX, TOffsetY, TAtlas int16
	R, G, B, A                 byte
}

type Region

type Region struct {
	X, Y, W, H float64
}

Region is an area for a Drawable to draw to

type Text

type Text struct {
	Width float64
	// contains filtered or unexported fields
}

Text is a drawable that draws a string.

func NewText

func NewText(val string, x, y float64, r, g, b int) *Text

NewText creates a new Text drawable.

func (*Text) A

func (t *Text) A() int

func (*Text) Attach

func (t *Text) Attach(vAttach, hAttach AttachPoint) *Text

Attach changes the location where this is attached to.

func (*Text) AttachTo

func (b *Text) AttachTo(d Drawable)

func (*Text) AttachedTo

func (b *Text) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*Text) Attachment

func (b *Text) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*Text) B

func (t *Text) B() int

func (*Text) Draw

func (t *Text) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*Text) G

func (t *Text) G() int

func (*Text) Layer

func (b *Text) Layer() int

func (*Text) Offset

func (t *Text) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*Text) OnRemove

func (b *Text) OnRemove(d Drawable)

func (*Text) R

func (t *Text) R() int

func (*Text) Remove

func (t *Text) Remove()

Remove removes the text element from the draw list.

func (*Text) Rotation

func (t *Text) Rotation() float64

func (*Text) ScaleX

func (t *Text) ScaleX() float64

func (*Text) ScaleY

func (t *Text) ScaleY() float64

func (*Text) SetA

func (t *Text) SetA(a int)

func (*Text) SetB

func (t *Text) SetB(b int)

func (*Text) SetDraw

func (b *Text) SetDraw(shouldDraw bool)

func (*Text) SetG

func (t *Text) SetG(g int)

func (*Text) SetLayer

func (b *Text) SetLayer(l int)

func (*Text) SetR

func (t *Text) SetR(r int)

func (*Text) SetRemoveHook

func (b *Text) SetRemoveHook(r func(Drawable))

func (*Text) SetRotation

func (t *Text) SetRotation(r float64)

func (*Text) SetScaleX

func (t *Text) SetScaleX(s float64)

func (*Text) SetScaleY

func (t *Text) SetScaleY(s float64)

func (*Text) SetX

func (t *Text) SetX(x float64)

func (*Text) SetY

func (t *Text) SetY(y float64)

func (*Text) ShouldDraw

func (b *Text) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*Text) Size

func (t *Text) Size() (float64, float64)

Size returns the size of this drawable.

func (*Text) Update

func (t *Text) Update(val string)

Update updates the string drawn by this drawable.

func (*Text) Value

func (t *Text) Value() string

func (*Text) X

func (t *Text) X() float64

func (*Text) Y

func (t *Text) Y() float64

type TextBox

type TextBox struct {
	SubmitFunc func()
	// contains filtered or unexported fields
}

TextBox is a drawable that allows for input.

func NewTextBox

func NewTextBox(x, y, w, h float64) *TextBox

NewTextBox creates a new TextBox drawable.

func (*TextBox) Attach

func (t *TextBox) Attach(vAttach, hAttach AttachPoint) *TextBox

Attach changes the location where this is attached to.

func (*TextBox) AttachTo

func (b *TextBox) AttachTo(d Drawable)

func (*TextBox) AttachedTo

func (b *TextBox) AttachedTo() Drawable

AttachedTo returns the Drawable this is attached to or nil.

func (*TextBox) Attachment

func (b *TextBox) Attachment() (vAttach, hAttach AttachPoint)

Attachment returns the sides where this element is attached too.

func (*TextBox) Click

func (t *TextBox) Click(r Region, x, y float64)

func (*TextBox) Draw

func (t *TextBox) Draw(r Region, delta float64)

Draw draws this to the target region.

func (*TextBox) Height

func (t *TextBox) Height() float64

func (*TextBox) Hover

func (t *TextBox) Hover(r Region, x, y float64, over bool)

func (*TextBox) Layer

func (b *TextBox) Layer() int

func (*TextBox) Offset

func (t *TextBox) Offset() (float64, float64)

Offset returns the offset of this drawable from the attachment point.

func (*TextBox) OnRemove

func (b *TextBox) OnRemove(d Drawable)

func (*TextBox) Password

func (t *TextBox) Password() bool

func (*TextBox) Remove

func (t *TextBox) Remove()

Remove removes the textbox element from the draw list.

func (*TextBox) SetDraw

func (b *TextBox) SetDraw(shouldDraw bool)

func (*TextBox) SetHeight

func (t *TextBox) SetHeight(h float64)

func (*TextBox) SetLayer

func (b *TextBox) SetLayer(l int)

func (*TextBox) SetPassword

func (t *TextBox) SetPassword(p bool)

func (*TextBox) SetRemoveHook

func (b *TextBox) SetRemoveHook(r func(Drawable))

func (*TextBox) SetWidth

func (t *TextBox) SetWidth(w float64)

func (*TextBox) SetX

func (t *TextBox) SetX(x float64)

func (*TextBox) SetY

func (t *TextBox) SetY(y float64)

func (*TextBox) ShouldDraw

func (b *TextBox) ShouldDraw() bool

ShouldDraw returns whether this should be drawn at this time.

func (*TextBox) Size

func (t *TextBox) Size() (float64, float64)

Size returns the size of this drawable.

func (*TextBox) Update

func (t *TextBox) Update(val string)

Update updates the string drawn by this drawable.

func (*TextBox) Value

func (t *TextBox) Value() string

func (*TextBox) Width

func (t *TextBox) Width() float64

func (*TextBox) X

func (t *TextBox) X() float64

func (*TextBox) Y

func (t *TextBox) Y() float64

Directories

Path Synopsis
Package scene provides methods to manage and load multiple ui scenes.
Package scene provides methods to manage and load multiple ui scenes.

Jump to

Keyboard shortcuts

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