Documentation
¶
Overview ¶
Package vggio provides a vg.Canvas implementation backed by Gioui.
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultDPI = 96
DefaultDPI is the default dot resolution for image drawing in dots per inch.
Variables ¶
This section is empty.
Functions ¶
func UseBackgroundColor ¶
UseBackgroundColor specifies the image background color. Without UseBackgroundColor, the default color is white.
Types ¶
type Canvas ¶
Canvas implements the vg.Canvas interface, drawing to an image.Image using vgimg and painting that image into a Gioui context.
Example ¶
package main import ( "log" "os" "time" "gioui.org/app" "gioui.org/io/key" "gioui.org/io/system" "gioui.org/unit" "github.com/elamre/plot" "github.com/elamre/plot/vg" "github.com/elamre/plot/vg/draw" "github.com/elamre/plot/vg/vggio" ) func main() { const ( w = 20 * vg.Centimeter h = 15 * vg.Centimeter dpi = 96 ) go func(w, h vg.Length) { win := app.NewWindow( app.Title("Gonum"), app.Size( unit.Px(float32(w.Dots(dpi))), unit.Px(float32(h.Dots(dpi))), ), ) defer win.Close() done := time.NewTimer(2 * time.Second) defer done.Stop() for { select { case e := <-win.Events(): switch e := e.(type) { case system.FrameEvent: p, err := plot.New() if err != nil { log.Fatalf("could not create plot: %+v", err) } p.Title.Text = "My title" p.X.Label.Text = "X" p.Y.Label.Text = "Y" cnv := vggio.New(e, w, h, vggio.UseDPI(dpi)) p.Draw(draw.New(cnv)) cnv.Paint(e) case key.Event: switch e.Name { case "Q", key.NameEscape: os.Exit(0) } } case <-done.C: os.Exit(0) } } }(w, h) app.Main() }
Output:
func New ¶
func New(e system.FrameEvent, w, h vg.Length, opts ...option) *Canvas
New returns a new image canvas with the provided dimensions and options. The currently accepted options are UseDPI and UseBackgroundColor. If the resolution or background color are not specified, defaults are used.
func (*Canvas) Paint ¶
func (c *Canvas) Paint(e system.FrameEvent)
Paint paints the canvas' content on the screen.
Click to show internal directories.
Click to hide internal directories.