-
Notifications
You must be signed in to change notification settings - Fork 38
/
render.go
68 lines (53 loc) · 1.52 KB
/
render.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package terminal
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/theme"
)
const cursorWidth = 2
type render struct {
term *Terminal
}
func (r *render) Layout(s fyne.Size) {
r.term.content.Resize(s)
}
func (r *render) MinSize() fyne.Size {
return fyne.NewSize(0, 0) // don't get propped open by the text cells
}
func (r *render) Refresh() {
r.moveCursor()
r.term.refreshCursor()
r.term.content.Refresh()
}
func (r *render) BackgroundColor() color.Color {
return color.Transparent
}
func (r *render) Objects() []fyne.CanvasObject {
return []fyne.CanvasObject{r.term.content, r.term.cursor}
}
func (r *render) Destroy() {
}
func (r *render) moveCursor() {
cell := r.term.guessCellSize()
r.term.cursor.Move(fyne.NewPos(cell.Width*float32(r.term.cursorCol), cell.Height*float32(r.term.cursorRow)))
}
func (t *Terminal) refreshCursor() {
t.cursor.Hidden = !t.focused || t.cursorHidden
if t.bell {
t.cursor.FillColor = theme.Color(theme.ColorNameError)
} else {
t.cursor.FillColor = theme.Color(theme.ColorNamePrimary)
}
t.cursor.Resize(fyne.NewSize(cursorWidth, t.guessCellSize().Height))
t.cursor.Refresh()
}
// CreateRenderer requests a new renderer for this terminal (just a wrapper around the TextGrid)
func (t *Terminal) CreateRenderer() fyne.WidgetRenderer {
t.cursor = canvas.NewRectangle(theme.Color(theme.ColorNamePrimary))
t.cursor.Hidden = true
t.cursor.Resize(fyne.NewSize(cursorWidth, t.guessCellSize().Height))
r := &render{term: t}
t.cursorMoved = r.moveCursor
return r
}