MCPcopy Create free account
hub / github.com/cogentcore/core / renderSVG

Method renderSVG

core/icon.go:77–109  ·  view source on GitHub ↗

renderSVG renders the [Icon.svg] if necessary.

()

Source from the content-addressed store, hash-verified

75
76// renderSVG renders the [Icon.svg] if necessary.
77func (ic *Icon) renderSVG() {
78 if ic.svg.Root == nil || !ic.svg.Root.HasChildren() {
79 return
80 }
81
82 sv := &ic.svg
83 sz := ic.Geom.Size.Actual.Content.ToPoint()
84 clr := gradient.ApplyOpacity(ic.Styles.Color, ic.Styles.Opacity)
85 if !ic.NeedsRebuild() && sv.Pixels != nil { // if rebuilding then rebuild
86 isz := sv.Pixels.Bounds().Size()
87 // if nothing has changed, we don't need to re-render
88 if isz == sz && sv.Name == string(ic.Icon) && sv.Color == clr {
89 return
90 }
91 }
92
93 if sz == (image.Point{}) {
94 return
95 }
96 // ensure that we have new pixels to render to in order to prevent
97 // us from rendering over ourself
98 sv.Pixels = image.NewRGBA(image.Rectangle{Max: sz})
99 sv.RenderState.Init(sz.X, sz.Y, sv.Pixels)
100 sv.Geom.Size = sz // make sure
101
102 sv.Resize(sz) // does Config if needed
103
104 sv.Color = clr
105
106 sv.Scale = 1
107 sv.Render()
108 sv.Name = string(ic.Icon)
109}
110
111func (ic *Icon) Render() {
112 ic.renderSVG()

Callers 1

RenderMethod · 0.95

Calls 9

ApplyOpacityFunction · 0.92
ToPointMethod · 0.80
NeedsRebuildMethod · 0.80
SizeMethod · 0.65
InitMethod · 0.65
RenderMethod · 0.65
HasChildrenMethod · 0.45
BoundsMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected