charStartPos returns the starting (top left) render coords for the given position -- makes no attempt to rationalize that pos (i.e., if not in visible range, position will be out of range too)
(pos lexer.Pos)
| 89 | // position -- makes no attempt to rationalize that pos (i.e., if not in |
| 90 | // visible range, position will be out of range too) |
| 91 | func (ed *Editor) charStartPos(pos lexer.Pos) math32.Vector2 { |
| 92 | spos := ed.renderStartPos() |
| 93 | spos.X += ed.LineNumberOffset |
| 94 | if pos.Ln >= len(ed.offsets) { |
| 95 | if len(ed.offsets) > 0 { |
| 96 | pos.Ln = len(ed.offsets) - 1 |
| 97 | } else { |
| 98 | return spos |
| 99 | } |
| 100 | } else { |
| 101 | spos.Y += ed.offsets[pos.Ln] |
| 102 | } |
| 103 | if pos.Ln >= len(ed.renders) { |
| 104 | return spos |
| 105 | } |
| 106 | rp := &ed.renders[pos.Ln] |
| 107 | if len(rp.Spans) > 0 { |
| 108 | // note: Y from rune pos is baseline |
| 109 | rrp, _, _, _ := ed.renders[pos.Ln].RuneRelPos(pos.Ch) |
| 110 | spos.X += rrp.X |
| 111 | spos.Y += rrp.Y - ed.renders[pos.Ln].Spans[0].RelPos.Y // relative |
| 112 | } |
| 113 | return spos |
| 114 | } |
| 115 | |
| 116 | // charStartPosVisible returns the starting pos for given position |
| 117 | // that is currently visible, based on bounding boxes. |
no test coverage detected