ui

package
v0.0.0-...-47a16e8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LetterSpacing      = 1
	SpaceWidth         = 4
	TextPadding        = 1
	ButtonHeight       = 15
	DefaultButtonWidth = 90
)

Variables

This section is empty.

Functions

func ButtonBackground

func ButtonBackground(mgr *ecs.World, w, h int, l, t float64, layer int, absolute bool) ecs.Entity

ButtonBackground constructs a new background for a button. It visual only and contains no interaction.

func EvaluateIfExpression

func EvaluateIfExpression(expr string, data interface{}) bool

func LineSpacing

func LineSpacing(l TextSize) int

func Panel

func Panel(mgr *ecs.World, w, h int, l, t float64, layer int, absolute bool) ecs.Entity

Panel constructs a new UI panel. DEPRECATED! Use a UI Component instead.

func Resolve

func Resolve(text string, data interface{}) (string, error)

Resolve the value of text by executing it as a template with the provided data source. Values like "45" are returned directly, while value like {{ .Age }} are resolved by pulling the field (if it exists) with the name "Age" from data.

func ResolveInt

func ResolveInt(text string, data interface{}) (int, error)

ResolveInt functions like Resolve, but returns an integral value.

Types

type AttributeMap

type AttributeMap map[string]string

func (AttributeMap) Align

func (m AttributeMap) Align() string

func (AttributeMap) BottomPadding

func (m AttributeMap) BottomPadding() int

func (AttributeMap) FontLayout

func (m AttributeMap) FontLayout() TextLayout

func (AttributeMap) FontSize

func (m AttributeMap) FontSize() TextSize

func (AttributeMap) Height

func (m AttributeMap) Height() int

func (AttributeMap) Intangible

func (m AttributeMap) Intangible() bool

func (AttributeMap) LeftPadding

func (m AttributeMap) LeftPadding() int

func (AttributeMap) RightPadding

func (m AttributeMap) RightPadding() int

func (AttributeMap) TopPadding

func (m AttributeMap) TopPadding() int

func (AttributeMap) Twelfths

func (m AttributeMap) Twelfths() int

func (AttributeMap) Valign

func (m AttributeMap) Valign() string

func (AttributeMap) Width

func (m AttributeMap) Width() int

func (AttributeMap) X

func (m AttributeMap) X() int

func (AttributeMap) Y

func (m AttributeMap) Y() int

type ButtonRenderInstruction

type ButtonRenderInstruction struct {
	Active bool
	Bounds image.Rectangle
	Label  string
}

type Character

type Character struct {
	Raw                 rune
	Width, Height, X, Y int
}

type Element

type Element struct {
	Type       ElementType
	Attributes AttributeMap

	Children []*Element
}

type ElementType

type ElementType int
const (
	UIElement ElementType = iota
	PanelElement
	PaddingElement
	ColumnElement
	TextElement
	ButtonElement
	ImageElement
	IfElement
	RangeElement
)

func (ElementType) String

func (i ElementType) String() string

type ImageRenderInstruction

type ImageRenderInstruction struct {
	Texture  string
	From     image.Rectangle
	AtX, AtY float64
}

type Interact

type Interact struct {
	X, Y                 float64
	AbsoluteX, AbsoluteY float64
}

Interact happens when a UIInteract event is unhandled by any UI.

func (Interact) Type

func (Interact) Type() event.Type

Type of the Event.

type Interactive

type Interactive struct {
	W, H    float64
	Trigger func(x, y float64)
}

Interactive tags Components that can be interacted with in some way. Trigger is a function that is provided the x,y coordinate of the click either in world or screen coordinates, depending on the Position of the Interactive.

func (*Interactive) Type

func (*Interactive) Type() string

Type of this Component.

type InteractiveRegion

type InteractiveRegion struct {
	Bounds  image.Rectangle
	Handler func()
}

type InteractiveSystem

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

InteractiveSystem pumps events through Interactives.

func NewInteractiveSystem

func NewInteractiveSystem(mgr *ecs.World, bus *event.Bus) *InteractiveSystem

NewInteractiveSystem creates a new InteractiveSystem.

func (*InteractiveSystem) Handle

func (is *InteractiveSystem) Handle(ev *Interact)

Handle an Interact event.

type Line

type Line []Word

func SplitLines

func SplitLines(lines []Line, width int) []Line

func (Line) String

func (l Line) String() string

func (Line) Width

func (l Line) Width() int

Width of a Line is the sum of the widths of it's Words plus SpaceWidth times the number of Words minus one.

type PanelRenderInstruction

type PanelRenderInstruction struct {
	Bounds image.Rectangle
}

type RenderInstruction

type RenderInstruction interface {
}

type Text

type Text struct {
	Lines []Line
	// Size              TextSize
	BitmapFontTexture string
}

Text is a metadata enriched version of a standard string, that has not been laid out.

func NewText

func NewText(value string, size TextSize) *Text

type TextLayout

type TextLayout int
const (
	TextLayoutLeft TextLayout = iota
	TextLayoutRight
	TextLayoutJustify
	TextLayoutCenter
)

type TextRenderInstruction

type TextRenderInstruction struct {
	Text   string
	Size   TextSize
	Bounds image.Rectangle
	Layout TextLayout
}

type TextSize

type TextSize int
const (
	TextSizeNormal TextSize = iota
	TextSizeSmall
)

type UI

type UI struct {
	Doc *Element

	Data interface{}
	// contains filtered or unexported fields
}

UI is a Component that represents a UI. The stutter is unfortunate ...

func NewUI

func NewUI(r io.Reader) *UI

NewUI construct a new UI Component from a declared XML template. You're responsible for assigning Data to the Component before rendering it.

func (*UI) RenderInstructions

func (c *UI) RenderInstructions() []RenderInstruction

func (*UI) Type

func (*UI) Type() string

Type of this Component.

type UIInteract

type UIInteract struct {
	X, Y                 float64
	AbsoluteX, AbsoluteY float64
}

UIInteract happens when the player interacts with the game by clicking with the mouse or tapping on the screen.

func (UIInteract) Type

func (UIInteract) Type() event.Type

Type of the Event.

type UISystem

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

func NewUISystem

func NewUISystem(mgr *ecs.World, bus *event.Bus) *UISystem

func (*UISystem) Handle

func (uis *UISystem) Handle(ev *UIInteract)

func (*UISystem) Update

func (sys *UISystem) Update() error

type Word

type Word struct {
	Characters []Character
}

func (Word) String

func (w Word) String() string

func (*Word) Width

func (w *Word) Width() int

Width of a Word is the sum of the widths of it's characters plus LetterSpacing times the number of characters minus one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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