widget

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package widget draws the HUD of a game from an XML file.

NewWidgetByFile reads the file of the name from the assets and returns an actor drawing it over the level:

w, err := widget.NewWidgetByFile("mainwidget")
lv.Add(w)

The file holds nested boxes and texts, and every element can be found again by its name, so that the game updates it while playing:

hp := widget.GetWidgetObjectByNameP[*widget.WidgetText]("mainwidget", "HPText")
hp.Text = "3"

Sizes are given in percent of the screen height, so a widget keeps its proportions on any window size and in fullscreen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetWidgetObjectByName

func GetWidgetObjectByName[T WidgetObjecter](actorName string, objectName string) (object T, ok bool)

func GetWidgetObjectByNameP

func GetWidgetObjectByNameP[T WidgetObjecter](actorName string, objectName string) T

Types

type Widget

func NewWidgetByFile

func NewWidgetByFile(name string) (*Widget, error)

func (*Widget) Draw

func (a *Widget) Draw(screen *ebiten.Image)

func (*Widget) ZOrder

func (a *Widget) ZOrder() int

type WidgetBase

type WidgetBase struct {
	Name            string
	Origin          utility.Vector
	Offset          utility.Vector
	Margin          utility.Inset
	Padding         utility.Inset
	IsHide          bool
	BorderWidth     float64
	BorderColor     color.Color
	BackgroundColor color.Color
	ForegroundColor color.Color
	// contains filtered or unexported fields
}

func (*WidgetBase) BackgroundToForegroundArea

func (w *WidgetBase) BackgroundToForegroundArea(screenSize *utility.Vector, out *utility.RectangleF)

func (*WidgetBase) DrawBackground

func (w *WidgetBase) DrawBackground(screen *ebiten.Image, preferredArea utility.RectangleF)

func (*WidgetBase) GetAlignedArea

func (w *WidgetBase) GetAlignedArea(screenArea *utility.RectangleF, outerArea *utility.RectangleF, innerSize utility.Vector) (innerArea *utility.RectangleF)

func (*WidgetBase) GetFontFamilies

func (w *WidgetBase) GetFontFamilies() []*text.GoTextFaceSource

func (*WidgetBase) GetFontSize

func (w *WidgetBase) GetFontSize() *float64

func (*WidgetBase) GetName

func (w *WidgetBase) GetName() string

func (*WidgetBase) GetTextFace

func (w *WidgetBase) GetTextFace(screenSize *utility.Vector) text.Face

func (*WidgetBase) GetWidgetObject

func (w *WidgetBase) GetWidgetObject(name string) WidgetObjecter

func (*WidgetBase) Init

func (w *WidgetBase) Init(inherits WidgetBase)

func (*WidgetBase) MinSize

func (w *WidgetBase) MinSize(screenSize *utility.Vector) utility.Vector

func (*WidgetBase) SetFontFamilies

func (w *WidgetBase) SetFontFamilies(fontFamilies []*text.GoTextFaceSource)

func (*WidgetBase) SetFontSize

func (w *WidgetBase) SetFontSize(fontSize *float64)

type WidgetBaseXML

type WidgetBaseXML struct {
	Name            string   `xml:"name,attr"`
	Origin          string   `xml:"origin,attr"`
	Offset          string   `xml:"offset,attr"`
	Margin          string   `xml:"margin,attr"`
	Padding         string   `xml:"padding,attr"`
	IsHide          bool     `xml:"hide,attr"`
	BorderWidth     float64  `xml:"bdwidth,attr"`
	BorderColor     string   `xml:"bdcolor,attr"`
	BackgroundColor string   `xml:"bgcolor,attr"`
	ForegroundColor string   `xml:"fgcolor,attr"`
	FontFiles       *string  `xml:"fontfiles,attr"`
	FontSize        *float64 `xml:"fontsize,attr"`
}

func (WidgetBaseXML) Convert

func (x WidgetBaseXML) Convert() *WidgetBase

type WidgetButton

