canvas

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

View Source
var ZP = Point{}
View Source
var ZR = Rectangle{}

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

Canvas represents an HTML <canvas> element and its associated 2D rendering context.

func New

func New(elem js.Value) (*Canvas, error)

New returns a new Canvas that wraps the <canvas> elem. This will most likely be retrieved using

js.Global.Get("document").Call("getElementById", id)

If the browser doesn't support CanvasRenderingContext2D, an error is returned.

func (*Canvas) Clear

func (c *Canvas) Clear(r Rectangle)

Clear clears the pixels in the rectangle specified by r.

func (*Canvas) Height

func (c *Canvas) Height() float64

Height returns the height of the canvas.

func (*Canvas) MeasureText

func (c *Canvas) MeasureText(text string) (tm TextMetrics)

MeasureText returns a TextMetrics containing information about the string text.

func (*Canvas) Path

func (c *Canvas) Path(p func(*PathBuilder)) Object

Path returns an Object that draws a path build by the function p. For more information, see the documentation for PathBuilder.

func (*Canvas) Rect

func (c *Canvas) Rect(r Rectangle) Object

Rect returns an Object that draws a rectangle with the given bounds.

func (*Canvas) Text

func (c *Canvas) Text(text string, mw float64) Object

Text returns an Object that draws the string text. If mw is a positive number, than it specifies the maximumWidth parameter of the canvas context's fillText() and drawText() methods.

func (*Canvas) Width

func (c *Canvas) Width() float64

Width returns the width of the canvas.

type Font

type Font struct {
	Size int
	Name string
}

func (Font) String

func (f Font) String() string

type LineCap

type LineCap int
const (
	ButtCap LineCap = iota
	RoundCap
	SquareCap
)

func (LineCap) String

func (lc LineCap) String() string

type LineJoin

type LineJoin int
const (
	BevelJoin LineJoin = iota
	RoundJoin
	MiterJoin
)

func (LineJoin) String

func (lj LineJoin) String() string

type Object

type Object interface {
	// Stroke draws an outline of the Object.
	Stroke(Point)

	// Fill fills the area of the canvas represented by the Object.
	Fill(Point)

	// Set various styles having to do with drawing lines. For more
	// information, see the CanvasRenderingContext2D documentation.
	SetLineWidth(float64)
	SetLineCap(LineCap)
	SetLineJoin(LineJoin)
	SetMiterLimit(float64)
	SetLineDash([]float64)
}

Object represents an object that can be drawn on the canvas.

type PathBuilder

type PathBuilder struct {
	// contains filtered or unexported fields
}

PathBuilder is a type that is passed to a function used to create a custom, path-based object. See the documentation for (*Canvas).Path().

func (PathBuilder) Arc

func (pb PathBuilder) Arc(c Point, r float64, sa, ea float64, cc bool)

Add an arc to the path.

func (PathBuilder) Bezier

func (pb PathBuilder) Bezier(cp1, cp2, end Point)

Add a bezier curve to the path.

func (PathBuilder) Line

func (pb PathBuilder) Line(p Point)

Add a line from the current position to p to the path.

func (PathBuilder) MoveTo

func (pb PathBuilder) MoveTo(p Point)

Moves the current postion to p.

func (PathBuilder) Quadratic

func (pb PathBuilder) Quadratic(cp, end Point)

Add a quadratic curve to the path.

func (PathBuilder) Rect

func (pb PathBuilder) Rect(r Rectangle)

Adds the rectangle r to the path.

type Point

type Point struct {
	X, Y float64
}

Point represents a point on the cartesian plane. It is patterned after image.Point, but is float64 based.

func Pt

func Pt(x, y float64) Point

type Rectangle

type Rectangle struct {
	Min, Max Point
}

Rectangle represents a rectangle. It is patterned after image.Rectangle, but is float64 based.

func Rect

func Rect(x1, y1, x2, y2 float64) Rectangle

func (Rectangle) Canon

func (r Rectangle) Canon() Rectangle

func (Rectangle) Dx

func (r Rectangle) Dx() float64

func (Rectangle) Dy

func (r Rectangle) Dy() float64

type TextMetrics

type TextMetrics struct {
	// contains filtered or unexported fields
}

func (TextMetrics) ActualBoundingBoxAscent

func (tm TextMetrics) ActualBoundingBoxAscent() float64

func (TextMetrics) ActualBoundingBoxDescent

func (tm TextMetrics) ActualBoundingBoxDescent() float64

func (TextMetrics) ActualBoundingBoxLeft

func (tm TextMetrics) ActualBoundingBoxLeft() float64

func (TextMetrics) ActualBoundingBoxRight

func (tm TextMetrics) ActualBoundingBoxRight() float64

func (TextMetrics) AlphabeticBaseline

func (tm TextMetrics) AlphabeticBaseline() float64

func (TextMetrics) EmHeightAscent

func (tm TextMetrics) EmHeightAscent() float64

func (TextMetrics) EmHeightDescent

func (tm TextMetrics) EmHeightDescent() float64

func (TextMetrics) FontBoundingBoxAscent

func (tm TextMetrics) FontBoundingBoxAscent() float64

func (TextMetrics) FontBoundingBoxDescent

func (tm TextMetrics) FontBoundingBoxDescent() float64

func (TextMetrics) HangingBaseline

func (tm TextMetrics) HangingBaseline() float64

func (TextMetrics) IdeographicBaseline

func (tm TextMetrics) IdeographicBaseline() float64

func (TextMetrics) Width

func (tm TextMetrics) Width() float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL