-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtypes.go
175 lines (137 loc) · 4.22 KB
/
types.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package washeet
import (
"sync"
"syscall/js"
)
type sheetPaintType byte
type sheetPaintRequest struct {
kind sheetPaintType
col int64
row int64
endCol int64
endRow int64
// For whole sheet paint requests
changeSheetStartCol bool
changeSheetStartRow bool
}
// TextAlignType is used to represent alignment of a cell's content.
type TextAlignType byte
// SheetDataProvider is the interface that needs to be implemented by the user of washeet
// which is used to draw and populate the contents of the spreadsheet.
type SheetDataProvider interface {
// GetDisplayString returns the content of the cell at (column,row) as a string.
GetDisplayString(column int64, row int64) string
// GetCellAttribs returns cell-attributes information via CellAttribs type.
GetCellAttribs(column, row int64) *CellAttribs
// GetColumnWidth returns the width of "column" column in pixels.
GetColumnWidth(column int64) float64
// GetRowHeight returns the height of "row" row in pixels.
GetRowHeight(row int64) float64
// TrimToNonEmptyRange trims given range represented by
// { top-left cell (column = c1, row = r1), bottom-right cell (column = c2, row = r2)
// to the biggest sub-range that does not have any leading/trailing empty columns/rows.
// It returns false if given range is completely empty, else it returns true.
TrimToNonEmptyRange(c1, r1, c2, r2 *int64) bool
}
// SheetNotifier is the interface via which client-users of washeet can
// notify which cell/range has changed its contents.
type SheetNotifier interface {
// UpdateCell call tells washeet that the specified cell contents have changed
// and needs redrawing.
UpdateCell(column, row int64)
// UpdateRange call tells washeet that the specified range's contents have changed
// and needs redrawing.
UpdateRange(startColumn, startRow, endColumn, endRow int64)
}
// markData represents a selection range as
// {top-left-cell(column = C1, row = R1), bottom-right-cell(column = C2, row = R2) }
type markData struct {
c1 int64
r1 int64
c2 int64
r2 int64
}
// cellCoords represents a cell's absolute coordinates.
type cellCoords struct {
col int64
row int64
}
// mouseState represents the state of the mouse at a given time.
type mouseState byte
// selectionState is used to store the start and current location of an on-going selection.
type selectionState struct {
refStartCell cellCoords
refCurrCell cellCoords
}
type layoutData struct {
startColumn int64
startRow int64
endColumn int64
endRow int64
colStartXCoords []float64
rowStartYCoords []float64
layoutFromStartCol bool
layoutFromStartRow bool
}
type canvasStoreType struct {
sheetCanvasElement js.Value
sheetCanvasContext js.Value
selectionCanvasElement js.Value
selectionCanvasContext js.Value
foregroundCanvasElement js.Value
}
// Sheet represents the spreadsheet user-interface.
type Sheet struct {
document js.Value
window js.Value
navigator js.Value
container *js.Value
canvasStore canvasStoreType
clipboardTextArea js.Value
origX float64
origY float64
maxX float64
maxY float64
dataSource SheetDataProvider
rafLayoutData *layoutData
evtHndlrLayoutData *layoutData
paintQueue chan *sheetPaintRequest
rafWorkerCallback js.Func
mark markData
stopSignal bool
stopRequest chan struct{}
ehMutex sync.Mutex
mouseState mouseState
selectionState selectionState
mousedownHandler js.Func
mouseupHandler js.Func
mousemoveHandler js.Func
keydownHandler js.Func
layoutFromStartCol bool
layoutFromStartRow bool
}
type cellMeasureGetter func(int64) float64
// Color represents a color.
type Color uint32
type colorSettings struct {
gridLine *Color
cellFill *Color
cellStroke *Color // fonts etc.
cursorStroke *Color
headerFill *Color
selectionStroke *Color
selectionFill *Color
selectionClearFill *Color
}
// textAttribs represent a cell's text attribute states like
// bold, italics, underline.
type textAttribs uint8
// CellAttribs stores the attributes of a cell.
type CellAttribs struct {
txtAttribs *textAttribs
txtAlign TextAlignType
fgColor *Color
bgColor *Color
fontSize uint8
}
type cornerType uint8