type WidgetButton struct {
	*WidgetText
}

type WidgetButtonXML

type WidgetButtonXML struct {
	WidgetBaseXML
	Text string `xml:",chardata"`
}

func (WidgetButtonXML) Convert

func (x WidgetButtonXML) Convert() *WidgetButton

type WidgetContainerBase

type WidgetContainerBase struct {
	*WidgetBase
	Children []WidgetObjecter
}

func (*WidgetContainerBase) GetWidgetObject

func (w *WidgetContainerBase) GetWidgetObject(name string) WidgetObjecter

func (*WidgetContainerBase) Init

func (w *WidgetContainerBase) Init(inherits WidgetBase)

func (*WidgetContainerBase) SetFontFamilies

func (w *WidgetContainerBase) SetFontFamilies(fontFamilies []*text.GoTextFaceSource)

func (*WidgetContainerBase) SetFontSize

func (w *WidgetContainerBase) SetFontSize(fontSize *float64)

type WidgetContainerBaseXML

type WidgetContainerBaseXML struct {
	WidgetBaseXML
	HBoxes  []WidgetHBoxXML   `xml:"hbox"`
	VBoxes  []WidgetVBoxXML   `xml:"vbox"`
	Texts   []WidgetTextXML   `xml:"text"`
	Buttons []WidgetButtonXML `xml:"button"`
}

func (WidgetContainerBaseXML) Convert

func (x WidgetContainerBaseXML) Convert() []WidgetObjecter

type WidgetHBox

type WidgetHBox struct {
	*WidgetContainerBase
}

func (*WidgetHBox) Draw

func (w *WidgetHBox) Draw(screen *ebiten.Image, preferredArea utility.RectangleF)

func (*WidgetHBox) MinSize

func (w *WidgetHBox) MinSize(screenSize *utility.Vector) utility.Vector

type WidgetHBoxXML

type WidgetHBoxXML struct {
	WidgetContainerBaseXML
}

func (WidgetHBoxXML) Convert

func (x WidgetHBoxXML) Convert() *WidgetHBox

type WidgetObjecter

type WidgetObjecter interface {
	Init(inherits WidgetBase)
	GetFontFamilies() []*text.GoTextFaceSource
	GetFontSize() *float64
	SetFontFamilies(fontFamilies []*text.GoTextFaceSource)
	SetFontSize(fontSize *float64)
	GetName() string
	GetWidgetObject(name string) WidgetObjecter
	MinSize(screenSize *utility.Vector) utility.Vector
	Draw(screen *ebiten.Image, preferredArea utility.RectangleF)
}

type WidgetText

type WidgetText struct {
	*WidgetBase
	Text string
}

func (*WidgetText) Draw

func (w *WidgetText) Draw(screen *ebiten.Image, preferredArea utility.RectangleF)

func (*WidgetText) MinSize

func (w *WidgetText) MinSize(screenSize *utility.Vector) utility.Vector

type WidgetTextXML

type WidgetTextXML struct {
	WidgetBaseXML
	Text string `xml:",chardata"`
}

func (WidgetTextXML) Convert

func (x WidgetTextXML) Convert() *WidgetText

type WidgetVBox

type WidgetVBox struct {
	*WidgetContainerBase
}

func (*WidgetVBox) Draw

func (w *WidgetVBox) Draw(screen *ebiten.Image, preferredArea utility.RectangleF)

func (*WidgetVBox) MinSize

func (w *WidgetVBox) MinSize(screenSize *utility.Vector) utility.Vector

type WidgetVBoxXML

type WidgetVBoxXML struct {
	WidgetContainerBaseXML
}

func (WidgetVBoxXML) Convert

func (x WidgetVBoxXML) Convert() *WidgetVBox

type WidgetXML

type WidgetXML struct {
	WidgetContainerBaseXML
	Version int `xml:"version,attr"`
}

func (WidgetXML) ToActor

func (x WidgetXML) ToActor(name string) *Widget

Jump to

Keyboard shortcuts

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