forked from fyne-io/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition.go
30 lines (24 loc) · 791 Bytes
/
position.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package terminal
import (
"fmt"
"fyne.io/fyne/v2"
)
type position struct {
Col, Row int
}
func (r position) String() string {
return fmt.Sprintf("row: %x, col: %x", r.Row, r.Col)
}
func (t *Terminal) getTermPosition(pos fyne.Position) position {
cell := t.guessCellSize()
col := int(pos.X/cell.Width) + 1
row := int(pos.Y/cell.Height) + 1
return position{col, row}
}
// getTextPosition converts a terminal position (row and col) to fyne coordinates.
func (t *Terminal) getTextPosition(pos position) fyne.Position {
cell := t.guessCellSize()
x := (pos.Col - 1) * int(cell.Width) // Convert column to pixel position (1-based to 0-based)
y := (pos.Row - 1) * int(cell.Height) // Convert row to pixel position (1-based to 0-based)
return fyne.NewPos(float32(x), float32(y))
}