egui

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2019 License: Apache-2.0 Imports: 18 Imported by: 1

README

egui

Ebiten Graphical User Interface (and Framework)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSliceNameInvalid is returned when a slice name has invalid characters or too short
	ErrSliceNameInvalid = fmt.Errorf("slice name invalid")
	// ErrSliceAlreadyExists is returned when a slice already exists
	ErrSliceAlreadyExists = fmt.Errorf("slice already exists")
	// ErrSliceNotFound is returned when a slice is not loaded into the UI
	ErrSliceNotFound = fmt.Errorf("slice not found")
)
View Source
var (
	// ErrElementNameInvalid is returned when a element name has invalid characters or too short
	ErrElementNameInvalid = fmt.Errorf("element name invalid")
	// ErrElementAlreadyExists is returned when a element already exists
	ErrElementAlreadyExists = fmt.Errorf("element already exists")
	// ErrElementNotFound is returned when a element is not loaded into the UI
	ErrElementNotFound = fmt.Errorf("element not found")
	// ErrFontNameInvalid is returned when a font name has invalid characters or too short
	ErrFontNameInvalid = fmt.Errorf("font name invalid")
	// ErrFontAlreadyExists is returned when a font already exists
	ErrFontAlreadyExists = fmt.Errorf("font already exists")
	// ErrFontNotFound is returned when a font was not found
	ErrFontNotFound = fmt.Errorf("font not found")
	// ErrFontCannotRemoveDefault is returned when you attempt to delete a font currently set as default
	ErrFontCannotRemoveDefault = fmt.Errorf("font is default, cannot remove")
	// ErrImageNameInvalid is returned when a image name has invalid characters or too short
	ErrImageNameInvalid = fmt.Errorf("image name invalid")
	// ErrImageAlreadyExists is returned when a image already exists
	ErrImageAlreadyExists = fmt.Errorf("image already exists")
	// ErrImageNotFound is returned when a image was not found
	ErrImageNotFound = fmt.Errorf("image not found")
	// ErrSceneNameInvalid is returned when a scene name has invalid characters or too short
	ErrSceneNameInvalid = fmt.Errorf("scene name invalid")
	// ErrSceneAlreadyExists is returned when a Scene already exists
	ErrSceneAlreadyExists = fmt.Errorf("scene already exists")
	// ErrSceneNotFound is returned when a scene is not loaded into the UI
	ErrSceneNotFound = fmt.Errorf("scene not found")
)

Functions

func DrawNineSlicing added in v0.0.4

func DrawNineSlicing(dst, src *ebiten.Image, sliceKey *SliceKey, width int, height int, geoM *ebiten.GeoM, colorM *ebiten.ColorM)

DrawNineSlicing will render slicing data

Types

type Button

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

Button represents a UI Button element

func (*Button) IsDestroyed

func (e *Button) IsDestroyed() bool

IsDestroyed returns true when the element is flagged for deletion

func (*Button) IsEnabled added in v0.0.4

func (e *Button) IsEnabled() bool

IsEnabled returns true if a button is enabled

func (*Button) IsVisible

func (e *Button) IsVisible() bool

IsVisible returns true if mob is visible

func (*Button) LerpPosition

func (e *Button) LerpPosition(endPosition common.Vector, duration time.Duration, isDestroyed bool, endFunc func())

LerpPosition changes an element's position over duration

func (*Button) Name added in v0.0.4

func (e *Button) Name() string

Name returns a mob's name

func (*Button) RenderIndex added in v0.0.4

func (e *Button) RenderIndex() int64

RenderIndex returns the render index of element

func (*Button) SetEnabled added in v0.0.4

func (e *Button) SetEnabled(isEnabled bool)

SetEnabled changes if a button is enabled

func (*Button) SetIsDestroyed added in v0.0.4

func (e *Button) SetIsDestroyed(isDestroyed bool)

SetIsDestroyed sets an element to be destroyed on next update

