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

Method Transform

svg/viewbox.go:52–76  ·  view source on GitHub ↗

Transform returns the transform based on viewbox size relative to given box (viewport) size that it will be rendered into

(box math32.Vector2)

Source from the content-addressed store, hash-verified

50// Transform returns the transform based on viewbox size relative to given box
51// (viewport) size that it will be rendered into
52func (vb *ViewBox) Transform(box math32.Vector2) (size, trans, scale math32.Vector2) {
53 of := styles.FitFill
54 switch {
55 case vb.PreserveAspectRatio.Align.X == AlignNone:
56 of = styles.FitFill
57 case vb.PreserveAspectRatio.MeetOrSlice == Meet:
58 of = styles.FitContain
59 case vb.PreserveAspectRatio.MeetOrSlice == Slice:
60 of = styles.FitCover
61 }
62 if vb.Size.X == 0 || vb.Size.Y == 0 {
63 vb.Size = math32.Vec2(100, 100)
64 }
65 size = styles.ObjectSizeFromFit(of, vb.Size, box)
66 scale = size.Div(vb.Size)
67 extra := box.Sub(size)
68 if extra.X > 0 {
69 trans.X = extra.X * vb.PreserveAspectRatio.Align.X.AlignFactor()
70 }
71 if extra.Y > 0 {
72 trans.Y = extra.Y * vb.PreserveAspectRatio.Align.Y.AlignFactor()
73 }
74 trans.SetDiv(scale)
75 return
76}
77
78// ViewBoxAlign defines values for the PreserveAspectRatio alignment factor
79type ViewBoxAligns int32 //enums:enum -trim-prefix Align -transform lower

Callers 3

SetImageMethod · 0.45
RenderTextMethod · 0.45
SetRootTransformMethod · 0.45

Calls 6

Vec2Function · 0.92
ObjectSizeFromFitFunction · 0.92
AlignFactorMethod · 0.80
DivMethod · 0.45
SubMethod · 0.45
SetDivMethod · 0.45

Tested by

no test coverage detected