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

Method PosX

plot/text.go:93–106  ·  view source on GitHub ↗

PosX returns the starting position for a horizontally-aligned text element, based on given width. Text must have been config'd already.

(width float32)

Source from the content-addressed store, hash-verified

91// PosX returns the starting position for a horizontally-aligned text element,
92// based on given width. Text must have been config'd already.
93func (tx *Text) PosX(width float32) math32.Vector2 {
94 pos := math32.Vector2{}
95 pos.X = styles.AlignFactor(tx.Style.Align) * width
96 switch tx.Style.Align {
97 case styles.Center:
98 pos.X -= 0.5 * tx.PaintText.BBox.Size().X
99 case styles.End:
100 pos.X -= tx.PaintText.BBox.Size().X
101 }
102 if math32.Abs(tx.Style.Rotation) > 10 {
103 pos.Y += 0.5 * tx.PaintText.BBox.Size().Y
104 }
105 return pos
106}
107
108// PosY returns the starting position for a vertically-rotated text element,
109// based on given height. Text must have been config'd already.

Callers 4

DrawMethod · 0.80
tickPosXMethod · 0.80
drawXMethod · 0.80
drawYMethod · 0.80

Calls 3

AlignFactorFunction · 0.92
AbsFunction · 0.92
SizeMethod · 0.65

Tested by

no test coverage detected