func (*Button) SetOnPressFunction

func (e *Button) SetOnPressFunction(f func())

SetOnPressFunction lets you pass a function without the need of button handling

func (*Button) SetOnPressed

func (e *Button) SetOnPressed(f func(e *Button))

SetOnPressed sets a button state

func (*Button) SetRenderIndex added in v0.0.4

func (e *Button) SetRenderIndex(renderIndex int64)

SetRenderIndex sets the render index of element

func (*Button) SetShape

func (e *Button) SetShape(shape common.Rectangle)

SetShape sets an element's X/Y position as well as width/height

func (*Button) SetText added in v0.0.4

func (e *Button) SetText(text string)

SetText changes the text on the button

func (*Button) SetVisible added in v0.0.4

func (e *Button) SetVisible(isVisible bool)

SetVisible changes the visibility of a button

func (*Button) Shape

func (e *Button) Shape() *common.Rectangle

Shape returns an element's X/Y position as well as width/height

func (*Button) X added in v0.0.4

func (e *Button) X() float64

X returns the X position of a button

func (*Button) Y added in v0.0.4

func (e *Button) Y() float64

Y returns the Y position of a button

type Font added in v0.0.4

type Font struct {
	Face     font.Face
	Height   int
	Name     string
	Language language.Tag
	// contains filtered or unexported fields
}

Font contains related data for loading a font file

func (*Font) DrawText added in v0.0.4

func (f *Font) DrawText(dst *ebiten.Image, str string, ox, oy float64, scale float64, textAlign int, color color.Color, displayTextRuneCount int)

DrawText draws a text

type Frame

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

Frame represents a UI Frame element

func (*Frame) IsDestroyed

func (e *Frame) IsDestroyed() bool

IsDestroyed returns true when the element is flagged for deletion

func (*Frame) IsEnabled added in v0.0.4

func (e *Frame) IsEnabled() bool

IsEnabled returns true if a Frame is enabled

func (*Frame) IsVisible

func (e *Frame) IsVisible() bool

IsVisible returns true if mob is visible

func (*Frame) LerpPosition

func (e *Frame) LerpPosition(endPosition common.Vector, duration time.Duration, isDestroyed bool, endFunc func())

LerpPosition changes an element's position over duration

func (*Frame) Name added in v0.0.4

func (e *Frame) Name() string

Name returns a mob's name

func (*Frame) RenderIndex added in v0.0.4

func (e *Frame) RenderIndex() int64

RenderIndex returns the render index of element

func (*Frame) SetIsDestroyed added in v0.0.4

func (e *Frame) SetIsDestroyed(isDestroyed bool)

SetIsDestroyed sets an element to be destroyed on next update

func (*Frame) SetIsEnabled added in v0.0.4

func (e *Frame) SetIsEnabled(isEnabled bool)

SetIsEnabled changes if a Frame is enabled

func (*Frame) SetOnPressFunction

func (e *Frame) SetOnPressFunction(f func())

SetOnPressFunction lets you pass a function without the need of Frame handling

func (*Frame) SetOnPressed

func (e *Frame) SetOnPressed(f func(e *Frame))

SetOnPressed sets a Frame state

func (*Frame) SetRenderIndex added in v0.0.4

func (e *Frame) SetRenderIndex(renderIndex int64)

SetRenderIndex sets the render index of element

func (*Frame) SetShape

func (e *Frame) SetShape(shape common.Rectangle)

SetShape sets an element's X/Y position as well as width/height

func (*Frame) SetText added in v0.0.4

func (e *Frame) SetText(text string)

SetText changes the text on the Frame

func (*Frame) Shape

func (e *Frame) Shape() *common.Rectangle

Shape returns an element's X/Y position as well as width/height

type Image added in v0.0.4

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

Image represents a ebiten image with added details on how to render

func (*Image) AddSlice added in v0.0.4

func (img *Image) AddSlice(s *Slice) error

