-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay_logic_helpers.go
51 lines (45 loc) · 1.29 KB
/
display_logic_helpers.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
package main
import (
"container/list"
)
// Current line should have correct startingY !
func (c *Display) resyncBelow(from *list.Element) {
c.recalcBelow(from)
for ; from != nil && from.Value.(*Line).startingCoordY-c.offsetY < c.getHeight(); from = from.Next() {
from.Value.(*Line).resync()
}
// Clean at startingY
startingY := 0
if from != nil {
startingY = from.Value.(*Line).startingCoordY + from.Value.(*Line).calculateHeight()
} else {
startingY = c.data.Back().Value.(*Line).startingCoordY + c.data.Back().Value.(*Line).calculateHeight()
}
for ; startingY-c.offsetY < c.getHeight(); startingY++ {
for i := 0; i < c.getWidth(); i++ {
c.screen.clearStr(i, startingY-c.offsetY)
}
}
c.screen.sync()
}
func (c *Display) recalcBelow(from *list.Element) {
startingY := from.Value.(*Line).startingCoordY
for ; from != nil; from = from.Next() {
line := from.Value.(*Line)
line.startingCoordY = startingY
startingY += line.calculateHeight()
}
}
func (c *Display) resyncNewCursorY() {
onScreenCursorY := c.getCurrentEl().getOnScreenCursorY()
// If cursor jumped below screen
if onScreenCursorY >= c.getHeight() {
c.offsetY++
c.resyncBelow(c.data.Front())
} else if onScreenCursorY < 0 {
c.offsetY--
c.resyncBelow(c.data.Front())
} else {
c.resyncBelow(c.currentElement)
}
}