Documentation ¶
Overview ¶
Naiad lets you create windows with shapes in them. It is designed for creating graphical user interfaces. It wraps pixel and provides a simple way to create and manipulate persistent shapes on screen. It is as cross platform as pixel is, which is to say, very. This library is not designed to be used in conjunction with pixel, it abstracts it away. Eventually it will just use raw OpenGL as a backend.
The reason this exists is because the browser DOM is very useful for building user interfaces because you can just make things and the browser abstracts away all the rendering logic. However, it is inherently resource intensive, has too much vestigial nonsense built into it, and it wasn't even designed for constructing user interfaces (being more oriented towards text documents).
Naiad is designed to let you have your cake and eat it too. You have full freedom to create whatever ridiculous shapes you want, with the ease of working with a DOM, and the assurance that your program will not end up being a 127 megabyte, cpu eating, ram eating piece of garbage.
On-screen shapes in Naiad are structured using groups. These groups contain paths (and soon text as well). At the top there is a root group which you are not allowed to mess with, but you can add things to it and remove things from it through methods defined on the window object.
Paths, in turn, are just lists of points. Each point contains information like position, color, and line cap type. The entire path contains stuff like line thickness, and if it should be filled or stroked.
Index ¶
- Constants
- func Run(callback func())
- type Key
- type LineCap
- type Point
- type Shape
- type ShapeGroup
- func (base *ShapeGroup) Bounds() (min, max Vector)
- func (group *ShapeGroup) Contains(position Vector) (shapes []Shape)
- func (base *ShapeGroup) Dirty() (isDirty bool)
- func (group *ShapeGroup) Kind() (kind ShapeKind)
- func (group *ShapeGroup) Lift(shape Shape) (found bool)
- func (group *ShapeGroup) Pop() (shape Shape)
- func (group *ShapeGroup) PopBottom() (shape Shape)
- func (group *ShapeGroup) Push(shape Shape)
- func (group *ShapeGroup) PushBottom(shape Shape)
- func (group *ShapeGroup) SetBounds(max Vector)
- func (base *ShapeGroup) SetClean()
- func (base *ShapeGroup) SetDirty()
- func (base *ShapeGroup) SetPosition(position Vector)
- func (base *ShapeGroup) SetX(x float64)
- func (base *ShapeGroup) SetY(y float64)
- func (base *ShapeGroup) X() (x float64)
- func (base *ShapeGroup) Y() (y float64)
- type ShapeKind
- type ShapePath
- func (base *ShapePath) Bounds() (min, max Vector)
- func (shape *ShapePath) Contains(position Vector) (shapes []Shape)
- func (base *ShapePath) Dirty() (isDirty bool)
- func (shape *ShapePath) Kind() (kind ShapeKind)
- func (shape *ShapePath) Open() (closed bool)
- func (shape *ShapePath) Pop() (point Point)
- func (shape *ShapePath) Push(point Point)
- func (base *ShapePath) SetClean()
- func (base *ShapePath) SetDirty()
- func (shape *ShapePath) SetOpen(open bool)
- func (base *ShapePath) SetPosition(position Vector)
- func (shape *ShapePath) SetThickness(thickness float64)
- func (base *ShapePath) SetX(x float64)
- func (base *ShapePath) SetY(y float64)
- func (shape *ShapePath) Thickness() (thickness float64)
- func (base *ShapePath) X() (x float64)
- func (base *ShapePath) Y() (y float64)
- type Vector
- type Window
- func (window *Window) Await(timeout time.Duration)
- func (window *Window) Bounds() (min, max Vector)
- func (window *Window) Closed() (closed bool)
- func (base *Window) Dirty() (isDirty bool)
- func (window *Window) IsHovered(shape Shape) (hovered bool)
- func (window *Window) IsLeftClicked(shape Shape) (clicked bool)
- func (window *Window) IsLeftHeld(shape Shape) (held bool)
- func (window *Window) JustPressed(key Key) (pressed bool)
- func (window *Window) JustReleased(key Key) (released bool)
- func (window *Window) MouseHover() (hoveredShapes []Shape)
- func (window *Window) MouseLeftClick() (clickedShapes []Shape)
- func (window *Window) MouseLeftHold() (heldShapes []Shape)
- func (window *Window) MousePosition() (position Vector)
- func (window *Window) MousePreviousPosition() (previousPosition Vector)
- func (window *Window) Open() (err error)
- func (window *Window) Poll()
- func (window *Window) Pressed(key Key) (pressed bool)
- func (window *Window) Repeated(key Key) (repeated bool)
- func (window *Window) SetBounds(size Vector)
- func (base *Window) SetClean()
- func (base *Window) SetDirty()
- func (window *Window) SetIcon(icon ...image.Image)
- func (base *Window) SetPosition(position Vector)
- func (window *Window) SetTitle(title string)
- func (window *Window) SetTransparent(transparent bool)
- func (base *Window) SetX(x float64)
- func (base *Window) SetY(y float64)
- func (window *Window) Typed() (text string)
- func (base *Window) X() (x float64)
- func (base *Window) Y() (y float64)
Constants ¶
const ( KeyUnknown = Key(pixelgl.KeyUnknown) KeySpace = Key(pixelgl.KeySpace) KeyApostrophe = Key(pixelgl.KeyApostrophe) KeyComma = Key(pixelgl.KeyComma) KeyMinus = Key(pixelgl.KeyMinus) KeyPeriod = Key(pixelgl.KeyPeriod) KeySlash = Key(pixelgl.KeySlash) Key0 = Key(pixelgl.Key0) Key1 = Key(pixelgl.Key1) Key2 = Key(pixelgl.Key2) Key3 = Key(pixelgl.Key3) Key4 = Key(pixelgl.Key4) Key5 = Key(pixelgl.Key5) Key6 = Key(pixelgl.Key6) Key7 = Key(pixelgl.Key7) Key8 = Key(pixelgl.Key8) Key9 = Key(pixelgl.Key9) KeySemicolon = Key(pixelgl.KeySemicolon) KeyEqual = Key(pixelgl.KeyEqual) KeyA = Key(pixelgl.KeyA) KeyB = Key(pixelgl.KeyB) KeyC = Key(pixelgl.KeyC) KeyD = Key(pixelgl.KeyD) KeyE = Key(pixelgl.KeyE) KeyF = Key(pixelgl.KeyF) KeyG = Key(pixelgl.KeyG) KeyH = Key(pixelgl.KeyH) KeyI = Key(pixelgl.KeyI) KeyJ = Key(pixelgl.KeyJ) KeyK = Key(pixelgl.KeyK) KeyL = Key(pixelgl.KeyL) KeyM = Key(pixelgl.KeyM) KeyN = Key(pixelgl.KeyN) KeyO = Key(pixelgl.KeyO) KeyP = Key(pixelgl.KeyP) KeyQ = Key(pixelgl.KeyQ) KeyR = Key(pixelgl.KeyR) KeyS = Key(pixelgl.KeyS) KeyT = Key(pixelgl.KeyT) KeyU = Key(pixelgl.KeyU) KeyV = Key(pixelgl.KeyV) KeyW = Key(pixelgl.KeyW) KeyX = Key(pixelgl.KeyX) KeyY = Key(pixelgl.KeyY) KeyZ = Key(pixelgl.KeyZ) KeyLeftBracket = Key(pixelgl.KeyLeftBracket) KeyBackslash = Key(pixelgl.KeyBackslash) KeyRightBracket = Key(pixelgl.KeyRightBracket) KeyGraveAccent = Key(pixelgl.KeyGraveAccent) KeyWorld1 = Key(pixelgl.KeyWorld1) KeyWorld2 = Key(pixelgl.KeyWorld2) KeyEscape = Key(pixelgl.KeyEscape) KeyEnter = Key(pixelgl.KeyEnter) KeyTab = Key(pixelgl.KeyTab) KeyBackspace = Key(pixelgl.KeyBackspace) KeyInsert = Key(pixelgl.KeyInsert) KeyDelete = Key(pixelgl.KeyDelete) KeyRight = Key(pixelgl.KeyRight) KeyLeft = Key(pixelgl.KeyLeft) KeyDown = Key(pixelgl.KeyDown) KeyUp = Key(pixelgl.KeyUp) KeyPageUp = Key(pixelgl.KeyPageUp) KeyPageDown = Key(pixelgl.KeyPageDown) KeyHome = Key(pixelgl.KeyHome) KeyEnd = Key(pixelgl.KeyEnd) KeyCapsLock = Key(pixelgl.KeyCapsLock) KeyScrollLock = Key(pixelgl.KeyScrollLock) KeyNumLock = Key(pixelgl.KeyNumLock) KeyPrintScreen = Key(pixelgl.KeyPrintScreen) KeyPause = Key(pixelgl.KeyPause) KeyF1 = Key(pixelgl.KeyF1) KeyF2 = Key(pixelgl.KeyF2) KeyF3 = Key(pixelgl.KeyF3) KeyF4 = Key(pixelgl.KeyF4) KeyF5 = Key(pixelgl.KeyF5) KeyF6 = Key(pixelgl.KeyF6) KeyF7 = Key(pixelgl.KeyF7) KeyF8 = Key(pixelgl.KeyF8) KeyF9 = Key(pixelgl.KeyF9) KeyF10 = Key(pixelgl.KeyF10) KeyF11 = Key(pixelgl.KeyF11) KeyF12 = Key(pixelgl.KeyF12) KeyF13 = Key(pixelgl.KeyF13) KeyF14 = Key(pixelgl.KeyF14) KeyF15 = Key(pixelgl.KeyF15) KeyF16 = Key(pixelgl.KeyF16) KeyF17 = Key(pixelgl.KeyF17) KeyF18 = Key(pixelgl.KeyF18) KeyF19 = Key(pixelgl.KeyF19) KeyF20 = Key(pixelgl.KeyF20) KeyF21 = Key(pixelgl.KeyF21) KeyF22 = Key(pixelgl.KeyF22) KeyF23 = Key(pixelgl.KeyF23) KeyF24 = Key(pixelgl.KeyF24) KeyF25 = Key(pixelgl.KeyF25) KeyKP0 = Key(pixelgl.KeyKP0) KeyKP1 = Key(pixelgl.KeyKP1) KeyKP2 = Key(pixelgl.KeyKP2) KeyKP3 = Key(pixelgl.KeyKP3) KeyKP4 = Key(pixelgl.KeyKP4) KeyKP5 = Key(pixelgl.KeyKP5) KeyKP6 = Key(pixelgl.KeyKP6) KeyKP7 = Key(pixelgl.KeyKP7) KeyKP8 = Key(pixelgl.KeyKP8) KeyKP9 = Key(pixelgl.KeyKP9) KeyKPDecimal = Key(pixelgl.KeyKPDecimal) KeyKPDivide = Key(pixelgl.KeyKPDivide) KeyKPMultiply = Key(pixelgl.KeyKPMultiply) KeyKPSubtract = Key(pixelgl.KeyKPSubtract) KeyKPAdd = Key(pixelgl.KeyKPAdd) KeyKPEnter = Key(pixelgl.KeyKPEnter) KeyKPEqual = Key(pixelgl.KeyKPEqual) KeyLeftShift = Key(pixelgl.KeyLeftShift) KeyLeftControl = Key(pixelgl.KeyLeftControl) KeyLeftAlt = Key(pixelgl.KeyLeftAlt) KeyLeftSuper = Key(pixelgl.KeyLeftSuper) KeyRightShift = Key(pixelgl.KeyRightShift) KeyRightControl = Key(pixelgl.KeyRightControl) KeyRightAlt = Key(pixelgl.KeyRightAlt) KeyRightSuper = Key(pixelgl.KeyRightSuper) KeyMenu = Key(pixelgl.KeyMenu) KeyLast = Key(pixelgl.KeyLast) )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LineCap ¶
type LineCap int
LineCap determines how corners and ends of lines should look. Each point has one of these values.
type Point ¶
type Point struct { Vector // contains filtered or unexported fields }
Point represents a single point on a path. It has information about its position, color, and line cap type.
type Shape ¶
type Shape interface { // Kind returns what kind of shape it is. Kind() (kind ShapeKind) // Dirty returns wether the shape is dirty or not. Dirty() (isDirty bool) // SetDirty causes the shape to be flagged as dirty. SetDirty() // SetClean causes the shape to be flagged as clean. SetClean() // Bounds returns the bounds of the shape, relative to its origin. This // is usually in the top left, which means min will usually be (0, 0). // Hovever, in shapes such as paths, the min bound may be in a different // spot due to things such as stroke thickness and points with negative // coordinates. Bounds() (min, max Vector) // Contains takes in mouse coordinates, and recursively checks if those // coordinates are contained in the shape or any of its children. It // returns a slice of all shapes (including itself) that the points are // contained within. If the position is not inside the shape, it should // immediately stop, return nil, and not recurse into anything else. Contains(position Vector) (shapes []Shape) // contains filtered or unexported methods }
Shape is an interface representing an on-screen shape. For a shape to be inserted into naiad's shape hierarchy, it must support these behaviors.
type ShapeGroup ¶
type ShapeGroup struct {
// contains filtered or unexported fields
}
ShapeGroup is a group containing other shapes. It has its own internal buffer that the shapes inside of it will be drawn to, reducing the need for redraws. It should be used to group objects composed of several different shapes together, especially if they move together.
func NewShapeGroup ¶
func NewShapeGroup( x, y float64, w, h float64, ) ( group *ShapeGroup, )
NewShapeGroup creates a new shape group with the specified position and bounds.
func (*ShapeGroup) Bounds ¶
func (base *ShapeGroup) Bounds() (min, max Vector)
Bounds returns the bounds of the shape, relative to its origin. This is usually in the top left, which means min will usually be (0, 0). Hovever, in shapes such as paths, the min bound may be in a different spot due to things such as stroke thickness and points with negative coordinates.
func (*ShapeGroup) Contains ¶
func (group *ShapeGroup) Contains(position Vector) (shapes []Shape)
Contains takes in mouse coordinates, and determines if they are inside of the shape. If it is, the returned slice will have one item pointing to this shape. If not, the returned slice will be nil.
func (*ShapeGroup) Dirty ¶
func (base *ShapeGroup) Dirty() (isDirty bool)
Dirty returns wether the shape is dirty or not.
func (*ShapeGroup) Kind ¶
func (group *ShapeGroup) Kind() (kind ShapeKind)
Kind returns ShapeKindGroup.
func (*ShapeGroup) Lift ¶
func (group *ShapeGroup) Lift(shape Shape) (found bool)
Lift removes the specified shape from the group. If it was found in the group, it returns true. If it was not found, it returns false.
func (*ShapeGroup) Pop ¶
func (group *ShapeGroup) Pop() (shape Shape)
Pop removes the top-most shape from the shape group, and returns it.
func (*ShapeGroup) PopBottom ¶
func (group *ShapeGroup) PopBottom() (shape Shape)
PopBottom removes the bottom-most shape from the shape group, and returns it.
func (*ShapeGroup) Push ¶
func (group *ShapeGroup) Push(shape Shape)
Push adds a new shape to the top of the shape group.
func (*ShapeGroup) PushBottom ¶
func (group *ShapeGroup) PushBottom(shape Shape)
PushBottom inserts a shape at the bottom of the shape group.
func (*ShapeGroup) SetBounds ¶
func (group *ShapeGroup) SetBounds(max Vector)
SetBounds sets the size of the shape group.
func (*ShapeGroup) SetClean ¶
func (base *ShapeGroup) SetClean()
SetClean causes the shape to be flagged as clean.
func (*ShapeGroup) SetDirty ¶
func (base *ShapeGroup) SetDirty()
SetDirty causes the shape to be flagged as dirty.
func (*ShapeGroup) SetPosition ¶
func (base *ShapeGroup) SetPosition(position Vector)
SetPosition sets the position of the shape.
func (*ShapeGroup) SetX ¶
func (base *ShapeGroup) SetX(x float64)
SetX sets the x position of the shape.
func (*ShapeGroup) SetY ¶
func (base *ShapeGroup) SetY(y float64)
SetY sets the y position of the shape.
type ShapeKind ¶
type ShapeKind int
ShapeKind determines what sort of shape a Shape should be cast to. It can be retrieved by calling the Kind() method.
type ShapePath ¶
type ShapePath struct {
// contains filtered or unexported fields
}
ShapePath is a polygon (or line) composed of a set of points.
func NewShapePath ¶
NewShapePath creates a new path at the given x and y coordinates.
func (*ShapePath) Bounds ¶
func (base *ShapePath) Bounds() (min, max Vector)
Bounds returns the bounds of the shape, relative to its origin. This is usually in the top left, which means min will usually be (0, 0). Hovever, in shapes such as paths, the min bound may be in a different spot due to things such as stroke thickness and points with negative coordinates.
func (*ShapePath) Contains ¶
Contains takes in mouse coordinates, and determines if they are inside of the shape. If it is, the returned slice will have one item pointing to this shape. If not, the returned slice will be nil.
func (*ShapePath) Dirty ¶
func (base *ShapePath) Dirty() (isDirty bool)
Dirty returns wether the shape is dirty or not.
func (*ShapePath) SetClean ¶
func (base *ShapePath) SetClean()
SetClean causes the shape to be flagged as clean.
func (*ShapePath) SetDirty ¶
func (base *ShapePath) SetDirty()
SetDirty causes the shape to be flagged as dirty.
func (*ShapePath) SetOpen ¶
SetOpen sets whether or not the shape is open on one end. Set this to false to create a polyline as opposed to a polygon.
func (*ShapePath) SetPosition ¶
func (base *ShapePath) SetPosition(position Vector)
SetPosition sets the position of the shape.
func (*ShapePath) SetThickness ¶
SetThickness sets the stroke thickness of the shape. If the thickness is 0, the shape will be filled instead.
func (*ShapePath) SetX ¶
func (base *ShapePath) SetX(x float64)
SetX sets the x position of the shape.
func (*ShapePath) SetY ¶
func (base *ShapePath) SetY(y float64)
SetY sets the y position of the shape.
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
Vector represents a coordinate pair. It can be used to specify things such as bounds, or 2D coordinates.
type Window ¶
type Window struct { ShapeGroup // contains filtered or unexported fields }
Window represents an on-screen window.
func (*Window) Await ¶
Await waits for an event to occur, or the timeout to elapse. It then redraws the screen if needed. If the timeout is zero, there won't actually be a timeout and it will just wait forever for an event.
func (*Window) Dirty ¶
func (base *Window) Dirty() (isDirty bool)
Dirty returns wether the shape is dirty or not.
func (*Window) IsHovered ¶
IsHovered returns whether or not the specified shape is being hovered over by the mouse.
func (*Window) IsLeftClicked ¶
IsLeftClicked returns whether or not the specified shape was just clicked with the left mouse button.
func (*Window) IsLeftHeld ¶
IsLeftHeld returns whether or not the specified shape is being held by the left mouse button.
func (*Window) JustPressed ¶
JustPressed returns whether a key has just been pressed down.
func (*Window) JustReleased ¶
JustReleased returns whether a key has just been released.
func (*Window) MouseHover ¶
MouseHover returns a list of all shapes the mouse is hovering over. The first shape is the least specific, and the last shape is the most specific.
func (*Window) MouseLeftClick ¶
MouseLeftClicked returns a list of alll shapes that were clicked with the left mouse button. This emulates behavior found in most other programs, where for an object to be clicked the mouse must be held down in that object, and then released in that object.
func (*Window) MouseLeftHold ¶
MouseLeftHold returns a list of all shapes that were under the mouse when its left button started being held down. If the mouse's left button is not currently being held down, this function returns nil.
func (*Window) MousePosition ¶
MousePosition returns the current position of the mouse inside the window bounds.
func (*Window) MousePreviousPosition ¶
MousePreviousPosition returns the position of the mouse inside the window bounds the previous time window.Await or window.Poll etc. was called.
func (*Window) Open ¶
Open brings the window on screen. If the window has already been opened, this method does nothing.
func (*Window) Poll ¶
func (window *Window) Poll()
Poll polls events, and redraws the screen if needed. This is non-blocking.
func (*Window) Repeated ¶
Repeated returns whether a repeat event is being triggered for a key (when it has been held down).
func (*Window) SetBounds ¶
SetBounds sets the size of the window to the dimensions specified by a vector.
func (*Window) SetClean ¶
func (base *Window) SetClean()
SetClean causes the shape to be flagged as clean.
func (*Window) SetDirty ¶
func (base *Window) SetDirty()
SetDirty causes the shape to be flagged as dirty.
func (*Window) SetIcon ¶
SetIcon takes in different resolutions of the same icon (all images) and sets the window icon. This will not do anything after open has been called.
func (*Window) SetPosition ¶
func (base *Window) SetPosition(position Vector)
SetPosition sets the position of the shape.
func (*Window) SetTransparent ¶
SetTransparent sets whether or not the window has a transparent framebuffer, if supported.