config is called during the layout of the plot, prior to drawing
(pt *Plot)
| 69 | |
| 70 | // config is called during the layout of the plot, prior to drawing |
| 71 | func (tx *Text) Config(pt *Plot) { |
| 72 | uc := &pt.Paint.UnitContext |
| 73 | fs := &tx.Style.FontRender |
| 74 | if math32.Abs(tx.Style.Rotation) > 10 { |
| 75 | tx.Style.Align = styles.End |
| 76 | } |
| 77 | fs.ToDots(uc) |
| 78 | tx.Style.Padding.ToDots(uc) |
| 79 | txln := float32(len(tx.Text)) |
| 80 | fht := fs.Size.Dots |
| 81 | hsz := float32(12) * txln |
| 82 | txs := &pt.StandardTextStyle |
| 83 | tx.PaintText.SetHTML(tx.Text, fs, txs, uc, nil) |
| 84 | tx.PaintText.Layout(txs, fs, uc, math32.Vector2{X: hsz, Y: fht}) |
| 85 | if tx.Style.Rotation != 0 { |
| 86 | rotx := math32.Rotate2D(math32.DegToRad(tx.Style.Rotation)) |
| 87 | tx.PaintText.Transform(rotx, fs, uc) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // PosX returns the starting position for a horizontally-aligned text element, |
| 92 | // based on given width. Text must have been config'd already. |