Documentation ¶
Index ¶
- Constants
- func ButtonNewEvent(e Button, window *pixelgl.Window)
- func CalculateHeight(parent Element, window *pixelgl.Window, bounds *pixel.Rect, ...) (height *float64)
- func CalculateMin(e Element, bounds *pixel.Rect, size pixel.Vec) (min *pixel.Vec)
- func CalculateWidth(parent Element, window *pixelgl.Window, bounds *pixel.Rect, ...) (width *float64)
- func Call(name string, e Element) error
- func ChildrenAreInitialised(e Layout) bool
- func DrawBkg(e Element, b Image)
- func DrawCanvasOntoParent(child *pixelgl.Canvas, parent *pixelgl.Canvas)
- func DrawImage(e Element, i Image)
- func DrawLayout(e Layout)
- func DrawText(e Element, t Text)
- func DrawUI(e Element, window *pixelgl.Window)
- func FullName(e Element, sep string, includeNamespace bool) (name string)
- func InitBkg(e Element, i Image) error
- func InitImage(e Element, i Image) error
- func InitText(e Element, t Text) error
- func InitUI(e Element, window *pixelgl.Window, bounds *pixel.Rect) error
- func Name(e Element, includeNamespace bool) (name string)
- func ParseAttr(t reflect.Type, v string) (reflect.Value, error)
- func Register(name xml.Name, reflectType reflect.Type, factory Factory)
- func RegisterAttrType(t reflect.Type, p AttrParser)
- func RegisterCallback(name string, c Callback)
- func SetAttrs(e Element, attrs []xml.Attr) error
- func XMLNameMatch(n1 xml.Name, n2 xml.Name) bool
- func XMLNameToString(name xml.Name) string
- type AttrParser
- type Background
- func (b *Background) GetColor() color.RGBA
- func (b *Background) GetField() string
- func (b *Background) GetSVG() *oksvg.SvgIcon
- func (b *Background) GetScale() util.ScaleOption
- func (b *Background) GetSprite() *pixel.Sprite
- func (b *Background) IsInitialised() bool
- func (b *Background) IsSVG() bool
- func (b *Background) Reset()
- func (b *Background) SetSVG(s *oksvg.SvgIcon)
- func (b *Background) SetSprite(s *pixel.Sprite)
- func (b *Background) UnmarshalXML(*xml.Decoder, xml.StartElement) (err error)
- type Button
- type ButtonImpl
- func (e *ButtonImpl) CallPressCallback() error
- func (e *ButtonImpl) GetButtonBkg(s ButtonState) *pixel.Sprite
- func (e *ButtonImpl) GetButtonBkgField(s ButtonState) string
- func (e *ButtonImpl) GetButtonState() ButtonState
- func (e *ButtonImpl) Init(window *pixelgl.Window, bounds *pixel.Rect) error
- func (e *ButtonImpl) IsInitialised() bool
- func (e *ButtonImpl) SetButtonBkg(state ButtonState, sprite *pixel.Sprite)
- func (e *ButtonImpl) SetButtonState(s ButtonState)
- type ButtonState
- type Callback
- type Element
- type Factory
- type Image
- type ImageImpl
- func (i *ImageImpl) GetColor() color.RGBA
- func (i *ImageImpl) GetField() string
- func (i *ImageImpl) GetSVG() *oksvg.SvgIcon
- func (i *ImageImpl) GetScale() util.ScaleOption
- func (i *ImageImpl) GetSprite() *pixel.Sprite
- func (i *ImageImpl) IsInitialised() bool
- func (i *ImageImpl) IsSVG() bool
- func (i *ImageImpl) Reset()
- func (i *ImageImpl) SetSVG(s *oksvg.SvgIcon)
- func (i *ImageImpl) SetSprite(s *pixel.Sprite)
- type Impl
- func (e *Impl) AddNamespace(namespace string)
- func (e *Impl) Draw()
- func (e *Impl) GetActualHeight() *float64
- func (e *Impl) GetActualWidth() *float64
- func (e *Impl) GetBkg() Image
- func (e *Impl) GetBounds() *pixel.Rect
- func (e *Impl) GetCanvas() *pixelgl.Canvas
- func (e *Impl) GetFS() http.FileSystem
- func (e *Impl) GetGravity() util.Gravity
- func (e *Impl) GetID() *string
- func (e *Impl) GetMax() *pixel.Vec
- func (e *Impl) GetMin() *pixel.Vec
- func (e *Impl) GetName() xml.Name
- func (e *Impl) GetNamespaces() []string
- func (e *Impl) GetPadding() util.AbsoluteQuantity
- func (e *Impl) GetParent() Layout
- func (e *Impl) GetRelHeight() util.RelativeSize
- func (e *Impl) GetRelWidth() util.RelativeSize
- func (e *Impl) Init(window *pixelgl.Window, bounds *pixel.Rect) error
- func (e *Impl) IsInitialised() bool
- func (e *Impl) NewEvent(*pixelgl.Window)
- func (e *Impl) Reset()
- func (e *Impl) ResetPosition()
- func (e *Impl) SetActualHeight(height *float64)
- func (e *Impl) SetActualWidth(width *float64)
- func (e *Impl) SetMax(max *pixel.Vec)
- func (e *Impl) SetMin(min *pixel.Vec)
- func (e *Impl) UnmarshalXML(d *xml.Decoder, s xml.StartElement) (err error)
- type Layout
- type LayoutImpl
- type NoElemError
- type Root
- type Text
- type TextImpl
- func (t *TextImpl) GetField() string
- func (t *TextImpl) GetFont() string
- func (t *TextImpl) GetSprite() *text.Text
- func (t *TextImpl) GetText() string
- func (t *TextImpl) GetTextSize() float64
- func (t *TextImpl) IsInitialised() bool
- func (t *TextImpl) Reset()
- func (t *TextImpl) SetSprite(s *text.Text)
- func (t *TextImpl) SetText(s string) error
Constants ¶
const ButtonDefaultState = "default"
The default button state
const ButtonHoveredState = "hovered"
The button state when the mouse is over it
const ButtonPressedState = "pressed"
The button state for when the mouse is pressing the button
Variables ¶
This section is empty.
Functions ¶
func ButtonNewEvent ¶
Function to handle a button's new event
func CalculateHeight ¶
func CalculateHeight(parent Element, window *pixelgl.Window, bounds *pixel.Rect, relHeight util.RelativeSize) (height *float64)
Function to calculate an element's height
func CalculateMin ¶
Function to calculate an element's minimum point
func CalculateWidth ¶
func CalculateWidth(parent Element, window *pixelgl.Window, bounds *pixel.Rect, relWidth util.RelativeSize) (width *float64)
Function to calculate an element's width
func ChildrenAreInitialised ¶
Function to determine whether a layout's children have been initialised. This function doesn't call element.IsInitialised
func DrawCanvasOntoParent ¶
Function to draw a canvas (usually an element's) onto a parent canvas. This function is generally used by layouts, or just anything that has child element(s)
func DrawUI ¶
Function to draw the entire UI element tree, by traversing up the given element's parents
func FullName ¶
Function to get an element's full name, which includes its parent's and grandparent's etc. element names. The function calls any unknown elements "unknown" in the path
func InitUI ¶
Function to reset and initialise the entire UI element tree, by traversing up the given element's parents
func Name ¶
Function to get an element's name. The function returns an empty string if the element isn't registered
func RegisterAttrType ¶
func RegisterAttrType(t reflect.Type, p AttrParser)
Function to register an attribute type
func RegisterCallback ¶
Function to register a new callback
func SetAttrs ¶
Function to parse the given xml attributes and set the fields of the given element using uixml tags. This function searches for tags recursively. It does not support arrays or maps
func XMLNameMatch ¶
Function to determine if two XML names match. Returns true if n1 and n2 match exactly or if n1.Space == "" and n1.Local and n2.Local match
func XMLNameToString ¶
Function to convert an xml name to a string
Types ¶
type AttrParser ¶
Type for an attribute parser
type Background ¶
type Background struct { // The background field // from xml Field string `uixml:"http://github.com/bhollier/ui/api/schema background,optional"` // The background's scale option Scale util.ScaleOption `uixml:"http://github.com/bhollier/ui/api/schema bkg-scale,optional"` // The background's colour Color color.RGBA `uixml:"http://github.com/bhollier/ui/api/schema bkg-color,optional"` // contains filtered or unexported fields }
Implementation of the image interface for a background
func (*Background) GetColor ¶
func (b *Background) GetColor() color.RGBA
Function to get the background's colour
func (*Background) GetField ¶
func (b *Background) GetField() string
Function to get the background's XML field
func (*Background) GetSVG ¶
func (b *Background) GetSVG() *oksvg.SvgIcon
Function to get the background's SVG
func (*Background) GetScale ¶
func (b *Background) GetScale() util.ScaleOption
Function to get the background's scale option
func (*Background) GetSprite ¶
func (b *Background) GetSprite() *pixel.Sprite
Function to get the background's sprite
func (*Background) IsInitialised ¶
func (b *Background) IsInitialised() bool
Function to determine whether the background has been initialised, by whether its background sprite has been set (assuming it's meant to be set). This function doesn't call element.IsInitialised
func (*Background) IsSVG ¶
func (b *Background) IsSVG() bool
Function to determine whether the background looks like an SVG
func (*Background) SetSVG ¶
func (b *Background) SetSVG(s *oksvg.SvgIcon)
Function to set the background's SVG
func (*Background) SetSprite ¶
func (b *Background) SetSprite(s *pixel.Sprite)
Function to set the background's sprite
func (*Background) UnmarshalXML ¶
func (b *Background) UnmarshalXML(*xml.Decoder, xml.StartElement) (err error)
Function to unmarshal an XML element into an element. SetAttrs should've been called before this function
type Button ¶
type Button interface { // A button is an element Element // Function to get the button's // current state GetButtonState() ButtonState // Function to set the button's // current state SetButtonState(s ButtonState) // Function to get the button's // background field from XML for // the given state GetButtonBkgField(s ButtonState) string // Function to get the button's // background sprite for the given // state GetButtonBkg(s ButtonState) *pixel.Sprite // Function to set the button's // background sprite for the given // state SetButtonBkg(state ButtonState, sprite *pixel.Sprite) // Function to call the press callback CallPressCallback() error }
Interface for a button element
type ButtonImpl ¶
type ButtonImpl struct { // The button is an element Impl // The button's background when // being hovered over from XML HoveredBackground string `uixml:"http://github.com/bhollier/ui/api/schema bkg-hovered,optional"` // The button's background when // being pressed from XML PressedBackground string `uixml:"http://github.com/bhollier/ui/api/schema bkg-pressed,optional"` // The element's press callback PressCallback string `uixml:"http://github.com/bhollier/ui/api/schema press-callback,optional"` // contains filtered or unexported fields }
Type for a button. Note, structs must either include ButtonImpl or Impl, not both
func NewButton ¶
func NewButton(fs http.FileSystem, name xml.Name, parent Layout) ButtonImpl
Function to create a button element
func (*ButtonImpl) CallPressCallback ¶
func (e *ButtonImpl) CallPressCallback() error
Function to call the press callback
func (*ButtonImpl) GetButtonBkg ¶
func (e *ButtonImpl) GetButtonBkg(s ButtonState) *pixel.Sprite
Function to get the button's background sprite for the given state
func (*ButtonImpl) GetButtonBkgField ¶
func (e *ButtonImpl) GetButtonBkgField(s ButtonState) string
Function to get the button's background field from XML for the given state
func (*ButtonImpl) GetButtonState ¶
func (e *ButtonImpl) GetButtonState() ButtonState
Function to get the button's current state
func (*ButtonImpl) IsInitialised ¶
func (e *ButtonImpl) IsInitialised() bool
Function to determine whether the element is initialised
func (*ButtonImpl) SetButtonBkg ¶
func (e *ButtonImpl) SetButtonBkg(state ButtonState, sprite *pixel.Sprite)
Function to set the button's background sprite for the given state
func (*ButtonImpl) SetButtonState ¶
func (e *ButtonImpl) SetButtonState(s ButtonState)
Function to set the button's current state
type Element ¶
type Element interface { // Function to get the element's parent GetParent() Layout // Function to get the filesystem to use // for opening files GetFS() http.FileSystem // Function to get the element's XML name GetName() xml.Name // Function to get the element's XML // namespaces. This should include // GetName().Space GetNamespaces() []string // Function to add a namespace to the // element AddNamespace(string) // Function to get the element's // ID (or nil, if it doesn't have // one) GetID() *string // Function to get the element's // relative width GetRelWidth() util.RelativeSize // Function to get the element's // relative height GetRelHeight() util.RelativeSize // Function to get the element's // actual width. If nil, it isn't // known yet GetActualWidth() *float64 // Function to set the element's // actual width SetActualWidth(*float64) // Function to get the element's // actual height. If nil, it isn't // known yet GetActualHeight() *float64 // Function to set the element's // actual height SetActualHeight(*float64) // Function to get the element's // minimum point. If nil, it isn't // known yet GetMin() *pixel.Vec // Function to set the element's // minimum point SetMin(*pixel.Vec) // Function to get the element's // maximum point. If nil, it isn't // known yet GetMax() *pixel.Vec // Function to set the element's // maximum point SetMax(*pixel.Vec) // Function to get the element's // bounds. If nil, either the min // or max isn't known GetBounds() *pixel.Rect // Function to get the element's // padding GetPadding() util.AbsoluteQuantity // Function to get the element's // gravity GetGravity() util.Gravity // Function to get the element's // background GetBkg() Image // Function to get the element's // canvas GetCanvas() *pixelgl.Canvas // Function to unmarshal an XML element // into a UI element. This function is // usually only called by xml.Unmarshal UnmarshalXML(d *xml.Decoder, start xml.StartElement) error // Function to reset the element's // position ResetPosition() // Function to reset the element // completely Reset() // Function to determine whether // the element is initialised IsInitialised() bool // Function to initialise the element // (load textures, create sprites, set // sprite locations, etc.) Init(window *pixelgl.Window, bounds *pixel.Rect) error // Function that is called when there // is a new event NewEvent(*pixelgl.Window) // Function to draw the element // to its canvas Draw() }
Interface type for something that is an element
func ChildrenUnmarshalXML ¶
func ChildrenUnmarshalXML(fs http.FileSystem, parent Layout, d *xml.Decoder, start xml.StartElement) ([]Element, error)
Function to unmarshal an XML element into a number of child elements. This function is usually only called by LayoutImpl.UnmarshalXML
func New ¶
Function to create an element with the given XML name. If none is found and name.Space is empty, the function will search for an element type with a matching name.Local and with a matching name.Space in parent.GetNamespaces(), then if still not found will search for an element type with a matching name.Local
type Image ¶
type Image interface { // Function to get the image's // XML field GetField() string // Function to get the image's // scale options GetScale() util.ScaleOption // Function to get the image's // colour GetColor() color.RGBA // Function to determine whether // the image looks like an SVG IsSVG() bool // Function to get the image's // SVG. Always returns nil if // IsSVG returns false GetSVG() *oksvg.SvgIcon // Function to set the image's // SVG SetSVG(*oksvg.SvgIcon) // Function to get the image's // sprite GetSprite() *pixel.Sprite // Function to set the image's // sprite SetSprite(*pixel.Sprite) }
Interface for an image
type ImageImpl ¶
type ImageImpl struct { // The image field from // xml Field string `uixml:"http://github.com/bhollier/ui/api/schema source,optional"` // The image's scale // option Scale util.ScaleOption `uixml:"http://github.com/bhollier/ui/api/schema scale,optional"` // The image's colour Color color.RGBA `uixml:"http://github.com/bhollier/ui/api/schema color,optional"` // contains filtered or unexported fields }
Implementation of the image interface
func (*ImageImpl) GetScale ¶
func (i *ImageImpl) GetScale() util.ScaleOption
Function to get the image's image scale options
func (*ImageImpl) IsInitialised ¶
Function to determine whether the image has been initialised, by whether its image sprite has been set (assuming it's meant to be set). This function doesn't call element.IsInitialised
type Impl ¶
type Impl struct { // The element's ID ID string `uixml:"http://github.com/bhollier/ui/api/schema id,optional"` // The element's relative width RelativeWidth util.RelativeSize `uixml:"http://github.com/bhollier/ui/api/schema width"` // The element's relative height RelativeHeight util.RelativeSize `uixml:"http://github.com/bhollier/ui/api/schema height"` // The element's padding Padding util.AbsoluteQuantity `uixml:"http://github.com/bhollier/ui/api/schema padding,optional"` // The element's background Bkg Background // The element's gravity Gravity util.Gravity `uixml:"http://github.com/bhollier/ui/api/schema gravity,optional"` // contains filtered or unexported fields }
Type for the implementation of a UI element. Most elements should include this at some point (but only once)
func NewElement ¶
Function to create an element
func (*Impl) AddNamespace ¶
Function to add a namespace to the element
func (*Impl) Draw ¶
func (e *Impl) Draw()
Function to draw the element. This function should be called first
func (*Impl) GetActualHeight ¶
Function to get the element's actual height. If nil, it isn't known yet
func (*Impl) GetActualWidth ¶
Function to get the element's actual width. If nil, it isn't known yet
func (*Impl) GetBounds ¶
Function to get the element's bounds. If nil, either the min or max isn't known
func (*Impl) GetFS ¶
func (e *Impl) GetFS() http.FileSystem
Function to get the filesystem to use for opening files
func (*Impl) GetGravity ¶
Function to get the element's gravity
func (*Impl) GetNamespaces ¶
Function to get the element's namespaces
func (*Impl) GetPadding ¶
func (e *Impl) GetPadding() util.AbsoluteQuantity
Function to get the element's padding
func (*Impl) GetRelHeight ¶
func (e *Impl) GetRelHeight() util.RelativeSize
Function to get the element's relative height
func (*Impl) GetRelWidth ¶
func (e *Impl) GetRelWidth() util.RelativeSize
Function to get the element's relative width
func (*Impl) Init ¶
Function to initialise an element's position, width and height. Because it doesn't know the element's actual size, it won't set the width or height if the relative width or height is "match_content"
func (*Impl) IsInitialised ¶
Function to determine whether the element has been initialised by whether its width, height, position and canvas are set (not nil) and if it's background is initialised
func (*Impl) NewEvent ¶
Function that is called when there is a new event. This function does nothing
func (*Impl) Reset ¶
func (e *Impl) Reset()
Function to reset the element. This function doesn't reset the width and height of the element
func (*Impl) ResetPosition ¶
func (e *Impl) ResetPosition()
Function to reset the element's position
func (*Impl) SetActualHeight ¶
Function to set the element's actual height
func (*Impl) SetActualWidth ¶
Function to set the element's actual width
func (*Impl) UnmarshalXML ¶
Function to unmarshal an XML element into an element. SetAttrs should've been called before this function
type Layout ¶
type Layout interface { // A layout is also an element Element // Function to get one of a layout's child // elements GetChild(n int) Element // Function to get one of a layout's child // elements by its ID GetChildByID(id string) Element // Function to get the number of child // elements this layout has NumChildren() int }
Interface type for a layout element
type LayoutImpl ¶
type LayoutImpl struct { // The layout's child elements // (in order) Children []Element }
Type for a layout
func (*LayoutImpl) GetChild ¶
func (e *LayoutImpl) GetChild(n int) Element
Function to get one of a layout's child elements
func (*LayoutImpl) GetChildByID ¶
func (e *LayoutImpl) GetChildByID(id string) Element
Function to get one of a layout's child elements by its ID. Returns nil if no child could be found
func (*LayoutImpl) NewEvent ¶
func (e *LayoutImpl) NewEvent(window *pixelgl.Window)
Function that is called when there is a new event. This function only calls NewEvent on the child elements
func (*LayoutImpl) NumChildren ¶
func (e *LayoutImpl) NumChildren() int
Function to get the number element elements a layout has
func (*LayoutImpl) ResetPosition ¶
func (e *LayoutImpl) ResetPosition()
Function to reset the child element's positions
type NoElemError ¶
Type for an error when an attribute's element ID doesn't match an actual ID
func NewNoElemError ¶
func NewNoElemError(elem Element, refElem string, attrName string) NoElemError
Function to create a NoElemError. elem is the element that references an ID, refElem is the ID of the element being referenced (that doesn't exist), and attrName is the name of the attribute asking for the ID
type Root ¶
type Root struct { // The root element itself Element // contains filtered or unexported fields }
Type for the root of a UI XML document
func (*Root) UnmarshalXML ¶
Function to unmarshal an XML element into a root element. This function is usually only called by xml.Unmarshal
type Text ¶
type Text interface { // Function to get the text // XML field GetField() string // Function to get the text // font GetFont() string // Function to get the text // currently being displayed GetText() string // Function to set the text // currently being displayed. // This function doesn't alter // the text's width and height, // for this element.SetText // should be used instead SetText(string) error // Function to get the text size GetTextSize() float64 // Function to get the text // "sprite" GetSprite() *text.Text // Function to set the text // "sprite" SetSprite(*text.Text) }
Interface for some text
type TextImpl ¶
type TextImpl struct { // The element's text from xml Text string `uixml:"http://github.com/bhollier/ui/api/schema text,optional"` // The element's font Font string `uixml:"http://github.com/bhollier/ui/api/schema font,optional"` // The element's text size Size float64 `uixml:"http://github.com/bhollier/ui/api/schema text-size,optional"` // contains filtered or unexported fields }
Implementation of the text interface
func (*TextImpl) GetTextSize ¶
Function to get the text size
func (*TextImpl) IsInitialised ¶
Function to determine whether the text has been initialised, by whether its text sprite has been set (assuming it's meant to be set). This function doesn't call element.IsInitialised