PosX returns the starting position for a horizontally-aligned text element, based on given width. Text must have been config'd already.
(width float32)
| 91 | // PosX returns the starting position for a horizontally-aligned text element, |
| 92 | // based on given width. Text must have been config'd already. |
| 93 | func (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. |