Skip to content

Commit

Permalink
svg: revert to original translate order, div by scale to make it work…
Browse files Browse the repository at this point in the history
… for for viewbox align
  • Loading branch information
rcoreilly committed Jan 22, 2024
1 parent 9988f55 commit 400f1f9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion gi/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (a *App) SetIconSVG(r io.Reader) *App {

sv := svg.NewSVG(16, 16)
sv.Color = colors.C(colors.FromRGB(66, 133, 244)) // Google Blue (#4285f4)
sv.Norm = true
err := sv.ReadXML(r)
if grr.Log(err) != nil {
return a
Expand Down
4 changes: 3 additions & 1 deletion gi/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ func (ic *Icon) OnInit() {
}

func (ic *Icon) SetStyles() {
ic.SVG.Norm = true
ic.SVG.Scale = 1
ic.Style(func(s *styles.Style) {
s.Min.X.Dp(16)
s.Min.Y.Dp(16)
})
ic.StyleFinal(func(s *styles.Style) {
ic.SVG.Root.ViewBox.PreserveAspectRatio.SetFromStyle(s)
})
}

// SetIcon sets the icon, logging error if not found.
Expand Down
4 changes: 3 additions & 1 deletion gi/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type SVG struct {

func (sv *SVG) OnInit() {
sv.SVG = svg.NewSVG(10, 10)
sv.SVG.Norm = true
sv.WidgetBase.OnInit()
sv.SetStyles()
sv.HandleEvents()
Expand All @@ -43,6 +42,9 @@ func (sv *SVG) SetStyles() {
s.Grow.Set(1, 1)
s.Min.Set(units.Dp(sv.SVG.Root.ViewBox.Size.X), units.Dp(sv.SVG.Root.ViewBox.Size.Y))
})
sv.StyleFinal(func(s *styles.Style) {
sv.SVG.Root.ViewBox.PreserveAspectRatio.SetFromStyle(s)
})
}

func (sv *SVG) HandleEvents() {
Expand Down
2 changes: 1 addition & 1 deletion svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (sv *SVG) SetRootTransform() {
trans.SetAdd(sv.Translate)
scale.SetMulScalar(sv.Scale)
pc := &sv.Root.Paint
pc.Transform = pc.Transform.Translate(trans.X, trans.Y).Scale(scale.X, scale.Y)
pc.Transform = pc.Transform.Scale(scale.X, scale.Y).Translate(trans.X, trans.Y)
if sv.InvertY {
pc.Transform.Y0 = -pc.Transform.Y0
}
Expand Down
1 change: 1 addition & 0 deletions svg/viewbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (vb *ViewBox) Transform(box mat32.Vec2) (size, trans, scale mat32.Vec2) {
if extra.Y > 0 {
trans.Y = extra.Y * vb.PreserveAspectRatio.Align.Y.AlignFactor()
}
trans.SetDiv(scale)
return
}

Expand Down

0 comments on commit 400f1f9

Please sign in to comment.