Documentation
¶
Overview ¶
Package ui provides types and functions for creating an interactive User Interface.
Index ¶
- Constants
- func NewController(cfg *Config, initFn InitFunc) app.Controller
- type Bounds
- func (b Bounds) Contains(position Position) bool
- func (b Bounds) Grow(size Size) Bounds
- func (b Bounds) Intersect(other Bounds) Bounds
- func (b Bounds) Resize(width, height int) Bounds
- func (b Bounds) Shrink(size Size) Bounds
- func (b Bounds) String() string
- func (b Bounds) Translate(delta Position) Bounds
- type Canvas
- func (c Canvas) Clip(bounds Bounds)
- func (c Canvas) Contour() *Contour
- func (c Canvas) DrawSurface(surface Surface, position Position, size Size)
- func (c Canvas) Pop()
- func (c Canvas) Push()
- func (c Canvas) ResetTransform()
- func (c Canvas) SetClipBounds(left, right, top, bottom float32)
- func (c Canvas) SetTransform(transform sprec.Mat4)
- func (c Canvas) Shape() *Shape
- func (c Canvas) Text() *Text
- func (c Canvas) Translate(delta sprec.Vec2)
- type Color
- func Aqua() Color
- func Black() Color
- func Blue() Color
- func ColorWithAlpha(color Color, a uint8) Color
- func Fuchsia() Color
- func Gray() Color
- func Green() Color
- func Lime() Color
- func Maroon() Color
- func Navy() Color
- func Olive() Color
- func Purple() Color
- func RGB(r, g, b uint8) Color
- func RGBA(r, g, b, a uint8) Color
- func Red() Color
- func Silver() Color
- func Teal() Color
- func Transparent() Color
- func White() Color
- func Yellow() Color
- type Config
- type Context
- func (c *Context) CreateContext() *Context
- func (c *Context) CreateElement() *Element
- func (c *Context) CreateFont(font *opentype.Font) (*Font, error)
- func (c *Context) CreateFontCollection(collection *opentype.Collection) (*FontCollection, error)
- func (c *Context) CreateImage(img image.Image) (*Image, error)
- func (c *Context) Destroy()
- func (c *Context) GetFont(family, subFamily string) (*Font, bool)
- func (c *Context) OpenFont(uri string) (*Font, error)
- func (c *Context) OpenFontCollection(uri string) (*FontCollection, error)
- func (c *Context) OpenImage(uri string) (*Image, error)
- func (c *Context) Schedule(fn func())
- func (c *Context) Window() *Window
- type Contour
- func (c *Contour) Begin()
- func (c *Contour) Circle(position sprec.Vec2, radius float32, stroke Stroke)
- func (c *Contour) CloseLoop()
- func (c *Contour) CubeTo(control1, control2, position sprec.Vec2, stroke Stroke)
- func (c *Contour) End()
- func (c *Contour) LineTo(position sprec.Vec2, stroke Stroke)
- func (c *Contour) MoveTo(position sprec.Vec2, stroke Stroke)
- func (c *Contour) QuadTo(control, position sprec.Vec2, stroke Stroke)
- func (c *Contour) Rectangle(position, size sprec.Vec2, stroke Stroke)
- func (c *Contour) RoundRectangle(position, size sprec.Vec2, roundness RectRoundness, stroke Stroke)
- func (c *Contour) Triangle(p1, p2, p3 sprec.Vec2, stroke Stroke)
- type ContourMesh
- type ContourVertex
- type Element
- func (e *Element) AppendChild(child *Element)
- func (e *Element) AppendSibling(sibling *Element)
- func (e *Element) Bounds() Bounds
- func (e *Element) ContentBounds() Bounds
- func (e *Element) Context() *Context
- func (e *Element) Destroy()
- func (e *Element) Detach()
- func (e *Element) Enabled() bool
- func (e *Element) Essence() Essence
- func (e *Element) FirstChild() *Element
- func (e *Element) Focusable() bool
- func (e *Element) ID() string
- func (e *Element) IdealSize() Size
- func (e *Element) InjectEssence(target interface{})
- func (e *Element) LastChild() *Element
- func (e *Element) Layout() Layout
- func (e *Element) LayoutConfig() LayoutConfig
- func (e *Element) LeftSibling() *Element
- func (e *Element) Padding() Spacing
- func (e *Element) Parent() *Element
- func (e *Element) PrependChild(child *Element)
- func (e *Element) RemoveChild(child *Element)
- func (e *Element) RightSibling() *Element
- func (e *Element) SetBounds(bounds Bounds)
- func (e *Element) SetEnabled(enabled bool)
- func (e *Element) SetEssence(essence Essence)
- func (e *Element) SetFocusable(focusable bool)
- func (e *Element) SetID(id string)
- func (e *Element) SetIdealSize(size Size)
- func (e *Element) SetLayout(layout Layout)
- func (e *Element) SetLayoutConfig(layoutConfig LayoutConfig)
- func (e *Element) SetPadding(padding Spacing)
- func (e *Element) SetVisible(visible bool)
- func (e *Element) Visible() bool
- type ElementKeyboardHandler
- type ElementMouseHandler
- type ElementRenderHandler
- type ElementResizeHandler
- type Essence
- type FSResourceLocator
- type FileResourceLocator
- type FilepathPayload
- type Fill
- type FillLayout
- type FillRule
- type Font
- type FontCollection
- type Image
- type InitFunc
- type KeyCode
- type KeyModifier
- type KeyModifierSet
- type KeyboardEvent
- type KeyboardEventType
- type Layout
- type LayoutConfig
- type Material
- type MouseButton
- type MouseEvent
- type MouseEventType
- type Position
- type RectRoundness
- type ResourceLocator
- type ShaderCollection
- type ShaderSet
- type Shape
- func (s *Shape) Begin(fill Fill)
- func (s *Shape) Circle(position sprec.Vec2, radius float32)
- func (s *Shape) CubeTo(control1, control2, position sprec.Vec2)
- func (s *Shape) End()
- func (s *Shape) LineTo(position sprec.Vec2)
- func (s *Shape) MoveTo(position sprec.Vec2)
- func (s *Shape) QuadTo(control, position sprec.Vec2)
- func (s *Shape) Rectangle(position, size sprec.Vec2)
- func (s *Shape) RoundRectangle(position, size sprec.Vec2, roundness RectRoundness)
- func (s *Shape) Triangle(a, b, c sprec.Vec2)
- type ShapeMesh
- type ShapeVertex
- type Size
- type Spacing
- type Stroke
- type Surface
- type Text
- type TextMesh
- type TextVertex
- type Typography
- type Window
- func (w *Window) Context() *Context
- func (w *Window) DiscardFocus()
- func (w *Window) FindElementByID(id string) (*Element, bool)
- func (w *Window) GetElementByID(id string) *Element
- func (w *Window) IsElementFocused(element *Element) bool
- func (w *Window) Root() *Element
- func (w *Window) SetSize(size Size)
- func (w *Window) Size() Size
- type WindowHandler
Constants ¶
const ( KeyboardEventTypeKeyDown = app.KeyboardEventTypeKeyDown KeyboardEventTypeKeyUp = app.KeyboardEventTypeKeyUp KeyboardEventTypeRepeat = app.KeyboardEventTypeRepeat KeyboardEventTypeType = app.KeyboardEventTypeType )
const ( KeyCodeEscape = app.KeyCodeEscape KeyCodeEnter = app.KeyCodeEnter KeyCodeSpace = app.KeyCodeSpace KeyCodeTab = app.KeyCodeTab KeyCodeCaps = app.KeyCodeCaps KeyCodeLeftShift = app.KeyCodeLeftShift KeyCodeRightShift = app.KeyCodeRightShift KeyCodeLeftControl = app.KeyCodeLeftControl KeyCodeRightControl = app.KeyCodeRightControl KeyCodeLeftAlt = app.KeyCodeLeftAlt KeyCodeRightAlt = app.KeyCodeRightAlt KeyCodeBackspace = app.KeyCodeBackspace KeyCodeInsert = app.KeyCodeInsert KeyCodeDelete = app.KeyCodeDelete KeyCodeHome = app.KeyCodeHome KeyCodeEnd = app.KeyCodeEnd KeyCodePageUp = app.KeyCodePageUp KeyCodePageDown = app.KeyCodePageDown KeyCodeArrowLeft = app.KeyCodeArrowLeft KeyCodeArrowRight = app.KeyCodeArrowRight KeyCodeArrowUp = app.KeyCodeArrowUp KeyCodeArrowDown = app.KeyCodeArrowDown KeyCodeMinus = app.KeyCodeMinus KeyCodeEqual = app.KeyCodeEqual KeyCodeLeftBracket = app.KeyCodeLeftBracket KeyCodeRightBracket = app.KeyCodeRightBracket KeyCodeSemicolon = app.KeyCodeSemicolon KeyCodeComma = app.KeyCodeComma KeyCodePeriod = app.KeyCodePeriod KeyCodeSlash = app.KeyCodeSlash KeyCodeBackslash = app.KeyCodeBackslash KeyCodeApostrophe = app.KeyCodeApostrophe KeyCodeGraveAccent = app.KeyCodeGraveAccent KeyCodeA = app.KeyCodeA KeyCodeB = app.KeyCodeB KeyCodeC = app.KeyCodeC KeyCodeD = app.KeyCodeD KeyCodeE = app.KeyCodeE KeyCodeF = app.KeyCodeF KeyCodeG = app.KeyCodeG KeyCodeH = app.KeyCodeH KeyCodeI = app.KeyCodeI KeyCodeJ = app.KeyCodeJ KeyCodeK = app.KeyCodeK KeyCodeL = app.KeyCodeL KeyCodeM = app.KeyCodeM KeyCodeN = app.KeyCodeN KeyCodeO = app.KeyCodeO KeyCodeP = app.KeyCodeP KeyCodeQ = app.KeyCodeQ KeyCodeR = app.KeyCodeR KeyCodeS = app.KeyCodeS KeyCodeT = app.KeyCodeT KeyCodeU = app.KeyCodeU KeyCodeV = app.KeyCodeV KeyCodeW = app.KeyCodeW KeyCodeX = app.KeyCodeX KeyCodeY = app.KeyCodeY KeyCodeZ = app.KeyCodeZ KeyCode0 = app.KeyCode0 KeyCode1 = app.KeyCode1 KeyCode2 = app.KeyCode2 KeyCode3 = app.KeyCode3 KeyCode4 = app.KeyCode4 KeyCode5 = app.KeyCode5 KeyCode6 = app.KeyCode6 KeyCode7 = app.KeyCode7 KeyCode8 = app.KeyCode8 KeyCode9 = app.KeyCode9 KeyCodeF1 = app.KeyCodeF1 KeyCodeF2 = app.KeyCodeF2 KeyCodeF3 = app.KeyCodeF3 KeyCodeF4 = app.KeyCodeF4 KeyCodeF5 = app.KeyCodeF5 KeyCodeF6 = app.KeyCodeF6 KeyCodeF7 = app.KeyCodeF7 KeyCodeF8 = app.KeyCodeF8 KeyCodeF9 = app.KeyCodeF9 KeyCodeF10 = app.KeyCodeF10 KeyCodeF11 = app.KeyCodeF11 KeyCodeF12 = app.KeyCodeF12 )
const ( KeyModifierControl = app.KeyModifierControl KeyModifierShift = app.KeyModifierShift KeyModifierAlt = app.KeyModifierAlt KeyModifierCapsLock = app.KeyModifierCapsLock )
const ( MouseEventTypeDown = app.MouseEventTypeDown MouseEventTypeUp = app.MouseEventTypeUp MouseEventTypeMove = app.MouseEventTypeMove MouseEventTypeDrag = app.MouseEventTypeDrag MouseEventTypeDragCancel = app.MouseEventTypeDragCancel MouseEventTypeDrop = app.MouseEventTypeDrop MouseEventTypeEnter = app.MouseEventTypeEnter MouseEventTypeLeave = app.MouseEventTypeLeave MouseEventTypeScroll = app.MouseEventTypeScroll )
const ( MouseButtonLeft = app.MouseButtonLeft MouseButtonMiddle = app.MouseButtonMiddle MouseButtonRight = app.MouseButtonRight )
Variables ¶
This section is empty.
Functions ¶
func NewController ¶
func NewController(cfg *Config, initFn InitFunc) app.Controller
NewController creates a new app.Controller that integrates with the ui package to render a user interface.
Types ¶
type Bounds ¶
Bounds represents a content area on the screen. It consists of a Position and Size.
func (Bounds) Contains ¶
Contains returns whether the specified Position is contained by this Bounds.
func (Bounds) Grow ¶
Grow returns a new Bounds that has a size that is larger by the given amount compared to these Bounds.
func (Bounds) Intersect ¶
Intersect returns a new Bounds that is the intersection of the specified Bounds and these Bounds.
func (Bounds) Resize ¶
Resize returns a new Bounds that is with a new Size of the specified dimensions.
func (Bounds) Shrink ¶
Shrink returns a new Bounds that has a size that is smaller by the given amount compared to these Bounds.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas represents a mechanism through which an Element can render itself to the screen.
func (Canvas) Clip ¶
func (c Canvas) Clip(bounds Bounds)
Clip sets new clipping bounds. Pixels from draw operations that are outside the clipping bounds will not be drawn.
Initially the clipping bounds are equal to the window size.
func (Canvas) Contour ¶ added in v0.3.0
func (c Canvas) Contour() *Contour
Contour returns the contour rendering module.
func (Canvas) DrawSurface ¶ added in v0.3.0
DrawSurface renders the specified surface. The surface's Render method will be called when needed with the UI framebuffer bound.
func (Canvas) Pop ¶
func (c Canvas) Pop()
Pop restores the drawing state based on the parent layer. If this is the first layer, then this method panics.
func (Canvas) Push ¶
func (c Canvas) Push()
Push records the current state and creates a new state layer. Changes done in the new layer will not affect the parent layer.
You may create up to 256 layers including the starting one after which the method panics.
func (Canvas) ResetTransform ¶ added in v0.4.0
func (c Canvas) ResetTransform()
ResetTransform restores the transform to the value it had after the last Push. If this is the first layer, then it is set to the identity matrix.
func (Canvas) SetClipBounds ¶ added in v0.4.0
func (c Canvas) SetClipBounds(left, right, top, bottom float32)
func (Canvas) SetTransform ¶ added in v0.4.0
SetTransform changes the transform relative to the former layer transform.
func (Canvas) Shape ¶ added in v0.3.0
func (c Canvas) Shape() *Shape
Shape returns the shape rendering module.
type Color ¶
Color represents a 32bit color (8 bits per channel).
func ColorWithAlpha ¶ added in v0.3.0
ColorWithAlpha returns a new color that based on the specified color but with adjusted alpha channel.
func RGB ¶
RGB creates a new Color off of the specified R (Red), G (Green), B (Blue) components. The alpha of the Color is set to 255 (opaque).
func RGBA ¶
RGBA creates a new Color off of the specified R (Red), G (Green), B (Blue), A (Alpha) components.
func (Color) Opaque ¶
Opaque returns whether this color is opaque. (i.e. has an alpha with the maximum value)
func (Color) Translucent ¶
Translucent returns whether this color is translucent.
A translucent color is one that is not fully visible (i.e. has an alpha value smaller than the maximum).
func (Color) Transparent ¶
Transparent returns whether this color is transparent.
A transparent color is one that is not at all visible (i.e. has an alpha value equal to zero).
type Config ¶ added in v0.4.0
type Config struct {
// contains filtered or unexported fields
}
func NewConfig ¶ added in v0.4.0
func NewConfig(locator ResourceLocator, renderAPI render.API, shaders ShaderCollection) *Config
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the lifecycle and resource allocation of an Element hierarchy.
func (*Context) CreateContext ¶ added in v0.4.0
CreateContext returns a new Context that is a child of the current Context and as such can reuse resources held by the current context.
func (*Context) CreateElement ¶
CreateElement creates a new Element instance.
The returned Element is not attached to anything and will not be drawn or processed in any way until it is attached to the Element hierarchy.
Depending on what you allocate within the context of this Element, make sure to Delete this Element once done. Alternatively, as long as the Element is part of a hierarchy, you could leave that to the View that owns the hierarchy, which will clean everything in its hierarchy, once closed.
func (*Context) CreateFont ¶ added in v0.4.0
CreateFont creates a new Font resource.
The Font will be destroyed once this Context is destroyed.
func (*Context) CreateFontCollection ¶ added in v0.4.0
func (c *Context) CreateFontCollection(collection *opentype.Collection) (*FontCollection, error)
CreateFontCollection creates a new FontCollection resource.
The FontCollection will be destroyed once this Context is destroyed.
func (*Context) CreateImage ¶ added in v0.3.0
CreateImage creates a new Image resource.
The Image will be destroyed once this Context is destroyed.
func (*Context) Destroy ¶ added in v0.4.0
func (c *Context) Destroy()
Destroy releases all resources held by this Context.
func (*Context) GetFont ¶
GetFont returns the Font with the specified family and sub-family name from all of the created or loaded fonts and/or family collections.
func (*Context) OpenFont ¶ added in v0.4.0
OpenFont opens the Font at the specified URI location.
The URI is interpreted according to the used ResourceLocator.
The Font will be destroyed once this Context is destroyed.
func (*Context) OpenFontCollection ¶
func (c *Context) OpenFontCollection(uri string) (*FontCollection, error)
OpenFontCollection opens the FontCollection at the specified URI location.
The URI is interpreted according to the used ResourceLocator.
The FontCollection will be destroyed once this Context is destroyed.
func (*Context) OpenImage ¶
OpenImage opens the Image at the specified URI location.
The URI is interpreted according to the used ResourceLocator.
The Image will be destroyed once this Context is destroyed.
func (*Context) Schedule ¶
func (c *Context) Schedule(fn func())
Schedule appends the specified function to be called from the main thread (main goroutine).
This function is safe for concurrent use, though such use would not guarantee any order for the functions that are being concurrently added.
This function can be called from both the main thread, as well as from other goroutines.
There is a limit on the number of functions that can be queued within a given frame iteration. Once the buffer is full, new functions will be dropped.
type Contour ¶ added in v0.3.0
type Contour struct {
// contains filtered or unexported fields
}
Contour represents a module for drawing curved lines.
func (*Contour) Begin ¶ added in v0.3.0
func (c *Contour) Begin()
Begin starts a new contour. Make sure to use End when finished with the contour.
func (*Contour) Circle ¶ added in v0.3.0
Circle is a helper function that draws a circle at the specified position and with the specified radius using a sequence of Shape instructions (whether MoveTo, LineTo or Bezier curves are used is up to the implementation).
func (*Contour) CloseLoop ¶ added in v0.3.0
func (c *Contour) CloseLoop()
CloseLoop makes an automatic line connection back to the starting point, as specified via MoveTo.
func (*Contour) CubeTo ¶ added in v0.3.0
CubeTo creates a cubic Bezier curve from the last cursor position to the newly specified position by going past the two specified control points. The target position is assigned the specified stroke setting.
func (*Contour) End ¶ added in v0.3.0
func (c *Contour) End()
End marks the end of the contour and pushes all collected data for drawing.
func (*Contour) LineTo ¶ added in v0.3.0
LineTo creates a direct line from the last cursor position to the newly specified position and sets the specified stroke for the new position.
func (*Contour) MoveTo ¶ added in v0.3.0
MoveTo positions the cursor to the specified position and marks the specified stroke setting for that point.
func (*Contour) QuadTo ¶ added in v0.3.0
QuadTo creates a quadratic Bezier curve from the last cursor position to the newly specified position by going past the specified control point. The target position is assigned the specified stroke setting.
func (*Contour) Rectangle ¶ added in v0.3.0
Rectangle is a helper function that draws the outline of a rectangle at the specified position and size using a sequence of MoveTo and LineTo instructions.
func (*Contour) RoundRectangle ¶ added in v0.3.0
func (c *Contour) RoundRectangle(position, size sprec.Vec2, roundness RectRoundness, stroke Stroke)
RoundRectangle is a helper function that draws a rounded rectangle at the specified position and with the specified size and corner radiuses.
type ContourMesh ¶ added in v0.4.0
type ContourMesh struct {
// contains filtered or unexported fields
}
func (*ContourMesh) Allocate ¶ added in v0.4.0
func (m *ContourMesh) Allocate(api render.API)
func (*ContourMesh) Append ¶ added in v0.4.0
func (m *ContourMesh) Append(vertex ContourVertex)
func (*ContourMesh) Offset ¶ added in v0.4.0
func (m *ContourMesh) Offset() int
func (*ContourMesh) Release ¶ added in v0.4.0
func (m *ContourMesh) Release()
func (*ContourMesh) Reset ¶ added in v0.4.0
func (m *ContourMesh) Reset()
func (*ContourMesh) Update ¶ added in v0.4.0
func (m *ContourMesh) Update()
type ContourVertex ¶ added in v0.4.0
type ContourVertex struct {
// contains filtered or unexported fields
}
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents a hierarchical entity on the screen. It need not necessarily be a control and could just be an intermediate element used to group Controls.
func (*Element) AppendChild ¶
AppendChild adds the specified Element as the right-most child of this Element. If the appended Element already has a parent, it is first detached from that parent.
func (*Element) AppendSibling ¶
AppendSibling attaches an Element to the right of the current one.
func (*Element) Bounds ¶
Bounds returns the bounds of this Element relative to its parent. If it is a top-most Element, then the bounds are relative to the Window's content area.
func (*Element) ContentBounds ¶
ContentBounds returns the bounds of the content area of this Element relative to the Element itself. The content bounds are calculated based on the Element's bounds and padding.
func (*Element) Destroy ¶
func (e *Element) Destroy()
Destroy removes this Element from the hierarchy, as well as any child Elements and releases all allocated resources.
func (*Element) Detach ¶
func (e *Element) Detach()
Detach removes this Element from the hierarchy but does not release any resources.
func (*Element) Essence ¶
Essence returns the Essence that is responsible for the behavior of this Element.
func (*Element) FirstChild ¶
FirstChild returns the first (left-most) child Element of this Element. If this Element does not have any children then this method returns nil.
func (*Element) Focusable ¶ added in v0.3.0
Focusable returns whether this Element can receive keyboard events. When an element if focusable and a mouse down event is received, it becomes the focused element and will begin to receive keyboard events.
func (*Element) ID ¶
ID returns the ID of this Element. If an ID was not specified, then an emptry string is returned.
func (*Element) IdealSize ¶
IdealSize returns the ideal dimensions for this Element, which could (but not necessarily) be taken into consideration by layout containers.
func (*Element) InjectEssence ¶
func (e *Element) InjectEssence(target interface{})
InjectEssence assigns the Essence of this Element to the target. If the target is not a pointer to the correct type, this method panics.
func (*Element) LastChild ¶
LastChild returns the last (right-most) child Element of this Element. If this Element does not have any children then this method returns nil.
func (*Element) LayoutConfig ¶
func (e *Element) LayoutConfig() LayoutConfig
LayoutConfig returns the layout configuration for this Element. The actual implementation of the LayoutConfig interface depends on the owner Element. If this Element does not have any layout preference, then nil is returned.
func (*Element) LeftSibling ¶
LeftSibling returns the left sibling Element of this Element. If this Element is the left-most child of its parent or does not have a parent then this method returns nil.
func (*Element) Padding ¶
Padding returns the spacing that should be maintained inside an Element between its outer bounds and its content area. This setting could affect the layouting of child Elements and clipping during rendering.
func (*Element) Parent ¶
Parent returns the parent Element in the hierarchy. If this is the top-most Element then nil is returned.
func (*Element) PrependChild ¶
PrependChild adds the specified Element as the left-most child of this Element. If the preprended Element already has a parent, it is first detached from that parent.
func (*Element) RemoveChild ¶
RemoveChild removes the specified Element from the list of children held by this Element. If the specified Element is not a child of this Element, then nothing happens.
func (*Element) RightSibling ¶
RightSibling returns the right sibling Element of this Element. If this Element is the right-most child of its parent or does not have a parent then this method returns nil.
func (*Element) SetBounds ¶
SetBounds configures this Element's bounds relative to its parent. If it is a top-most element, then the bounds are relative to the Window's content area.
func (*Element) SetEnabled ¶
SetEnabled specifies whether this Element should be enabled for user interaction.
func (*Element) SetEssence ¶
SetEssence changes the Essence that is to control the behavior and represent the purpose of this Element. Specifying nil indicates that this is a plain Element that will not handle events in any special way.
func (*Element) SetFocusable ¶ added in v0.3.0
SetFocusable controls whether this Element should receive keyboard events.
func (*Element) SetID ¶
SetID changes the ID of this Element. If this Element represents a Control, then this ID would affect the ID of that owner Control.
func (*Element) SetIdealSize ¶
SetIdealSize changes this Element's ideal dimensions.
func (*Element) SetLayout ¶
SetLayout changes this Element's layout. If specified, this Element's children will be positioned according to the specified Layout. If nil is specified, then child Elements are not repositioned in any way and will use their configured bounds as positioning and size.
func (*Element) SetLayoutConfig ¶
func (e *Element) SetLayoutConfig(layoutConfig LayoutConfig)
SetLayoutConfig changes this Element's layout configuration. The provided implementation should match the requirements of the parent layout Element, otherwise they will not be taken into consideration. If nil is specified, then default layouting should be used.
func (*Element) SetPadding ¶
SetPadding configures this Element's content area spacing.
func (*Element) SetVisible ¶
SetVisible controls whether this Element should be rendered.
type ElementKeyboardHandler ¶ added in v0.3.0
type ElementKeyboardHandler interface {
OnKeyboardEvent(element *Element, event KeyboardEvent) bool
}
ElementKeyboardHandler is a type of EventHandler that can be used to receive events when an element is focused and keyboard actions are performed.
type ElementMouseHandler ¶
type ElementMouseHandler interface {
OnMouseEvent(element *Element, event MouseEvent) bool
}
ElementMouseHandler is a type of ElementHandler that can be used to receive events when the mouse has interacted with a given Element.
type ElementRenderHandler ¶
ElementRenderHandler is a type of ElementHandler that can be used to receive events when a given Element is being rendered and to perform a custom rendering for the Element.
type ElementResizeHandler ¶
ElementResizeHandler is a type of ElementHandler that can be used to receive events when an Element has been resized.
type Essence ¶
type Essence interface{}
Essence represents the behavior that is attached to an Element. For example, the actual value behind the interface could be a specific UI control and/or a handler.
type FSResourceLocator ¶ added in v0.3.0
type FSResourceLocator struct {
// contains filtered or unexported fields
}
FileResourceLocator is an implementation of ResourceLocator that uses the fs.FS abstraction to load resources. This allows the API to be used with embedded files, for example.
func NewFSResourceLocator ¶ added in v0.3.0
func NewFSResourceLocator(filesys fs.FS) *FSResourceLocator
NewFSResourceLocator returns a new instance of FSResourceLocator that uses the specified fs.FS to load resources.
func (*FSResourceLocator) OpenResource ¶ added in v0.3.0
func (l *FSResourceLocator) OpenResource(uri string) (io.ReadCloser, error)
OpenResource opens the resource at the specified URI location.
type FileResourceLocator ¶
type FileResourceLocator struct {
// contains filtered or unexported fields
}
FileResourceLocator is an implementation of ResourceLocator that uses the local filesystem to open resources.
func NewFileResourceLocator ¶ added in v0.3.0
func NewFileResourceLocator(dir string) *FileResourceLocator
NewFileResourceLocator returns a new FileResourceLocator that is configured to search for resources relative to dir.
func (*FileResourceLocator) OpenResource ¶
func (l *FileResourceLocator) OpenResource(uri string) (io.ReadCloser, error)
OpenResource opens the resource at the specified relative URI path.
type FilepathPayload ¶ added in v0.3.0
type FilepathPayload = app.FilepathPayload
FilepathPayload is a type of Payload that occurs when files have been dragged and dropped into the window.
type Fill ¶ added in v0.3.0
type Fill struct { // Rule specifies the mechanism through which it is determined // which point is part of the shape in an overlapping or concave // polygon. Rule FillRule // Color specifies the color to use to fill the shape. Color Color // Image specifies an optional image to be used for filling // the shape. Image *Image // ImageOffset determines the offset of the origin of the // image relative to the current translation context. ImageOffset sprec.Vec2 // ImageSize determines the size of the drawn image. In // essence, this size performs scaling. ImageSize sprec.Vec2 }
Fill configures how a solid shape is to be drawn.
type FillLayout ¶ added in v0.3.0
type FillLayout struct{}
FillLayout resizes the children to fill the content space of the parent element.
func NewFillLayout ¶ added in v0.3.0
func NewFillLayout() *FillLayout
NewFillLayout returns a new FillLayout instance.
func (*FillLayout) Apply ¶ added in v0.3.0
func (l *FillLayout) Apply(element *Element)
Apply applies this layout to the specified Element.
type FillRule ¶ added in v0.3.0
type FillRule int
FillRule represents the mechanism through which it is determined which point is part of the shape in an overlapping or concave polygon.
const ( // FillRuleSimple is the fastest approach and should be used // with non-overlapping concave shapes. FillRuleSimple FillRule = iota // FillRuleNonZero will fill areas that are covered by the // shape, regardless if it overlaps. FillRuleNonZero // FillRuleEvenOdd will fill areas that are covered by the // shape and it does not overlap or overlaps an odd number // of times. FillRuleEvenOdd )
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
Font represents a text Font.
func (*Font) Destroy ¶ added in v0.4.0
func (f *Font) Destroy()
Destroy releases all resources related to this font.
type FontCollection ¶
type FontCollection struct {
// contains filtered or unexported fields
}
FontCollection represents a collection of Fonts.
func (*FontCollection) Destroy ¶ added in v0.4.0
func (c *FontCollection) Destroy()
func (*FontCollection) Fonts ¶
func (c *FontCollection) Fonts() []*Font
Fonts returns all Fonts contained by this collection.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image represents a 2D image.
type InitFunc ¶
type InitFunc func(window *Window)
InitFunc can be used to initialize the Window with the respective Element hierarchy.
type KeyModifierSet ¶
type KeyModifierSet = app.KeyModifierSet
KeyModifierSet is used to indicate which modifier keys were active at the event occurrence.
type KeyboardEvent ¶
type KeyboardEvent struct { // Type specifies the keyboard event type. Type KeyboardEventType // Code returns the code of the keyboard key. Code KeyCode // Rune returns the character that was typed in case // of an KeyboardEventTypeType event. Rune rune // Modifiers contains a set of modifier keys that were // pressed during the event. Modifiers KeyModifierSet }
KeyboardEvent is used to propagate events related to keyboard actions.
func (KeyboardEvent) String ¶
func (e KeyboardEvent) String() string
String returns a string representation for this keyboard event.
type KeyboardEventType ¶
type KeyboardEventType = app.KeyboardEventType
KeyboardEventType is used to specify the type of keyboard action that occurred.
type Layout ¶
type Layout interface { // Apply applies this layout to the specified Element. Apply(element *Element) }
Layout represents an algorithm through which child Elements are positioned on the screen relative to their parent.
type LayoutConfig ¶
type LayoutConfig interface{}
LayoutConfig represents a layout configuration for an Element. The actual implementation of this interface is determined by the parent Element's layout model.
type MouseEvent ¶
type MouseEvent struct { // Index indicates which mouse triggered the event. By default // the index for a the primary mouse is 0. // This is applicable for devices with multiple pointers // (mobile) or in case a second mouse is emulated // (e.g. with a game controller). Index int // Position specifies the moust position relative to the receiver. Position Position // Type specifies the mouse event type. Type MouseEventType // Button specifies the button for which the event is // applicable. Button MouseButton // ScrollX determines the amount of horizontal scroll. ScrollX float64 // ScrollY determines the amount of vertical scroll. ScrollY float64 // Payload contains the data that was dropped. Payload interface{} }
MouseEvent represents an event related to a mouse action.
func (MouseEvent) String ¶
func (e MouseEvent) String() string
String returns a string representation for this mouse event.
type MouseEventType ¶
type MouseEventType = app.MouseEventType
MouseEventType represents the type of mouse event.
type Position ¶
Position represents a position on the screen that can either be absolute or relative, depending on the context.
func NewPosition ¶
NewPosition creates a new Position with the specified coordinates.
type RectRoundness ¶ added in v0.3.0
type RectRoundness struct { // TopLeftRadius specifies the radius of the top-left corner. TopLeftRadius float32 // TopRightRadius specifies the radius of the top-right corner. TopRightRadius float32 // BottomLeftRadius specifies the radius of the bottom-left corner. BottomLeftRadius float32 // BottomRightRadius specifies the radius of the bottom-right corner. BottomRightRadius float32 }
RectRoundness is used to configure the roundness of a round rectangle through corner radiuses.
type ResourceLocator ¶
type ResourceLocator interface { // OpenResource opens the resource at the specified // URI address. OpenResource(uri string) (io.ReadCloser, error) }
ResourceLocator represents a logic by which resources can be opened based off of a URI address.
This allows resources (e.g. Images, Fonts) to be accessed from the filesystem, from the network, or from a custom bundle file.
type ShaderCollection ¶ added in v0.4.0
type Shape ¶ added in v0.3.0
type Shape struct {
// contains filtered or unexported fields
}
Shape represents a module for drawing solid shapes.
func (*Shape) Begin ¶ added in v0.3.0
Begin starts a new solid shape using the specified fill settings. Make sure to use End when finished with the shape.
func (*Shape) Circle ¶ added in v0.3.0
Circle is a helper function that draws a circle at the specified position and with the specified radius using a sequence of Shape instructions (whether MoveTo, LineTo or Bezier curves are used is up to the implementation).
func (*Shape) CubeTo ¶ added in v0.3.0
CubeTo creates a cubic Bezier curve from the last cursor position to the newly specified position by going past the two specified control points.
func (*Shape) End ¶ added in v0.3.0
func (s *Shape) End()
End marks the end of the shape and pushes all collected data for drawing.
func (*Shape) LineTo ¶ added in v0.3.0
LineTo creates a direct line from the last cursor position to the newly specified position.
func (*Shape) QuadTo ¶ added in v0.3.0
QuadTo creates a quadratic Bezier curve from the last cursor position to the newly specified position by going past the specified control point.
func (*Shape) Rectangle ¶ added in v0.3.0
Rectangle is a helper function that draws a rectangle at the specified position and size using a sequence of MoveTo and LineTo instructions.
func (*Shape) RoundRectangle ¶ added in v0.3.0
func (s *Shape) RoundRectangle(position, size sprec.Vec2, roundness RectRoundness)
RoundRectangle is a helper function that draws a rounded rectangle at the specified position and with the specified size and corner radiuses.
type ShapeMesh ¶ added in v0.4.0
type ShapeMesh struct {
// contains filtered or unexported fields
}
func (*ShapeMesh) Append ¶ added in v0.4.0
func (m *ShapeMesh) Append(vertex ShapeVertex)
type ShapeVertex ¶ added in v0.4.0
type ShapeVertex struct {
// contains filtered or unexported fields
}
type Size ¶
Size represents the dimensions of something on the screen.
type Spacing ¶
Spacing represents a spacing around or inside a given screen entity (e.g. Element).
func (Spacing) Horizontal ¶
Horizontal returns the horizontal amount of spacing.
type Stroke ¶ added in v0.3.0
type Stroke struct { // Size determines the size of the contour. Size float32 // Color specifies the color of the contour. Color Color }
Stroke configures how a contour is to be drawn.
type Text ¶ added in v0.3.0
type Text struct {
// contains filtered or unexported fields
}
Text represents a module for drawing text.
func (*Text) Begin ¶ added in v0.3.0
func (t *Text) Begin(typography Typography)
Begin starts a new text sequence using the specified typography settings. Make sure to use End when finished with the text.
type TextMesh ¶ added in v0.4.0
type TextMesh struct {
// contains filtered or unexported fields
}
func (*TextMesh) Append ¶ added in v0.4.0
func (m *TextMesh) Append(vertex TextVertex)
type TextVertex ¶ added in v0.4.0
type TextVertex struct {
// contains filtered or unexported fields
}
type Typography ¶ added in v0.3.0
type Typography struct { // Font specifies the font to be used. Font *Font // Size specifies the font size. Size float32 // Color indicates the color of the text. Color Color }
Typography configures how text is to be drawn.
type Window ¶
Window represents an application window.
func (*Window) Context ¶
Context returns the Context for this Window.
Note that anything allocated through this Context will not be released until this Window is closed.
func (*Window) DiscardFocus ¶ added in v0.3.0
func (w *Window) DiscardFocus()
DiscardFocus removes the focus from any Element.
func (*Window) FindElementByID ¶
FindElementByID looks through the Element hierarchy tree for an Element with the specified ID.
func (*Window) GetElementByID ¶
GetElementByID looks through the Element hierarchy tree for an Element with the specified ID. Unlike FindElementByID, this method panics if such an Element cannot be found.
func (*Window) IsElementFocused ¶ added in v0.3.0
IsElementFocused returns whether the specified element is the currently focused Element.
type WindowHandler ¶
type WindowHandler interface { // OnResize is called whenever the native window has // been resized. OnResize(size Size) // OnFramebufferResize is called whenever the native window's // framebuffer has been resized. OnFramebufferResize(size Size) // OnKeyboardEvent is called whenever a native key event // has been registered. OnKeyboardEvent(event KeyboardEvent) bool // OnMouseEvent is called whenever a native mouse event // has been registered. OnMouseEvent(event MouseEvent) bool // OnRender is called whenever the Window should redraw // itself. OnRender() // OnCloseRequested is called whenever the end-user has // indicated that they would like to close the appplication. // (e.g. using the close button on the application) OnCloseRequested() }
WindowHandler is an interface that is used by the framework to communicate with Window implementations critical events.
Source Files
¶
- bounds.go
- canvas.go
- canvas_contour.go
- canvas_material.go
- canvas_mesh.go
- canvas_renderer.go
- canvas_shape.go
- canvas_state.go
- canvas_text.go
- color.go
- config.go
- context.go
- controller.go
- doc.go
- element.go
- font.go
- font_factory.go
- graphics.go
- image.go
- image_factory.go
- keyboard.go
- layout.go
- mouse.go
- position.go
- resource.go
- resource_manager.go
- size.go
- spacing.go
- util.go
- window.go
Directories
¶
Path | Synopsis |
---|---|
Package component features a framework, inspired by React and Redux, that allows you to extend the basic ui package with custom Components on top of plain ui Elements.
|
Package component features a framework, inspired by React and Redux, that allows you to extend the basic ui package with custom Components on top of plain ui Elements. |
Package mat provides a collection of Components that can be used to construct a higher-order user interface.
|
Package mat provides a collection of Components that can be used to construct a higher-order user interface. |
Package optional contains primitive types and ui types that can have an unspecified state.
|
Package optional contains primitive types and ui types that can have an unspecified state. |