gui2image

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 7 Imported by: 0

README

gui2image

A renderer that rendering gui controls to image

Install

go get github.com/lonord/gui2image

Example

// use Paper as root control
rootControl := &Paper{
	Control: Control{Background: color.RGBA{200, 200, 200, 255}, Bounds: image.Rect(0, 0, 480, 320)},
}
// add a ImageView
f, err := os.Open(filepath.Join("testdata", "TestRenderImageView.Input.png"))
if err != nil {
	t.Fatal(err)
}
imgIn, err := png.Decode(f)
if err != nil {
	t.Fatal(err)
}
imgView := &ImageView{
	Control: Control{Background: color.RGBA{200, 200, 200, 255}, Bounds: image.Rect(140, 20, 340, 220)},
	Img:     imgIn,
}
rootControl.AddSub(imgView)
// add a Label
label := &Label{
	Control:   Control{Background: color.RGBA{200, 200, 200, 255}, Bounds: image.Rect(0, 240, 480, 320)},
	Text:      "hello world",
	FontSize:  18,
	TextColor: color.Black,
	HAlign:    AlignCenter,
	VAlign:    AlignCenter,
}
rootControl.AddSub(label)
// render
img := rootControl.Image()   // img is the output image

And output image is:

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlignType

type AlignType int

AlignType indicates align type

const (
	AlignBegin AlignType = iota
	AlignCenter
	AlignEnd
)

AlignType enum

type Control

type Control struct {
	Background color.Color
	Bounds     image.Rectangle
}

Control is the base view

func (*Control) Image

func (p *Control) Image() image.Image

Image implements method of View

type ImageView

type ImageView struct {
	Control
	Img image.Image
}

ImageView is the view display image

func (*ImageView) Image

func (v *ImageView) Image() image.Image

Image implements method of View

type Label

type Label struct {
	Control
	Text      string
	TextColor color.Color
	VAlign    AlignType
	HAlign    AlignType
	FontSize  float64
	Font      *truetype.Font
}

Label is the view display text

func (*Label) Image

func (l *Label) Image() image.Image

Image implements method of View

type Paper

type Paper struct {
	Control
	// contains filtered or unexported fields
}

Paper is the content view

func (*Paper) AddSub

func (p *Paper) AddSub(sub View)

AddSub add sub view to self

func (*Paper) Image

func (p *Paper) Image() image.Image

Image implements method of View

func (*Paper) RemoveSub

func (p *Paper) RemoveSub(sub View)

RemoveSub remove sub view

type View

type View interface {
	// Image render gui control tree to image
	Image() image.Image
}

View is the interface of all gui control

Jump to

Keyboard shortcuts

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