Debian Codegraph @

vt/damage.go

raw
1 package vt
2
3 import uv "github.com/charmbracelet/ultraviolet"
4
5 // Damage represents a damaged area.
6 type Damage interface {
7 // Bounds returns the bounds of the damaged area.
8 Bounds() uv.Rectangle
9 }
10
11 // CellDamage represents a damaged cell.
12 type CellDamage struct {
13 X, Y int
14 Width int
15 }
16
17 // Bounds returns the bounds of the damaged area.
18 func (d CellDamage) Bounds() uv.Rectangle {
19 return uv.Rect(d.X, d.Y, d.Width, 1)
20 }
21
22 // RectDamage represents a damaged rectangle.
23 type RectDamage uv.Rectangle
24
25 // Bounds returns the bounds of the damaged area.
26 func (d RectDamage) Bounds() uv.Rectangle {
27 return uv.Rectangle(d)
28 }
29
30 // X returns the x-coordinate of the damaged area.
31 func (d RectDamage) X() int {
32 return uv.Rectangle(d).Min.X
33 }
34
35 // Y returns the y-coordinate of the damaged area.
36 func (d RectDamage) Y() int {
37 return uv.Rectangle(d).Min.Y
38 }
39
40 // Width returns the width of the damaged area.
41 func (d RectDamage) Width() int {
42 return uv.Rectangle(d).Dx()
43 }
44
45 // Height returns the height of the damaged area.
46 func (d RectDamage) Height() int {
47 return uv.Rectangle(d).Dy()
48 }
49
50 // ScreenDamage represents a damaged screen.
51 type ScreenDamage struct {
52 Width, Height int
53 }
54
55 // Bounds returns the bounds of the damaged area.
56 func (d ScreenDamage) Bounds() uv.Rectangle {
57 return uv.Rect(0, 0, d.Width, d.Height)
58 }
59
60 // MoveDamage represents a moved area.
61 // The area is moved from the source to the destination.
62 type MoveDamage struct {
63 Src, Dst uv.Rectangle
64 }
65
66 // ScrollDamage represents a scrolled area.
67 // The area is scrolled by the given deltas.
68 type ScrollDamage struct {
69 uv.Rectangle
70 Dx, Dy int
71 }