8000 GitHub - inkeliz/giosvg: The <svg> in Gio · GitHub
[go: up one dir, main page]

Skip to content
inkelizPublic

About

The <svg> in Gio

Resources

Stars

27 stars

Watchers

2 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

< CC6B thead class="OverviewHeaderRow__Z_ScMh Box_1__wW_V7a">
NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GIOSVG

Give to your app some SVG icons. (:


Example:

// Embed your SVG into Golang:
//go:embed your_icon.svg
var iconFile []byte

// Give your SVG/XML to the Vector:
vector, err := giosvg.NewVector(iconFile)
if err != nil {
	panic(err)
}

// Create the Icon:
icon := giosvg.NewIcon(vector)

func someWidget(gtx layout.Context) layout.Dimensions {
	// Render your icon anywhere:
	return icon.Layout(gtx)
}

You can use embed to include your icon. The Vector can be reused to avoid parse the SVG multiple times.

If your icon use currentColor, you can use paint.ColorOp:

func someWidget(gtx layout.Context) layout.Dimensions {
    	// Render your icon anywhere, with custom color:
	paint.ColorOp{Color: color.NRGBA{B: 255, A: 255}}.Add(gtx.Ops)
	return icon.Layout(gtx)
}

It's possible to generate Gio functions from SVG, without need to parse XML at runtime, you can use:

go run github.com/inkeliz/giosvg/cmd/svggen -i .\path\to\assets -o .\path\to\pkg\vectors.go

It will compile all .SVG into one single file, that will create Gio functions (here you can see one example of generated file). You can render the SVG using icon := giosvg.NewIcon(pkg.IconName) then icon.Layout(gtx) as mentioned above (consider that pkg.IconName is the generated Golang code).


Icons in the example are from Freepik and from Flaticon Licensed by Creative Commons 3.0. This package is based on OKSVG.

About

The <svg> in Gio

Resources

Stars

27 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0