AddSlice adds a 9slicing to an image

func (*Image) Name added in v0.0.4

func (img *Image) Name() string

Name returns the image name

func (*Image) RemoveSlice added in v0.0.4

func (img *Image) RemoveSlice(s *Slice) error

RemoveSlice removes 9slicing data from an image

func (*Image) Slice added in v0.0.4

func (img *Image) Slice(name string) (*Slice, error)

Slice returns a 9 slice based on name

type Interfacer

type Interfacer interface {
	//TargetPositionUpdate(tp *common.Vector, duration time.Duration)
	IsEnabled() bool
	SetEnabled(isEnabled bool)
	IsVisible() bool
	SetVisible(isVisible bool)

	Name() string
	RenderIndex() int64
	SetRenderIndex(renderIndex int64)
	IsDestroyed() bool
	SetIsDestroyed(isDestroyed bool)
	SetText(text string)
	// Shape returns the shape of an element
	Shape() *common.Rectangle
	// SetShape sets the shape of an element
	SetShape(shape common.Rectangle)
	LerpPosition(endPosition common.Vector, duration time.Duration, isDestroyed bool, endFunc func())
	// contains filtered or unexported methods
}

Interfacer is a generic user interface wrapper

type Label

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

Label represents a UI label element

func (*Label) IsDestroyed

func (e *Label) IsDestroyed() bool

IsDestroyed returns true when the element is flagged for deletion

func (*Label) IsEnabled added in v0.0.4

func (e *Label) IsEnabled() bool

IsEnabled returns true if a button is enabled

func (*Label) IsVisible

func (e *Label) IsVisible() bool

IsVisible returns true if element should be shown

func (*Label) LerpColor

func (e *Label) LerpColor(endColor color.Color, duration time.Duration, isDestroyed bool, endFunc func())

LerpColor changes the label's color over duration

func (*Label) LerpPosition

func (e *Label) LerpPosition(endPosition common.Vector, duration time.Duration, isDestroyed bool, endFunc func())

LerpPosition changes an element's position over duration

func (*Label) Name added in v0.0.4

func (e *Label) Name() string

Name returns an element's name

func (*Label) RenderIndex added in v0.0.4

func (e *Label) RenderIndex() int64

RenderIndex returns the render index of element

func (*Label) SetEnabled added in v0.0.4

func (e *Label) SetEnabled(isEnabled bool)

SetEnabled changes if a button is enabled

func (*Label) SetIsDestroyed added in v0.0.4

func (e *Label) SetIsDestroyed(isDestroyed bool)

SetIsDestroyed sets an element to be destroyed on next update

func (*Label) SetOnPressFunction

func (e *Label) SetOnPressFunction(f func())

SetOnPressFunction lets you pass a function without the need of label handling

func (*Label) SetOnPressed

func (e *Label) SetOnPressed(f func(e *Label))

SetOnPressed sets a label state

func (*Label) SetRenderIndex added in v0.0.4

func (e *Label) SetRenderIndex(renderIndex int64)

SetRenderIndex sets the render index of element

func (*Label) SetShape

func (e *Label) SetShape(shape common.Rectangle)

SetShape sets an element's X/Y position as well as width/height

func (*Label) SetText added in v0.0.4

func (e *Label) SetText(text string)

SetText changes the text on the label

func (*Label) SetVisible added in v0.0.4

func (e *Label) SetVisible(isVisible bool)

SetVisible changes the visibility of a button

func (*Label) Shape

func (e *Label) Shape() *common.Rectangle

Shape returns an element's X/Y position as well as width/height

type Scene

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

Scene represents a layout of ui

func NewScene

func NewScene() (s *Scene)

NewScene initializes a new scene

func (*Scene) AddElement

func (s *Scene) AddElement(e Interfacer) error

AddElement adds an element to the scene list

func (*Scene) Element

func (s *Scene) Element(name string) (Interfacer, error)

Element returns an element based on name

