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 ¶
- func GetWidgetObjectByName[T WidgetObjecter](actorName string, objectName string) (object T, ok bool)
- func GetWidgetObjectByNameP[T WidgetObjecter](actorName string, objectName string) T
- type Widget
- type WidgetBase
- func (w *WidgetBase) BackgroundToForegroundArea(screenSize *utility.Vector, out *utility.RectangleF)
- func (w *WidgetBase) DrawBackground(screen *ebiten.Image, preferredArea utility.RectangleF)
- func (w *WidgetBase) GetAlignedArea(screenArea *utility.RectangleF, outerArea *utility.RectangleF, ...) (innerArea *utility.RectangleF)
- func (w *WidgetBase) GetFontFamilies() []*text.GoTextFaceSource
- func (w *WidgetBase) GetFontSize() *float64
- func (w *WidgetBase) GetName() string
- func (w *WidgetBase) GetTextFace(screenSize *utility.Vector) text.Face
- func (w *WidgetBase) GetWidgetObject(name string) WidgetObjecter
- func (w *WidgetBase) Init(inherits WidgetBase)
- func (w *WidgetBase) MinSize(screenSize *utility.Vector) utility.Vector
- func (w *WidgetBase) SetFontFamilies(fontFamilies []*text.GoTextFaceSource)
- func (w *WidgetBase) SetFontSize(fontSize *float64)
- type WidgetBaseXML
- type WidgetButton
- type WidgetButtonXML
- type WidgetContainerBase
- type WidgetContainerBaseXML
- type WidgetHBox
- type WidgetHBoxXML
- type WidgetObjecter
- type WidgetText
- type WidgetTextXML
- type WidgetVBox
- type WidgetVBoxXML
- type WidgetXML
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 ¶
type Widget struct {
*component.ActorCom
*component.DrawCom
*WidgetContainerBase
}
func NewWidgetByFile ¶
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)
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)
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)
type WidgetVBoxXML ¶
type WidgetVBoxXML struct {
WidgetContainerBaseXML
}
func (WidgetVBoxXML) Convert ¶
func (x WidgetVBoxXML) Convert() *WidgetVBox
Click to show internal directories.
Click to hide internal directories.