Documentation ¶
Overview ¶
Package ui provides methods to draw a user interface onto the the screen and manage resizing.
Index ¶
- Variables
- func AddDrawable(d Drawable)
- func Click(x, y float64, width, height int)
- func CycleFocus()
- func Draw(width, height int, delta float64)
- func ForceDraw()
- func HandleChar(w *glfw.Window, char rune)
- func HandleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, ...)
- func Hover(x, y float64, width, height int)
- func Intersects(d Drawable, x, y float64, width, height int) (float64, float64, bool)
- func Remove(d Drawable)
- type AttachPoint
- type Button
- func (b *Button) AddClick(f func())
- func (b *Button) AddHover(f func(over bool))
- func (b *Button) Attach(vAttach, hAttach AttachPoint) *Button
- func (b *Button) AttachTo(d Drawable)
- func (b *Button) AttachedTo() Drawable
- func (b *Button) Attachment() (vAttach, hAttach AttachPoint)
- func (b *Button) Click(r Region, x, y float64)
- func (b *Button) Disabled() bool
- func (b *Button) Draw(r Region, delta float64)
- func (b *Button) Height() float64
- func (b *Button) Hover(r Region, x, y float64, over bool)
- func (b *Button) Layer() int
- func (b *Button) Offset() (float64, float64)
- func (b *Button) OnRemove(d Drawable)
- func (b *Button) Remove()
- func (b *Button) SetDisabled(d bool)
- func (b *Button) SetDraw(shouldDraw bool)
- func (b *Button) SetHeight(h float64)
- func (b *Button) SetLayer(l int)
- func (b *Button) SetRemoveHook(r func(Drawable))
- func (b *Button) SetWidth(w float64)
- func (b *Button) SetX(x float64)
- func (b *Button) SetY(y float64)
- func (b *Button) ShouldDraw() bool
- func (b *Button) Size() (float64, float64)
- func (b *Button) Width() float64
- func (b *Button) X() float64
- func (b *Button) Y() float64
- type Container
- func (c *Container) Attach(vAttach, hAttach AttachPoint) *Container
- func (b *Container) AttachTo(d Drawable)
- func (b *Container) AttachedTo() Drawable
- func (b *Container) Attachment() (vAttach, hAttach AttachPoint)
- func (c *Container) Click(r Region, x, y float64)
- func (c *Container) Draw(r Region, delta float64)
- func (c *Container) Height() float64
- func (c *Container) Hover(r Region, x, y float64, over bool)
- func (b *Container) Layer() int
- func (c *Container) Offset() (float64, float64)
- func (b *Container) OnRemove(d Drawable)
- func (b *Container) SetDraw(shouldDraw bool)
- func (c *Container) SetHeight(h float64)
- func (b *Container) SetLayer(l int)
- func (b *Container) SetRemoveHook(r func(Drawable))
- func (c *Container) SetWidth(w float64)
- func (c *Container) SetX(x float64)
- func (c *Container) SetY(y float64)
- func (b *Container) ShouldDraw() bool
- func (c *Container) Size() (float64, float64)
- func (c *Container) Width() float64
- func (c *Container) X() float64
- func (c *Container) Y() float64
- type Drawable
- type Formatted
- func (f *Formatted) Attach(vAttach, hAttach AttachPoint) *Formatted
- func (b *Formatted) AttachTo(d Drawable)
- func (b *Formatted) AttachedTo() Drawable
- func (b *Formatted) Attachment() (vAttach, hAttach AttachPoint)
- func (f *Formatted) Draw(r Region, delta float64)
- func (b *Formatted) Layer() int
- func (f *Formatted) Offset() (float64, float64)
- func (b *Formatted) OnRemove(d Drawable)
- func (f *Formatted) Remove()
- func (f *Formatted) ScaleX() float64
- func (f *Formatted) ScaleY() float64
- func (b *Formatted) SetDraw(shouldDraw bool)
- func (b *Formatted) SetLayer(l int)
- func (b *Formatted) SetRemoveHook(r func(Drawable))
- func (f *Formatted) SetScaleX(s float64)
- func (f *Formatted) SetScaleY(s float64)
- func (f *Formatted) SetX(x float64)
- func (f *Formatted) SetY(y float64)
- func (b *Formatted) ShouldDraw() bool
- func (f *Formatted) Size() (float64, float64)
- func (f *Formatted) Update(val format.AnyComponent)
- func (f *Formatted) X() float64
- func (f *Formatted) Y() float64
- type Image
- func (i *Image) A() int
- func (i *Image) Attach(vAttach, hAttach AttachPoint) *Image
- func (b *Image) AttachTo(d Drawable)
- func (b *Image) AttachedTo() Drawable
- func (b *Image) Attachment() (vAttach, hAttach AttachPoint)
- func (i *Image) B() int
- func (i *Image) Draw(r Region, delta float64)
- func (i *Image) G() int
- func (i *Image) Height() float64
- func (b *Image) Layer() int
- func (i *Image) Offset() (float64, float64)
- func (b *Image) OnRemove(d Drawable)
- func (i *Image) R() int
- func (i *Image) Remove()
- func (i *Image) SetA(a int)
- func (i *Image) SetB(b int)
- func (b *Image) SetDraw(shouldDraw bool)
- func (i *Image) SetG(g int)
- func (i *Image) SetHeight(h float64)
- func (b *Image) SetLayer(l int)
- func (i *Image) SetR(r int)
- func (b *Image) SetRemoveHook(r func(Drawable))
- func (i *Image) SetTexture(t render.TextureInfo)
- func (i *Image) SetTextureHeight(h float64)
- func (i *Image) SetTextureWidth(w float64)
- func (i *Image) SetTextureX(x float64)
- func (i *Image) SetTextureY(y float64)
- func (i *Image) SetWidth(w float64)
- func (i *Image) SetX(x float64)
- func (i *Image) SetY(y float64)
- func (b *Image) ShouldDraw() bool
- func (i *Image) Size() (float64, float64)
- func (i *Image) Texture() render.TextureInfo
- func (i *Image) TextureHeight() float64
- func (i *Image) TextureWidth() float64
- func (i *Image) TextureX() float64
- func (i *Image) TextureY() float64
- func (i *Image) Width() float64
- func (i *Image) X() float64
- func (i *Image) Y() float64
- type Interactable
- type Mode
- type Model
- func (m *Model) Attach(vAttach, hAttach AttachPoint) *Model
- func (b *Model) AttachTo(d Drawable)
- func (b *Model) AttachedTo() Drawable
- func (b *Model) Attachment() (vAttach, hAttach AttachPoint)
- func (m *Model) Draw(r Region, delta float64)
- func (b *Model) Layer() int
- func (m *Model) Offset() (float64, float64)
- func (b *Model) OnRemove(d Drawable)
- func (m *Model) Remove()
- func (b *Model) SetDraw(shouldDraw bool)
- func (b *Model) SetLayer(l int)
- func (b *Model) SetRemoveHook(r func(Drawable))
- func (m *Model) SetX(x float64)
- func (m *Model) SetY(y float64)
- func (b *Model) ShouldDraw() bool
- func (m *Model) Size() (float64, float64)
- func (m *Model) X() float64
- func (m *Model) Y() float64
- type ModelVertex
- type Region
- type Text
- func (t *Text) A() int
- func (t *Text) Attach(vAttach, hAttach AttachPoint) *Text
- func (b *Text) AttachTo(d Drawable)
- func (b *Text) AttachedTo() Drawable
- func (b *Text) Attachment() (vAttach, hAttach AttachPoint)
- func (t *Text) B() int
- func (t *Text) Draw(r Region, delta float64)
- func (t *Text) G() int
- func (b *Text) Layer() int
- func (t *Text) Offset() (float64, float64)
- func (b *Text) OnRemove(d Drawable)
- func (t *Text) R() int
- func (t *Text) Remove()
- func (t *Text) Rotation() float64
- func (t *Text) ScaleX() float64
- func (t *Text) ScaleY() float64
- func (t *Text) SetA(a int)
- func (t *Text) SetB(b int)
- func (b *Text) SetDraw(shouldDraw bool)
- func (t *Text) SetG(g int)
- func (b *Text) SetLayer(l int)
- func (t *Text) SetR(r int)
- func (b *Text) SetRemoveHook(r func(Drawable))
- func (t *Text) SetRotation(r float64)
- func (t *Text) SetScaleX(s float64)
- func (t *Text) SetScaleY(s float64)
- func (t *Text) SetX(x float64)
- func (t *Text) SetY(y float64)
- func (b *Text) ShouldDraw() bool
- func (t *Text) Size() (float64, float64)
- func (t *Text) Update(val string)
- func (t *Text) Value() string
- func (t *Text) X() float64
- func (t *Text) Y() float64
- type TextBox
- func (t *TextBox) Attach(vAttach, hAttach AttachPoint) *TextBox
- func (b *TextBox) AttachTo(d Drawable)
- func (b *TextBox) AttachedTo() Drawable
- func (b *TextBox) Attachment() (vAttach, hAttach AttachPoint)
- func (t *TextBox) Click(r Region, x, y float64)
- func (t *TextBox) Draw(r Region, delta float64)
- func (t *TextBox) Height() float64
- func (t *TextBox) Hover(r Region, x, y float64, over bool)
- func (b *TextBox) Layer() int
- func (t *TextBox) Offset() (float64, float64)
- func (b *TextBox) OnRemove(d Drawable)
- func (t *TextBox) Password() bool
- func (t *TextBox) Remove()
- func (b *TextBox) SetDraw(shouldDraw bool)
- func (t *TextBox) SetHeight(h float64)
- func (b *TextBox) SetLayer(l int)
- func (t *TextBox) SetPassword(p bool)
- func (b *TextBox) SetRemoveHook(r func(Drawable))
- func (t *TextBox) SetWidth(w float64)
- func (t *TextBox) SetX(x float64)
- func (t *TextBox) SetY(y float64)
- func (b *TextBox) ShouldDraw() bool
- func (t *TextBox) Size() (float64, float64)
- func (t *TextBox) Update(val string)
- func (t *TextBox) Value() string
- func (t *TextBox) Width() float64
- func (t *TextBox) X() float64
- func (t *TextBox) Y() float64
Constants ¶
This section is empty.
Variables ¶
var ( // DrawMode is the scaling mode used. DrawMode = Scaled // Scale controls the scaling manually when DrawModel is Unscaled Scale = 1.0 )
var ClickSound func()
ClickSound is the method that will be added to all buttons to play a click sound
Functions ¶
func HandleChar ¶
HandleChar passes the input to the focused drawable
func HandleKey ¶
func HandleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey)
HandleKey passes the input to the focused drawable
func Intersects ¶
Intersects returns whether the point x,y intersects with the drawable
Types ¶
type AttachPoint ¶
type AttachPoint int
AttachPoint is a side of the screen that an element can be attached to
const (
Top, Left AttachPoint = iota, iota
Middle, Center
Bottom, Right
)
Attachment points
VAlign, HAlign
type Button ¶
type Button struct {
// contains filtered or unexported fields
}
Button is a drawable that draws a button.
func (*Button) AddClick ¶
func (b *Button) AddClick(f func())
AddClick adds a function to be called when the button is clicked
func (*Button) Attach ¶
func (b *Button) Attach(vAttach, hAttach AttachPoint) *Button
Attach changes the location where this is attached to.
func (*Button) AttachedTo ¶
func (b *Button) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*Button) Attachment ¶
func (b *Button) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*Button) Remove ¶
func (b *Button) Remove()
Remove removes the Button element from the draw list.
func (*Button) SetDisabled ¶
func (*Button) SetRemoveHook ¶
func (b *Button) SetRemoveHook(r func(Drawable))
func (*Button) ShouldDraw ¶
func (b *Button) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.
type Container ¶
type Container struct { HoverFunc func(over bool) ClickFunc func() // contains filtered or unexported fields }
Container is a drawable that is used for aligning other drawables. Should never be drawn.
func NewContainer ¶
func (*Container) Attach ¶
func (c *Container) Attach(vAttach, hAttach AttachPoint) *Container
Attach changes the location where this is attached to.
func (*Container) AttachedTo ¶
func (b *Container) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*Container) Attachment ¶
func (b *Container) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*Container) SetRemoveHook ¶
func (b *Container) SetRemoveHook(r func(Drawable))
func (*Container) ShouldDraw ¶
func (b *Container) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.
type Drawable ¶
type Drawable interface { Draw(r Region, delta float64) Size() (float64, float64) // Offset is the offset from the attachment point on // each axis Offset() (float64, float64) ShouldDraw() bool AttachedTo() Drawable AttachTo(d Drawable) Attachment() (vAttach, hAttach AttachPoint) Layer() int OnRemove(d Drawable) SetRemoveHook(func(Drawable)) // contains filtered or unexported methods }
Drawable is a scalable element that can be drawn to an area.
type Formatted ¶
type Formatted struct { MaxWidth float64 Width, Height float64 Lines int Text []*Text // contains filtered or unexported fields }
Formatted is a drawable that draws a string.
func NewFormatted ¶
func NewFormatted(val format.AnyComponent, x, y float64) *Formatted
NewFormatted creates a new Formatted drawable.
func NewFormattedWidth ¶
func NewFormattedWidth(val format.AnyComponent, x, y, width float64) *Formatted
NewFormattedWidth creates a new Formatted drawable with a max width.
func (*Formatted) Attach ¶
func (f *Formatted) Attach(vAttach, hAttach AttachPoint) *Formatted
Attach changes the location where this is attached to.
func (*Formatted) AttachedTo ¶
func (b *Formatted) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*Formatted) Attachment ¶
func (b *Formatted) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*Formatted) Remove ¶
func (f *Formatted) Remove()
Remove removes the Formatted element from the draw list.
func (*Formatted) SetRemoveHook ¶
func (b *Formatted) SetRemoveHook(r func(Drawable))
func (*Formatted) ShouldDraw ¶
func (b *Formatted) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.
func (*Formatted) Update ¶
func (f *Formatted) Update(val format.AnyComponent)
Update updates the component drawn by this drawable.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is a drawable that draws a texture.
func NewImage ¶
func NewImage(texture render.TextureInfo, x, y, w, h, tx, ty, tw, th float64, r, g, b int) *Image
NewImage creates a new image drawable.
func (*Image) Attach ¶
func (i *Image) Attach(vAttach, hAttach AttachPoint) *Image
Attach changes the location where this is attached to.
func (*Image) AttachedTo ¶
func (b *Image) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*Image) Attachment ¶
func (b *Image) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*Image) Remove ¶
func (i *Image) Remove()
Remove removes the image element from the draw list.
func (*Image) SetRemoveHook ¶
func (b *Image) SetRemoveHook(r func(Drawable))
func (*Image) SetTexture ¶
func (i *Image) SetTexture(t render.TextureInfo)
func (*Image) SetTextureHeight ¶
func (*Image) SetTextureWidth ¶
func (*Image) SetTextureX ¶
func (*Image) SetTextureY ¶
func (*Image) ShouldDraw ¶
func (b *Image) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.
func (*Image) Texture ¶
func (i *Image) Texture() render.TextureInfo
func (*Image) TextureHeight ¶
func (*Image) TextureWidth ¶
type Interactable ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
func (*Model) Attach ¶
func (m *Model) Attach(vAttach, hAttach AttachPoint) *Model
Attach changes the location where this is attached to.
func (*Model) AttachedTo ¶
func (b *Model) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*Model) Attachment ¶
func (b *Model) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*Model) Remove ¶
func (m *Model) Remove()
Remove removes the image element from the draw list.
func (*Model) SetRemoveHook ¶
func (b *Model) SetRemoveHook(r func(Drawable))
func (*Model) ShouldDraw ¶
func (b *Model) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.
type ModelVertex ¶
type Text ¶
type Text struct { Width float64 // contains filtered or unexported fields }
Text is a drawable that draws a string.
func (*Text) Attach ¶
func (t *Text) Attach(vAttach, hAttach AttachPoint) *Text
Attach changes the location where this is attached to.
func (*Text) AttachedTo ¶
func (b *Text) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*Text) Attachment ¶
func (b *Text) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*Text) SetRemoveHook ¶
func (b *Text) SetRemoveHook(r func(Drawable))
func (*Text) SetRotation ¶
func (*Text) ShouldDraw ¶
func (b *Text) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.
type TextBox ¶
type TextBox struct { SubmitFunc func() // contains filtered or unexported fields }
TextBox is a drawable that allows for input.
func NewTextBox ¶
NewTextBox creates a new TextBox drawable.
func (*TextBox) Attach ¶
func (t *TextBox) Attach(vAttach, hAttach AttachPoint) *TextBox
Attach changes the location where this is attached to.
func (*TextBox) AttachedTo ¶
func (b *TextBox) AttachedTo() Drawable
AttachedTo returns the Drawable this is attached to or nil.
func (*TextBox) Attachment ¶
func (b *TextBox) Attachment() (vAttach, hAttach AttachPoint)
Attachment returns the sides where this element is attached too.
func (*TextBox) Remove ¶
func (t *TextBox) Remove()
Remove removes the textbox element from the draw list.
func (*TextBox) SetPassword ¶
func (*TextBox) SetRemoveHook ¶
func (b *TextBox) SetRemoveHook(r func(Drawable))
func (*TextBox) ShouldDraw ¶
func (b *TextBox) ShouldDraw() bool
ShouldDraw returns whether this should be drawn at this time.