func (*Scene) RemoveElement

func (s *Scene) RemoveElement(name string) error

RemoveElement flags an element to be removed next update

type Slice added in v0.0.4

type Slice struct {
	Name string      `xml:"id,attr"`
	Keys []*SliceKey `xml:"key"`
}

Slice represents a 9 slicing instruction set within an image

type SliceKey added in v0.0.4

type SliceKey struct {
	Frame  string  `xml:"frame,attr"`
	X      float64 `xml:"x,attr"`
	Y      float64 `xml:"y,attr"`
	W      float64 `xml:"w,attr"`
	H      float64 `xml:"h,attr"`
	CX     float64 `xml:"cx,attr"`
	CY     float64 `xml:"cy,attr"`
	CW     float64 `xml:"cw,attr"`
	CH     float64 `xml:"ch,attr"`
	PivotX float64 `xml:"px,attr"`
	PivotY float64 `xml:"py,attr"`
}

SliceKey represents each slice's key data

type UI

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

UI contains core game components

func NewUI

func NewUI(screenResolution image.Point, scale float64) (*UI, error)

NewUI instantiates a new User Interface

func (*UI) AddFont added in v0.0.4

func (u *UI) AddFont(font *Font) error

AddFont adds an font font to ui

func (*UI) AddImage added in v0.0.4

func (u *UI) AddImage(img *Image) error

AddImage adds an image image to ui

func (*UI) AddScene

func (u *UI) AddScene(name string, scene *Scene) error

AddScene appends a new scene to the UI

func (*UI) CurrentScene

func (u *UI) CurrentScene() *Scene

CurrentScene returns the current scene

func (*UI) DefaultFont added in v0.0.4

func (u *UI) DefaultFont(name string) error

DefaultFont returns the current default font

func (*UI) Font added in v0.0.4

func (u *UI) Font(name string) (*Font, error)

Font returns named font

func (*UI) Image added in v0.0.4

func (u *UI) Image(name string) (*Image, error)

Image returns a named image

func (*UI) NewButton

func (u *UI) NewButton(name string, scene string, text string, shape common.Rectangle, textColor color.Color, imageName string, pressedSliceName string, unpressedSliceName string) (*Button, error)

NewButton creates a new button instance

func (*UI) NewFontTTF added in v0.0.4

func (u *UI) NewFontTTF(name string, fontData []byte, opts *truetype.Options, r rune) (*Font, error)

NewFontTTF instantiates a truetype font. truetype.Parse() can be used to load a TTF to fontData

func (*UI) NewFrame

func (u *UI) NewFrame(name string, imageName string, text string, shape *common.Rectangle) (e *Frame, err error)

NewFrame creates a new Frame instance

func (*UI) NewImage added in v0.0.4

func (u *UI) NewImage(name string, f io.Reader, filter ebiten.Filter) (*Image, error)

NewImage adds a new image to egui

func (*UI) NewLabel

func (u *UI) NewLabel(name string, text string, shape common.Rectangle, color color.Color) (e *Label, err error)

NewLabel creates a new label instance

func (*UI) RemoveFont added in v0.0.4

func (u *UI) RemoveFont(font *Font) error

RemoveFont is used to unload and remove a font

func (*UI) Resolution

func (u *UI) Resolution() image.Point

Resolution returns the resolution

func (*UI) Scene

func (u *UI) Scene(name string) (*Scene, error)

Scene gets a scene

func (*UI) SetCurrentScene

func (u *UI) SetCurrentScene(name string) error

SetCurrentScene sets current scene

func (*UI) SetDefaultFont added in v0.0.4

func (u *UI) SetDefaultFont(name string) error

SetDefaultFont updates all elements to use a new default font

func (*UI) SetResolution

func (u *UI) SetResolution(resolution image.Point)

SetResolution changes the resolution of the UI

func (*UI) Update

func (u *UI) Update(image *ebiten.Image) error

Update updates all UI elements

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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